From 0f697711645e2acf8f08456c7a69f8e092d8aa4c Mon Sep 17 00:00:00 2001 From: Alex Seeholzer Date: Tue, 2 Jun 2015 10:59:01 +0200 Subject: [PATCH 01/16] fix for django 1.8.2, get_template_from_string was removed --- helpdesk/views/staff.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/helpdesk/views/staff.py b/helpdesk/views/staff.py index 0ea21497..e3870abe 100644 --- a/helpdesk/views/staff.py +++ b/helpdesk/views/staff.py @@ -347,7 +347,11 @@ 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 + from django.template import Engine + comment = Engine().from_string(comment).render(Context(context)) if owner is -1 and ticket.assigned_to: owner = ticket.assigned_to.id From 039653cc7003f04a5e0324d4b4659d44642e858a Mon Sep 17 00:00:00 2001 From: Alex Seeholzer Date: Tue, 2 Jun 2015 16:18:50 +0200 Subject: [PATCH 02/16] further fixes for Django 1.8.2 template engine --- helpdesk/lib.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/helpdesk/lib.py b/helpdesk/lib.py index 22ef1a44..820e3b41 100644 --- a/helpdesk/lib.py +++ b/helpdesk/lib.py @@ -84,8 +84,11 @@ 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') - - text_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 + from django.template import Engine + + text_part = Engine().from_string( "%s{%% include '%s' %%}" % (t.plain_text, footer_file) ).render(context) @@ -100,11 +103,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 = Engine().from_string( "{%% 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 = Engine().from_string( HELPDESK_EMAIL_SUBJECT_TEMPLATE % { "subject": t.subject, }).render(context) From 0b7e0b7f04d32276ba4a4039013a52122278f475 Mon Sep 17 00:00:00 2001 From: Alex Seeholzer Date: Tue, 2 Jun 2015 16:57:52 +0200 Subject: [PATCH 03/16] changes in templating engine that worked for django 1.8 --- helpdesk/lib.py | 6 ++++-- helpdesk/views/staff.py | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/helpdesk/lib.py b/helpdesk/lib.py index 820e3b41..cd9aa8c5 100644 --- a/helpdesk/lib.py +++ b/helpdesk/lib.py @@ -103,13 +103,15 @@ 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) + from django.template import engines + # get_template_from_string was removed in Django 1.8 http://django.readthedocs.org/en/1.8.x/ref/templates/upgrading.html - html_part = Engine().from_string( + html_part = engines['django'].from_string( "{%% extends '%s' %%}{%% block title %%}%s{%% endblock %%}{%% block content %%}%s{%% endblock %%}" % (email_html_base_file, t.heading, t.html) ).render(context) # get_template_from_string was removed in Django 1.8 http://django.readthedocs.org/en/1.8.x/ref/templates/upgrading.html - subject_part = Engine().from_string( + subject_part = engines['django'].from_string( HELPDESK_EMAIL_SUBJECT_TEMPLATE % { "subject": t.subject, }).render(context) diff --git a/helpdesk/views/staff.py b/helpdesk/views/staff.py index e3870abe..e42dd162 100644 --- a/helpdesk/views/staff.py +++ b/helpdesk/views/staff.py @@ -350,8 +350,8 @@ def update_ticket(request, ticket_id, public=False): # get_template_from_string was removed in Django 1.8 http://django.readthedocs.org/en/1.8.x/ref/templates/upgrading.html - from django.template import Engine - comment = Engine().from_string(comment).render(Context(context)) + from django.template import engines + comment = engines['django'].from_string(comment).render(Context(context)) if owner is -1 and ticket.assigned_to: owner = ticket.assigned_to.id From cbea3c54f004e52c5a26fe8877eba3c1881eebed Mon Sep 17 00:00:00 2001 From: Alex Seeholzer Date: Fri, 12 Jun 2015 12:54:50 +0200 Subject: [PATCH 04/16] conformed template from_string method to use engines['django'] --- helpdesk/lib.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/helpdesk/lib.py b/helpdesk/lib.py index cd9aa8c5..1298c57b 100644 --- a/helpdesk/lib.py +++ b/helpdesk/lib.py @@ -86,9 +86,9 @@ def send_templated_mail(template_name, email_context, recipients, sender=None, b 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 - from django.template import Engine + from django.template import engines - text_part = Engine().from_string( + text_part = engines['django'].from_string( "%s{%% include '%s' %%}" % (t.plain_text, footer_file) ).render(context) From 87225ce2ba97eecf178d2919da6fda5fac47189f Mon Sep 17 00:00:00 2001 From: Alex Seeholzer Date: Fri, 12 Jun 2015 15:27:49 +0200 Subject: [PATCH 05/16] tests renamed for compliance --- helpdesk/tests/{navigation.py => test_navigation.py} | 0 helpdesk/tests/{public_actions.py => test_public_actions.py} | 0 .../tests/{ticket_submission.py => test_ticket_submission.py} | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename helpdesk/tests/{navigation.py => test_navigation.py} (100%) rename helpdesk/tests/{public_actions.py => test_public_actions.py} (100%) rename helpdesk/tests/{ticket_submission.py => test_ticket_submission.py} (100%) 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/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 From 05625d0bfd92cb3113d0e00808ef1cba596e9e71 Mon Sep 17 00:00:00 2001 From: Alex Seeholzer Date: Fri, 12 Jun 2015 15:30:54 +0200 Subject: [PATCH 06/16] added test running compatibility for django 1.8, workin in 1.6 and 1.7 --- quicktest.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/quicktest.py b/quicktest.py index 78724ec2..5111266b 100644 --- a/quicktest.py +++ b/quicktest.py @@ -93,14 +93,27 @@ class QuickDjangoTest(object): STATIC_URL = '/static/' ) + try: + # Django <= 1.8 + from django.test.simple import DjangoTestSuiteRunner + test_runner = DjangoTestSuiteRunner(verbosity=1) + except ImportError: + # Django >= 1.8 + from django.test.runner import DiscoverRunner + test_runner = DiscoverRunner(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) + # from django.test.simple import DjangoTestSuiteRunner + # failures = DjangoTestSuiteRunner().run_tests(self.apps, verbosity=1) + # if failures: + # sys.exit(failures) + if __name__ == '__main__': """ What do when the user hits this file from the shell. From 55dd80fa0621d9535bbd7672c57e9c5394a1159b Mon Sep 17 00:00:00 2001 From: Alex Seeholzer Date: Fri, 12 Jun 2015 15:35:58 +0200 Subject: [PATCH 07/16] removed unneccessary lines from quicktest.py and added source --- quicktest.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/quicktest.py b/quicktest.py index 5111266b..d4b5a911 100644 --- a/quicktest.py +++ b/quicktest.py @@ -93,6 +93,9 @@ 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.8 from django.test.simple import DjangoTestSuiteRunner @@ -109,11 +112,6 @@ class QuickDjangoTest(object): if failures: sys.exit(failures) - # from django.test.simple import DjangoTestSuiteRunner - # failures = DjangoTestSuiteRunner().run_tests(self.apps, verbosity=1) - # if failures: - # sys.exit(failures) - if __name__ == '__main__': """ What do when the user hits this file from the shell. From da30d2b97360d68b27d1a815eaf7ba83e1574650 Mon Sep 17 00:00:00 2001 From: Alex Seeholzer Date: Fri, 12 Jun 2015 15:27:49 +0200 Subject: [PATCH 08/16] tests renamed for compliance --- helpdesk/tests/{navigation.py => test_navigation.py} | 0 helpdesk/tests/{public_actions.py => test_public_actions.py} | 0 .../tests/{ticket_submission.py => test_ticket_submission.py} | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename helpdesk/tests/{navigation.py => test_navigation.py} (100%) rename helpdesk/tests/{public_actions.py => test_public_actions.py} (100%) rename helpdesk/tests/{ticket_submission.py => test_ticket_submission.py} (100%) 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/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 From f9682ccf37293718a2e9b2d73e1501089c7a7fec Mon Sep 17 00:00:00 2001 From: Alex Seeholzer Date: Fri, 12 Jun 2015 15:52:35 +0200 Subject: [PATCH 09/16] renamed test __init__.py imports to new test naming scheme --- helpdesk/tests/__init__.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/helpdesk/tests/__init__.py b/helpdesk/tests/__init__.py index a9d48839..5bb9a21e 100644 --- a/helpdesk/tests/__init__.py +++ b/helpdesk/tests/__init__.py @@ -1,3 +1,3 @@ -from helpdesk.tests.ticket_submission import * -from helpdesk.tests.public_actions import * -from helpdesk.tests.navigation import * \ No newline at end of file +from helpdesk.tests.test_ticket_submission import * +from helpdesk.tests.test_public_actions import * +from helpdesk.tests.test_navigation import * \ No newline at end of file From 2681f6340c6af6fdb6e3f6311a20579237d289a2 Mon Sep 17 00:00:00 2001 From: Scott Sadler Date: Fri, 6 Nov 2015 15:22:44 +0100 Subject: [PATCH 10/16] fix reload_urlconf test helper so it supports a third party urlconf --- helpdesk/tests/helpers.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) 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' From 50877c37089b2de5e7714a3546b09baca32ea03c Mon Sep 17 00:00:00 2001 From: Alex Seeholzer Date: Fri, 13 Nov 2015 14:07:36 +0100 Subject: [PATCH 11/16] Trying to fix travis build error & more general test imports: all files with test_*.py are imported from the /tests directory; --- helpdesk/tests/__init__.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/helpdesk/tests/__init__.py b/helpdesk/tests/__init__.py index 74468831..abe2f37a 100644 --- a/helpdesk/tests/__init__.py +++ b/helpdesk/tests/__init__.py @@ -1,4 +1,6 @@ -from helpdesk.tests.test_ticket_submission import * -from helpdesk.tests.test_public_actions import * -from helpdesk.tests.test_navigation import * -from helpdesk.tests.test_per_queue_staff_membership import * +from os.path import dirname, basename, isfile +import glob + +# import all test_*.py files in directory +modules = glob.glob(dirname(__file__)+"/test_*.py") +__all__ = [basename(f)[:-3] for f in modules if isfile(f)] From cd0daccb56fc08f3f1fd8cf303fdf252dfa7d8fc Mon Sep 17 00:00:00 2001 From: Alex Seeholzer Date: Fri, 13 Nov 2015 15:35:36 +0100 Subject: [PATCH 12/16] tests are correctly discovered for django < 1.6 --- helpdesk/tests/__init__.py | 13 ++++++++----- quicktest.py | 10 +++++----- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/helpdesk/tests/__init__.py b/helpdesk/tests/__init__.py index abe2f37a..807df353 100644 --- a/helpdesk/tests/__init__.py +++ b/helpdesk/tests/__init__.py @@ -1,6 +1,9 @@ -from os.path import dirname, basename, isfile -import glob +# import all test_*.py files in directory. +# neccessary for automatic discovery in django <= 1.5 +# http://stackoverflow.com/a/15780326/1382740 -# import all test_*.py files in directory -modules = glob.glob(dirname(__file__)+"/test_*.py") -__all__ = [basename(f)[:-3] for f in modules if isfile(f)] +import unittest + + +def suite(): + return unittest.TestLoader().discover("helpdesk.tests", pattern="test_*.py") diff --git a/quicktest.py b/quicktest.py index d4b5a911..cce174af 100644 --- a/quicktest.py +++ b/quicktest.py @@ -97,13 +97,13 @@ class QuickDjangoTest(object): # see: http://stackoverflow.com/questions/3841725/how-to-launch-tests-for-django-reusable-app try: - # Django <= 1.8 - from django.test.simple import DjangoTestSuiteRunner - test_runner = DjangoTestSuiteRunner(verbosity=1) - except ImportError: - # Django >= 1.8 + # 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 27c519f2eef90587fe1335236fbd7f055206f7ee Mon Sep 17 00:00:00 2001 From: Alex Seeholzer Date: Fri, 13 Nov 2015 15:36:04 +0100 Subject: [PATCH 13/16] downwards compatibility for django < 1.8 --- helpdesk/lib.py | 16 +++++++++------- helpdesk/views/staff.py | 9 +++++++-- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/helpdesk/lib.py b/helpdesk/lib.py index 1298c57b..3e031190 100644 --- a/helpdesk/lib.py +++ b/helpdesk/lib.py @@ -86,9 +86,13 @@ def send_templated_mail(template_name, email_context, recipients, sender=None, b 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 - from django.template import engines - - text_part = engines['django'].from_string( + 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 = template_func( "%s{%% include '%s' %%}" % (t.plain_text, footer_file) ).render(context) @@ -103,15 +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) - from django.template import engines - # get_template_from_string was removed in Django 1.8 http://django.readthedocs.org/en/1.8.x/ref/templates/upgrading.html - html_part = engines['django'].from_string( + html_part = template_func( "{%% extends '%s' %%}{%% block title %%}%s{%% endblock %%}{%% block content %%}%s{%% endblock %%}" % (email_html_base_file, t.heading, t.html) ).render(context) # get_template_from_string was removed in Django 1.8 http://django.readthedocs.org/en/1.8.x/ref/templates/upgrading.html - subject_part = engines['django'].from_string( + subject_part = template_func( HELPDESK_EMAIL_SUBJECT_TEMPLATE % { "subject": t.subject, }).render(context) diff --git a/helpdesk/views/staff.py b/helpdesk/views/staff.py index 22e5a538..c44073f1 100644 --- a/helpdesk/views/staff.py +++ b/helpdesk/views/staff.py @@ -370,8 +370,13 @@ def update_ticket(request, ticket_id, public=False): # get_template_from_string was removed in Django 1.8 http://django.readthedocs.org/en/1.8.x/ref/templates/upgrading.html - from django.template import engines - comment = engines['django'].from_string(comment).render(Context(context)) + 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 From 0b0f946389627d47c5afd640a9a05f75ee5f5ae7 Mon Sep 17 00:00:00 2001 From: Tony Zhu Date: Wed, 22 Apr 2015 15:25:04 -0400 Subject: [PATCH 14/16] Add the migration for changes in queues This is the missing migration for commit 9600f457d838521fc5b7011a6fea3bdf25e88213 --- helpdesk/migrations/0005_queues_no_null.py | 29 ++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 helpdesk/migrations/0005_queues_no_null.py diff --git a/helpdesk/migrations/0005_queues_no_null.py b/helpdesk/migrations/0005_queues_no_null.py new file mode 100644 index 00000000..d55e536d --- /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_initial_data_import'), + ] + + 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), + ), + ] From dbdaca8dd42296efc618ce812a099d93ad6e54cd Mon Sep 17 00:00:00 2001 From: Tony Zhu Date: Wed, 22 Apr 2015 15:26:53 -0400 Subject: [PATCH 15/16] django 1.8 email field size migration --- helpdesk/migrations/0006_email_maxlength.py | 29 +++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 helpdesk/migrations/0006_email_maxlength.py 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), + ), + ] From 0399612e57a82b85f663a413318a70eaaddc99a2 Mon Sep 17 00:00:00 2001 From: Alex Seeholzer Date: Fri, 13 Nov 2015 16:03:13 +0100 Subject: [PATCH 16/16] bugfix: migration dependency corrected --- helpdesk/migrations/0005_queues_no_null.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helpdesk/migrations/0005_queues_no_null.py b/helpdesk/migrations/0005_queues_no_null.py index d55e536d..8a678635 100644 --- a/helpdesk/migrations/0005_queues_no_null.py +++ b/helpdesk/migrations/0005_queues_no_null.py @@ -7,7 +7,7 @@ from django.db import models, migrations class Migration(migrations.Migration): dependencies = [ - ('helpdesk', '0004_initial_data_import'), + ('helpdesk', '0004_add_per_queue_staff_membership'), ] operations = [