From 307e9446a22284b66660605ad3708b96d627944d Mon Sep 17 00:00:00 2001 From: Alex Seeholzer Date: Mon, 16 Nov 2015 16:08:52 +0100 Subject: [PATCH 1/5] ensure tests for ticket submission run correctly in django 1.9 (URI's no longer include the scheme and domain part of the URLs) --- helpdesk/tests/test_ticket_submission.py | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/helpdesk/tests/test_ticket_submission.py b/helpdesk/tests/test_ticket_submission.py index e4779433..e5f9933b 100644 --- a/helpdesk/tests/test_ticket_submission.py +++ b/helpdesk/tests/test_ticket_submission.py @@ -4,6 +4,12 @@ from django.core import mail from django.test.client import Client from django.core.urlresolvers import reverse +try: # python 3 + from urllib.parse import urlparse +except ImportError: # python 2 + from urlparse import urlparse + + class TicketBasicsTestCase(TestCase): fixtures = ['emailtemplate.json'] @@ -44,11 +50,16 @@ class TicketBasicsTestCase(TestCase): last_redirect = response.redirect_chain[-1] last_redirect_url = last_redirect[0] last_redirect_status = last_redirect[1] + # Ensure we landed on the "View" page. - self.assertEqual(last_redirect_url.split('?')[0], 'http://testserver%s' % reverse('helpdesk_public_view')) + # Django 1.9 compatible way of testing this + # https://docs.djangoproject.com/en/1.9/releases/1.9/#http-redirects-no-longer-forced-to-absolute-uris + urlparts = urlparse(last_redirect_url) + self.assertEqual(urlparts.path, reverse('helpdesk_public_view')) + # Ensure submitter, new-queue + update-queue were all emailed. self.assertEqual(email_count+3, len(mail.outbox)) - + def test_create_ticket_private(self): email_count = len(mail.outbox) post_data = { @@ -83,7 +94,12 @@ class TicketBasicsTestCase(TestCase): last_redirect = response.redirect_chain[-1] last_redirect_url = last_redirect[0] last_redirect_status = last_redirect[1] + # Ensure we landed on the "View" page. - self.assertEqual(last_redirect_url.split('?')[0], 'http://testserver%s' % reverse('helpdesk_public_view')) + # Django 1.9 compatible way of testing this + # https://docs.djangoproject.com/en/1.9/releases/1.9/#http-redirects-no-longer-forced-to-absolute-uris + urlparts = urlparse(last_redirect_url) + self.assertEqual(urlparts.path, reverse('helpdesk_public_view')) + # Ensure only two e-mails were sent - submitter & updated. self.assertEqual(email_count+2, len(mail.outbox)) From e732b511e17fe358ea82b3a3682ffd0956289297 Mon Sep 17 00:00:00 2001 From: Alex Seeholzer Date: Mon, 16 Nov 2015 16:09:47 +0100 Subject: [PATCH 2/5] deprecated tags replaced in django 1.9 (ssi and url template tags are removed from the future template tag library) --- helpdesk/templates/helpdesk/public_base.html | 1 - helpdesk/templates/helpdesk/public_homepage.html | 1 - 2 files changed, 2 deletions(-) diff --git a/helpdesk/templates/helpdesk/public_base.html b/helpdesk/templates/helpdesk/public_base.html index b78c2fe3..fe80594b 100644 --- a/helpdesk/templates/helpdesk/public_base.html +++ b/helpdesk/templates/helpdesk/public_base.html @@ -1,5 +1,4 @@ {% load i18n %} -{% load url from future %} {% load load_helpdesk_settings %} {% load static from staticfiles %} {% with request|load_helpdesk_settings as helpdesk_settings %} diff --git a/helpdesk/templates/helpdesk/public_homepage.html b/helpdesk/templates/helpdesk/public_homepage.html index 786d5264..649a9d29 100644 --- a/helpdesk/templates/helpdesk/public_homepage.html +++ b/helpdesk/templates/helpdesk/public_homepage.html @@ -1,6 +1,5 @@ {% extends "helpdesk/public_base.html" %} {% load i18n bootstrap %} -{% load url from future %} {% block helpdesk_body %} From a906af367607813e85e7e30af25c18e96a4e9457 Mon Sep 17 00:00:00 2001 From: Alex Seeholzer Date: Mon, 16 Nov 2015 16:10:58 +0100 Subject: [PATCH 3/5] warnings about app_labels: reordered quicktest and added sites to INSTALLED_APPS --- quicktest.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/quicktest.py b/quicktest.py index cce174af..381c567b 100644 --- a/quicktest.py +++ b/quicktest.py @@ -19,13 +19,14 @@ class QuickDjangoTest(object): """ DIRNAME = os.path.dirname(__file__) INSTALLED_APPS = ( + 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', - 'django.contrib.sessions', - 'django.contrib.admin', - 'django.contrib.staticfiles', - 'django.contrib.messages', 'django.contrib.humanize', + 'django.contrib.messages', + 'django.contrib.sessions', + 'django.contrib.sites', + 'django.contrib.staticfiles', 'bootstrapform', ) MIDDLEWARE_CLASSES = [ From 2da16c511c2058d4a754cd835f8f720d023480ac Mon Sep 17 00:00:00 2001 From: Alex Seeholzer Date: Thu, 10 Dec 2015 13:36:24 +0100 Subject: [PATCH 4/5] updates to remove Django 1.10 deprecation warnings in Django 1.9: - use of patterns() in urls.py is deprecated - render() functions accept only dicts - introduced checks to ensure downward compatibility back to Django 1.7 --- helpdesk/lib.py | 7 ++- helpdesk/urls.py | 123 +++++++++++++++++++++------------------- helpdesk/views/staff.py | 8 ++- 3 files changed, 77 insertions(+), 61 deletions(-) diff --git a/helpdesk/lib.py b/helpdesk/lib.py index 3e031190..ff3b972f 100644 --- a/helpdesk/lib.py +++ b/helpdesk/lib.py @@ -49,6 +49,7 @@ def send_templated_mail(template_name, email_context, recipients, sender=None, b along with the File objects to be read. files can be blank. """ + from django import VERSION from django.conf import settings from django.core.mail import EmailMultiAlternatives from django.template import loader, Context @@ -57,7 +58,11 @@ def send_templated_mail(template_name, email_context, recipients, sender=None, b from helpdesk.settings import HELPDESK_EMAIL_SUBJECT_TEMPLATE import os - context = Context(email_context) + # RemovedInDjango110Warning: render() must be called with a dict, not a Context. + if VERSION >= (1, 8): + context = email_context + else: + context = Context(email_context) if hasattr(context['queue'], 'locale'): locale = getattr(context['queue'], 'locale', '') diff --git a/helpdesk/urls.py b/helpdesk/urls.py index d9dcb0dd..ab9a5437 100644 --- a/helpdesk/urls.py +++ b/helpdesk/urls.py @@ -16,7 +16,8 @@ else: from django.contrib.auth.decorators import login_required from helpdesk import settings as helpdesk_settings -from helpdesk.views import feeds +from helpdesk.views import feeds, staff, public, api, kb +from django.contrib.auth import views as auth_views from django.views.generic import TemplateView class DirectTemplateView(TemplateView): @@ -31,135 +32,135 @@ class DirectTemplateView(TemplateView): context[key] = value return context -urlpatterns = patterns('helpdesk.views.staff', +urlpatterns = [ url(r'^dashboard/$', - 'dashboard', + staff.dashboard, name='helpdesk_dashboard'), url(r'^tickets/$', - 'ticket_list', + staff.ticket_list, name='helpdesk_list'), url(r'^tickets/update/$', - 'mass_update', + staff.mass_update, name='helpdesk_mass_update'), url(r'^tickets/submit/$', - 'create_ticket', + staff.create_ticket, name='helpdesk_submit'), url(r'^tickets/(?P[0-9]+)/$', - 'view_ticket', + staff.view_ticket, name='helpdesk_view'), url(r'^tickets/(?P[0-9]+)/followup_edit/(?P[0-9]+)/$', - 'followup_edit', + staff.followup_edit, name='helpdesk_followup_edit'), url(r'^tickets/(?P[0-9]+)/followup_delete/(?P[0-9]+)/$', - 'followup_delete', + staff.followup_delete, name='helpdesk_followup_delete'), url(r'^tickets/(?P[0-9]+)/edit/$', - 'edit_ticket', + staff.edit_ticket, name='helpdesk_edit'), url(r'^tickets/(?P[0-9]+)/update/$', - 'update_ticket', + staff.update_ticket, name='helpdesk_update'), url(r'^tickets/(?P[0-9]+)/delete/$', - 'delete_ticket', + staff.delete_ticket, name='helpdesk_delete'), url(r'^tickets/(?P[0-9]+)/hold/$', - 'hold_ticket', + staff.hold_ticket, name='helpdesk_hold'), url(r'^tickets/(?P[0-9]+)/unhold/$', - 'unhold_ticket', + staff.unhold_ticket, name='helpdesk_unhold'), url(r'^tickets/(?P[0-9]+)/cc/$', - 'ticket_cc', + staff.ticket_cc, name='helpdesk_ticket_cc'), url(r'^tickets/(?P[0-9]+)/cc/add/$', - 'ticket_cc_add', + staff.ticket_cc_add, name='helpdesk_ticket_cc_add'), url(r'^tickets/(?P[0-9]+)/cc/delete/(?P[0-9]+)/$', - 'ticket_cc_del', + staff.ticket_cc_del, name='helpdesk_ticket_cc_del'), url(r'^tickets/(?P[0-9]+)/dependency/add/$', - 'ticket_dependency_add', + staff.ticket_dependency_add, name='helpdesk_ticket_dependency_add'), url(r'^tickets/(?P[0-9]+)/dependency/delete/(?P[0-9]+)/$', - 'ticket_dependency_del', + staff.ticket_dependency_del, name='helpdesk_ticket_dependency_del'), url(r'^tickets/(?P[0-9]+)/attachment_delete/(?P[0-9]+)/$', - 'attachment_del', + staff.attachment_del, name='helpdesk_attachment_del'), url(r'^raw/(?P\w+)/$', - 'raw_details', + staff.raw_details, name='helpdesk_raw'), url(r'^rss/$', - 'rss_list', + staff.rss_list, name='helpdesk_rss_index'), url(r'^reports/$', - 'report_index', + staff.report_index, name='helpdesk_report_index'), url(r'^reports/(?P\w+)/$', - 'run_report', + staff.run_report, name='helpdesk_run_report'), url(r'^save_query/$', - 'save_query', + staff.save_query, name='helpdesk_savequery'), url(r'^delete_query/(?P[0-9]+)/$', - 'delete_saved_query', + staff.delete_saved_query, name='helpdesk_delete_query'), url(r'^settings/$', - 'user_settings', + staff.user_settings, name='helpdesk_user_settings'), url(r'^ignore/$', - 'email_ignore', + staff.email_ignore, name='helpdesk_email_ignore'), url(r'^ignore/add/$', - 'email_ignore_add', + staff.email_ignore_add, name='helpdesk_email_ignore_add'), url(r'^ignore/delete/(?P[0-9]+)/$', - 'email_ignore_del', + staff.email_ignore_del, name='helpdesk_email_ignore_del'), -) +] -urlpatterns += patterns('helpdesk.views.public', +urlpatterns += [ url(r'^$', - 'homepage', + public.homepage, name='helpdesk_home'), url(r'^view/$', - 'view_ticket', + public.view_ticket, name='helpdesk_public_view'), url(r'^change_language/$', - 'change_language', + public.change_language, name='helpdesk_public_change_language'), -) +] -urlpatterns += patterns('', +urlpatterns += [ url(r'^rss/user/(?P[^/]+)/$', login_required(feeds.OpenTicketsByUser()), name='helpdesk_rss_user'), @@ -167,60 +168,66 @@ urlpatterns += patterns('', url(r'^rss/user/(?P[^/]+)/(?P[A-Za-z0-9_-]+)/$', login_required(feeds.OpenTicketsByUser()), name='helpdesk_rss_user_queue'), - + url(r'^rss/queue/(?P[A-Za-z0-9_-]+)/$', login_required(feeds.OpenTicketsByQueue()), name='helpdesk_rss_queue'), - + url(r'^rss/unassigned/$', login_required(feeds.UnassignedTickets()), name='helpdesk_rss_unassigned'), - + url(r'^rss/recent_activity/$', login_required(feeds.RecentFollowUps()), name='helpdesk_rss_activity'), - -) +] -urlpatterns += patterns('', +urlpatterns += [ url(r'^api/(?P[a-z_-]+)/$', - 'helpdesk.views.api.api', + api.api, name='helpdesk_api'), url(r'^login/$', - 'django.contrib.auth.views.login', + auth_views.login, {'template_name': 'helpdesk/registration/login.html'}, name='login'), url(r'^logout/$', - 'django.contrib.auth.views.logout', + auth_views.logout, {'template_name': 'helpdesk/registration/login.html', 'next_page': '../'}, name='logout'), -) +] if helpdesk_settings.HELPDESK_KB_ENABLED: - urlpatterns += patterns('helpdesk.views.kb', + urlpatterns += [ url(r'^kb/$', - 'index', name='helpdesk_kb_index'), + kb.index, + name='helpdesk_kb_index'), url(r'^kb/(?P[0-9]+)/$', - 'item', name='helpdesk_kb_item'), + kb.item, + name='helpdesk_kb_item'), url(r'^kb/(?P[0-9]+)/vote/$', - 'vote', name='helpdesk_kb_vote'), + kb.vote, + name='helpdesk_kb_vote'), url(r'^kb/(?P[A-Za-z0-9_-]+)/$', - 'category', name='helpdesk_kb_category'), - ) + kb.category, + name='helpdesk_kb_category'), + ] -urlpatterns += patterns('', - url(r'^api/$', TemplateView.as_view(template_name='helpdesk/help_api.html'), +urlpatterns += [ + url(r'^api/$', + TemplateView.as_view(template_name='helpdesk/help_api.html'), name='helpdesk_api_help'), - url(r'^help/context/$', TemplateView.as_view(template_name='helpdesk/help_context.html'), + url(r'^help/context/$', + TemplateView.as_view(template_name='helpdesk/help_context.html'), name='helpdesk_help_context'), - url(r'^system_settings/$', DirectTemplateView.as_view(template_name='helpdesk/system_settings.html'), + url(r'^system_settings/$', + DirectTemplateView.as_view(template_name='helpdesk/system_settings.html'), name='helpdesk_system_settings'), -) +] diff --git a/helpdesk/views/staff.py b/helpdesk/views/staff.py index af30017d..138605b7 100644 --- a/helpdesk/views/staff.py +++ b/helpdesk/views/staff.py @@ -11,6 +11,7 @@ from django.utils.encoding import python_2_unicode_compatible from datetime import datetime, timedelta import sys +from django import VERSION from django.conf import settings try: from django.contrib.auth import get_user_model @@ -374,7 +375,6 @@ def update_ticket(request, ticket_id, public=False): # then the following line will give us a crash, since django expects {% if %} # to be closed with an {% endif %} tag. - # 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 @@ -382,7 +382,11 @@ def update_ticket(request, ticket_id, public=False): except ImportError: # occurs in django < 1.8 template_func = loader.get_template_from_string - comment = template_func(comment).render(Context(context)) + # RemovedInDjango110Warning: render() must be called with a dict, not a Context. + if VERSION < (1, 8): + context = Context(context) + + comment = template_func(comment).render(context) if owner is -1 and ticket.assigned_to: owner = ticket.assigned_to.id From 905e52e603fe7d2d3f07682191282ae7d157e22d Mon Sep 17 00:00:00 2001 From: Alex Seeholzer Date: Tue, 15 Dec 2015 10:11:47 +0100 Subject: [PATCH 5/5] changed max_length given by string to integer; --- helpdesk/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helpdesk/models.py b/helpdesk/models.py index 09bd6d25..fb209e39 100644 --- a/helpdesk/models.py +++ b/helpdesk/models.py @@ -1213,7 +1213,7 @@ class CustomField(models.Model): label = models.CharField( _('Label'), - max_length='30', + max_length=30, help_text=_('The display label for this field'), )