From 2aaaf57504e4d61ca0683540a0d56a92a99ea198 Mon Sep 17 00:00:00 2001 From: Ross Poulton Date: Sat, 5 Nov 2011 00:56:53 +0000 Subject: [PATCH] Pull in changes from bclermont to fix content-type handling on queues when processing incoming e-mail. Closes GH-70. --- helpdesk/lib.py | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/helpdesk/lib.py b/helpdesk/lib.py index 04e6d873..05469588 100644 --- a/helpdesk/lib.py +++ b/helpdesk/lib.py @@ -54,13 +54,7 @@ def send_templated_mail(template_name, email_context, recipients, sender=None, b import os context = Context(email_context) - locale = 'en'; - if hasattr(context['queue'], 'locale'): - locale = getattr(context['queue'], 'locale', '') - else: - locale = context['queue'].get('locale', 'en') - if not locale: - locale = 'en' + locale = context['queue'].get('locale', 'en') t = None try: @@ -85,15 +79,15 @@ def send_templated_mail(template_name, email_context, recipients, sender=None, b email_html_base_file = os.path.join('helpdesk', locale, 'email_html_base.html') - + ''' keep new lines in html emails ''' from django.utils.safestring import mark_safe - + if context.has_key('comment'): html_txt = context['comment'] html_txt = html_txt.replace('\r\n', '
') context['comment'] = mark_safe(html_txt) - + html_part = loader.get_template_from_string( "{%% extends '%s' %%}{%% block title %%}%s{%% endblock %%}{%% block content %%}%s{%% endblock %%}" % (email_html_base_file, t.heading, t.html) ).render(context) @@ -150,13 +144,13 @@ def apply_query(queryset, params): """ Apply a dict-based set of filters & paramaters to a queryset. - queryset is a Django queryset, eg MyModel.objects.all() or + queryset is a Django queryset, eg MyModel.objects.all() or MyModel.objects.filter(user=request.user) 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'} - other_filter: Another filter of some type, most likely a + other_filter: Another filter of some type, most likely a set of Q() objects. sorting: The name of the column to sort by """ @@ -180,7 +174,7 @@ def safe_template_context(ticket): """ Return a dictionary that can be used as a template context to render comments and other details with ticket or queue paramaters. Note that - we don't just provide the Ticket & Queue objects to the template as + we don't just provide the Ticket & Queue objects to the template as they could reveal confidential information. Just imagine these two options: * {{ ticket.queue.email_box_password }} * {{ ticket.assigned_to.password }} @@ -204,7 +198,7 @@ def safe_template_context(ticket): else: context['queue'][field] = attr - for field in ( 'title', 'created', 'modified', 'submitter_email', + for field in ( 'title', 'created', 'modified', 'submitter_email', 'status', 'get_status_display', 'on_hold', 'description', 'resolution', 'priority', 'get_priority_display', 'last_escalation', 'ticket', 'ticket_for_url', @@ -225,7 +219,7 @@ def safe_template_context(ticket): def text_is_spam(text, request): # Based on a blog post by 'sciyoshi': # http://sciyoshi.com/blog/2008/aug/27/using-akismet-djangos-new-comments-framework/ - # This will return 'True' is the given text is deemed to be spam, or + # This will return 'True' is the given text is deemed to be spam, or # False if it is not spam. If it cannot be checked for some reason, we # assume it isn't spam. from django.contrib.sites.models import Site