diff --git a/helpdesk/lib.py b/helpdesk/lib.py index 22ef1a44..3e031190 100644 --- a/helpdesk/lib.py +++ b/helpdesk/lib.py @@ -84,8 +84,15 @@ 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 + template_func = engines['django'].from_string + except ImportError: # occurs in django < 1.8 + template_func = loader.get_template_from_string - text_part = loader.get_template_from_string( + text_part = template_func( "%s{%% include '%s' %%}" % (t.plain_text, footer_file) ).render(context) @@ -100,11 +107,13 @@ def send_templated_mail(template_name, email_context, recipients, sender=None, b html_txt = html_txt.replace('\r\n', '
') context['comment'] = mark_safe(html_txt) - html_part = loader.get_template_from_string( + # get_template_from_string was removed in Django 1.8 http://django.readthedocs.org/en/1.8.x/ref/templates/upgrading.html + html_part = template_func( "{%% extends '%s' %%}{%% block title %%}%s{%% endblock %%}{%% block content %%}%s{%% endblock %%}" % (email_html_base_file, t.heading, t.html) ).render(context) - subject_part = loader.get_template_from_string( + # get_template_from_string was removed in Django 1.8 http://django.readthedocs.org/en/1.8.x/ref/templates/upgrading.html + subject_part = template_func( HELPDESK_EMAIL_SUBJECT_TEMPLATE % { "subject": t.subject, }).render(context) diff --git a/helpdesk/migrations/0005_queues_no_null.py b/helpdesk/migrations/0005_queues_no_null.py new file mode 100644 index 00000000..8a678635 --- /dev/null +++ b/helpdesk/migrations/0005_queues_no_null.py @@ -0,0 +1,29 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('helpdesk', '0004_add_per_queue_staff_membership'), + ] + + operations = [ + migrations.AlterField( + model_name='escalationexclusion', + name='queues', + field=models.ManyToManyField(help_text='Leave blank for this exclusion to be applied to all queues, or select those queues you wish to exclude with this entry.', to='helpdesk.Queue', blank=True), + ), + migrations.AlterField( + model_name='ignoreemail', + name='queues', + field=models.ManyToManyField(help_text='Leave blank for this e-mail to be ignored on all queues, or select those queues you wish to ignore this e-mail for.', to='helpdesk.Queue', blank=True), + ), + migrations.AlterField( + model_name='presetreply', + name='queues', + field=models.ManyToManyField(help_text='Leave blank to allow this reply to be used for all queues, or select those queues you wish to limit this reply to.', to='helpdesk.Queue', blank=True), + ), + ] diff --git a/helpdesk/migrations/0006_email_maxlength.py b/helpdesk/migrations/0006_email_maxlength.py new file mode 100644 index 00000000..7c50b32a --- /dev/null +++ b/helpdesk/migrations/0006_email_maxlength.py @@ -0,0 +1,29 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('helpdesk', '0005_queues_no_null'), + ] + + operations = [ + migrations.AlterField( + model_name='queue', + name='email_address', + field=models.EmailField(help_text='All outgoing e-mails for this queue will use this e-mail address. If you use IMAP or POP3, this should be the e-mail address for that mailbox.', max_length=254, null=True, verbose_name='E-Mail Address', blank=True), + ), + migrations.AlterField( + model_name='ticket', + name='submitter_email', + field=models.EmailField(help_text='The submitter will receive an email for all public follow-ups left for this task.', max_length=254, null=True, verbose_name='Submitter E-Mail', blank=True), + ), + migrations.AlterField( + model_name='ticketcc', + name='email', + field=models.EmailField(help_text='For non-user followers, enter their e-mail address', max_length=254, null=True, verbose_name='E-Mail Address', blank=True), + ), + ] diff --git a/helpdesk/tests/__init__.py b/helpdesk/tests/__init__.py index b6f9def4..807df353 100644 --- a/helpdesk/tests/__init__.py +++ b/helpdesk/tests/__init__.py @@ -1,4 +1,9 @@ -from helpdesk.tests.ticket_submission import * -from helpdesk.tests.public_actions import * -from helpdesk.tests.navigation import * -from helpdesk.tests.per_queue_staff_membership import * +# import all test_*.py files in directory. +# neccessary for automatic discovery in django <= 1.5 +# http://stackoverflow.com/a/15780326/1382740 + +import unittest + + +def suite(): + return unittest.TestLoader().discover("helpdesk.tests", pattern="test_*.py") diff --git a/helpdesk/tests/helpers.py b/helpdesk/tests/helpers.py index 6dccad08..67715c90 100644 --- a/helpdesk/tests/helpers.py +++ b/helpdesk/tests/helpers.py @@ -26,8 +26,15 @@ def reload_urlconf(urlconf=None): from django.conf import settings urlconf = settings.ROOT_URLCONF - if urlconf in sys.modules: - from django.core.urlresolvers import clear_url_caches + if HELPDESK_URLCONF in sys.modules: + reload(sys.modules[HELPDESK_URLCONF]) + + if urlconf in sys.modules: reload(sys.modules[urlconf]) - clear_url_caches() + + from django.core.urlresolvers import clear_url_caches + clear_url_caches() + + +HELPDESK_URLCONF = 'helpdesk.urls' diff --git a/helpdesk/tests/navigation.py b/helpdesk/tests/test_navigation.py similarity index 100% rename from helpdesk/tests/navigation.py rename to helpdesk/tests/test_navigation.py diff --git a/helpdesk/tests/per_queue_staff_membership.py b/helpdesk/tests/test_per_queue_staff_membership.py similarity index 100% rename from helpdesk/tests/per_queue_staff_membership.py rename to helpdesk/tests/test_per_queue_staff_membership.py diff --git a/helpdesk/tests/public_actions.py b/helpdesk/tests/test_public_actions.py similarity index 100% rename from helpdesk/tests/public_actions.py rename to helpdesk/tests/test_public_actions.py diff --git a/helpdesk/tests/ticket_submission.py b/helpdesk/tests/test_ticket_submission.py similarity index 100% rename from helpdesk/tests/ticket_submission.py rename to helpdesk/tests/test_ticket_submission.py diff --git a/helpdesk/views/staff.py b/helpdesk/views/staff.py index f904ae40..c44073f1 100644 --- a/helpdesk/views/staff.py +++ b/helpdesk/views/staff.py @@ -367,7 +367,16 @@ def update_ticket(request, ticket_id, public=False): # if comment contains some django code, like "why does {% if bla %} crash", # then the following line will give us a crash, since django expects {% if %} # to be closed with an {% endif %} tag. - comment = loader.get_template_from_string(comment).render(Context(context)) + + + # 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 + template_func = engines['django'].from_string + except ImportError: # occurs in django < 1.8 + template_func = loader.get_template_from_string + + comment = template_func(comment).render(Context(context)) if owner is -1 and ticket.assigned_to: owner = ticket.assigned_to.id diff --git a/quicktest.py b/quicktest.py index 78724ec2..cce174af 100644 --- a/quicktest.py +++ b/quicktest.py @@ -93,11 +93,22 @@ class QuickDjangoTest(object): STATIC_URL = '/static/' ) + # compatibility with django 1.8 downwards + # see: http://stackoverflow.com/questions/3841725/how-to-launch-tests-for-django-reusable-app + + try: + # Django >= 1.6 + from django.test.runner import DiscoverRunner + test_runner = DiscoverRunner(verbosity=1) + except ImportError: + # Django <= 1.5 + from django.test.simple import DjangoTestSuiteRunner + test_runner = DjangoTestSuiteRunner(verbosity=1) + if django.VERSION >= (1, 7): django.setup() - from django.test.simple import DjangoTestSuiteRunner - failures = DjangoTestSuiteRunner().run_tests(self.apps, verbosity=1) + failures = test_runner.run_tests(self.apps) if failures: sys.exit(failures)