From 96f4fecb71bff70f582a35ee18c1c0656d2dbbc7 Mon Sep 17 00:00:00 2001 From: meomap Date: Fri, 14 Oct 2016 15:04:28 +0700 Subject: [PATCH] add setting for fallback locale --- docs/settings.rst | 4 ++++ helpdesk/lib.py | 13 +++++++------ helpdesk/settings.py | 3 +++ 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/docs/settings.rst b/docs/settings.rst index 81ce992f..ed3f716d 100644 --- a/docs/settings.rst +++ b/docs/settings.rst @@ -68,6 +68,10 @@ These changes are visible throughout django-helpdesk **Default:** ``HELPDESK_EMAIL_SUBJECT_TEMPLATE = "{{ ticket.ticket }} {{ ticket.title|safe }} %(subject)s"`` +- **HELPDESK_EMAIL_FALLBACK_LOCALE** Fallback locale for templated emails when queue locale not found + + **Default:** ``HELPDESK_EMAIL_FALLBACK_LOCALE= "en"`` + Options shown on public pages ----------------------------- diff --git a/helpdesk/lib.py b/helpdesk/lib.py index 3dfe5448..95dddbd0 100644 --- a/helpdesk/lib.py +++ b/helpdesk/lib.py @@ -46,7 +46,7 @@ def send_templated_mail(template_name, email_context, recipients, sender=None, b fail_silently is passed to Django's mail routine. Set to 'True' to ignore any errors at send time. - files can be a list of tuple. Each tuple should be a filename to attach, + files can be a list of tuple. Each tuple should be a filename to attach, along with the File objects to be read. files can be blank. """ @@ -56,7 +56,8 @@ def send_templated_mail(template_name, email_context, recipients, sender=None, b from django.template import loader, Context from helpdesk.models import EmailTemplate - from helpdesk.settings import HELPDESK_EMAIL_SUBJECT_TEMPLATE + from helpdesk.settings import HELPDESK_EMAIL_SUBJECT_TEMPLATE, \ + HELPDESK_EMAIL_FALLBACK_LOCALE import os # RemovedInDjango110Warning: render() must be called with a dict, not a Context. @@ -68,9 +69,9 @@ def send_templated_mail(template_name, email_context, recipients, sender=None, b if hasattr(context['queue'], 'locale'): locale = getattr(context['queue'], 'locale', '') else: - locale = context['queue'].get('locale', 'en') + locale = context['queue'].get('locale', HELPDESK_EMAIL_FALLBACK_LOCALE) if not locale: - locale = 'en' + locale = HELPDESK_EMAIL_FALLBACK_LOCALE t = None try: @@ -90,7 +91,7 @@ def send_templated_mail(template_name, email_context, recipients, sender=None, b sender = settings.DEFAULT_FROM_EMAIL footer_file = os.path.join('helpdesk', locale, 'email_text_footer.txt') - + # get_template_from_string was removed in Django 1.8 http://django.readthedocs.org/en/1.8.x/ref/templates/upgrading.html try: from django.template import engines @@ -178,7 +179,7 @@ def apply_query(queryset, params): params is a dictionary that contains the following: filtering: A dict of Django ORM filters, eg: {'user__id__in': [1, 3, 103], 'title__contains': 'foo'} - + search_string: A freetext search string sorting: The name of the column to sort by diff --git a/helpdesk/settings.py b/helpdesk/settings.py index 27cbfd59..0ead588d 100644 --- a/helpdesk/settings.py +++ b/helpdesk/settings.py @@ -86,6 +86,9 @@ HELPDESK_STAFF_ONLY_TICKET_CC = getattr(settings, 'HELPDESK_STAFF_ONLY_TICKET_CC # allow the subject to have a configurable template. HELPDESK_EMAIL_SUBJECT_TEMPLATE = getattr(settings, 'HELPDESK_EMAIL_SUBJECT_TEMPLATE', "{{ ticket.ticket }} {{ ticket.title|safe }} %(subject)s") +# default fallback locale when queue locale not found +HELPDESK_EMAIL_FALLBACK_LOCALE = getattr(settings, 'HELPDESK_EMAIL_FALLBACK_LOCALE', 'en') + ''' options for staff.create_ticket view ''' # hide the 'assigned to' / 'Case owner' field from the 'create_ticket' view?