Commit 2aeb5597 authored by Michal Čihař's avatar Michal Čihař

Generate usable In-Reply-To and References headers

So that MUAs can properly thread comments.

Fixes #782
Signed-off-by: default avatarMichal Čihař <michal@cihar.com>
parent d0de5a03
...@@ -38,7 +38,7 @@ from django.utils.translation import LANGUAGE_SESSION_KEY ...@@ -38,7 +38,7 @@ from django.utils.translation import LANGUAGE_SESSION_KEY
from social.apps.django_app.default.models import UserSocialAuth from social.apps.django_app.default.models import UserSocialAuth
from weblate.lang.models import Language from weblate.lang.models import Language
from weblate.trans.util import get_site_url from weblate.trans.util import get_site_url, get_site_domain
from weblate.accounts.avatar import get_user_display from weblate.accounts.avatar import get_user_display
from weblate.trans.util import report_error from weblate.trans.util import report_error
import weblate import weblate
...@@ -253,6 +253,19 @@ def get_notification_email(language, email, notification, ...@@ -253,6 +253,19 @@ def get_notification_email(language, email, notification,
cur_language = django_translation.get_language() cur_language = django_translation.get_language()
context = context or {} context = context or {}
headers = headers or {} headers = headers or {}
references = None
if 'unit' in context:
unit = context['unit']
references = '{0}/{1}/{2}/{3}'.format(
unit.translation.subproject.project.slug,
unit.translation.subproject.slug,
unit.translation.language.code,
unit.id
)
if references is not None:
references = '<{0}@{1}>'.format(references, get_site_domain())
headers['In-Reply-To'] = references
headers['References'] = references
try: try:
if info is None: if info is None:
info = translation_obj.__unicode__() info = translation_obj.__unicode__()
......
...@@ -81,16 +81,20 @@ def is_repo_link(val): ...@@ -81,16 +81,20 @@ def is_repo_link(val):
return val.startswith('weblate://') return val.startswith('weblate://')
def get_site_domain():
"""Returns current site domain."""
from django.contrib.sites.models import Site
return Site.objects.get_current().domain
def get_site_url(url=''): def get_site_url(url=''):
''' '''
Returns root url of current site with domain. Returns root url of current site with domain.
''' '''
from weblate.appsettings import ENABLE_HTTPS from weblate.appsettings import ENABLE_HTTPS
from django.contrib.sites.models import Site
site = Site.objects.get_current()
return '{0}://{1}{2}'.format( return '{0}://{1}{2}'.format(
'https' if ENABLE_HTTPS else 'http', 'https' if ENABLE_HTTPS else 'http',
site.domain, get_site_domain(),
url url
) )
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment