Merge pull request #454 from reduxionist/prune-legacy-code

Prune legacy code
This commit is contained in:
Jonathan Barratt 2016-11-21 20:32:35 +07:00 committed by GitHub
commit cac3267e82
6 changed files with 18 additions and 105 deletions

View File

@ -6,19 +6,16 @@ django-helpdesk - A Django powered ticket tracker for small enterprise.
forms.py - Definitions of newforms-based forms for creating and maintaining
tickets.
"""
from django.core.exceptions import ObjectDoesNotExist
from django.utils.six import StringIO
from django import forms
from django.forms import extras
from django.conf import settings
from django.utils.translation import ugettext_lazy as _
from django.contrib.auth import get_user_model
try:
from django.utils import timezone
except ImportError:
from datetime import datetime as timezone
from django.utils import timezone
from helpdesk.lib import send_templated_mail, safe_template_context
from helpdesk.models import (Ticket, Queue, FollowUp, Attachment, IgnoreEmail, TicketCC,

View File

@ -57,21 +57,15 @@ def send_templated_mail(template_name,
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
from helpdesk.models import EmailTemplate
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.
if VERSION >= (1, 8):
context = email_context
else:
context = Context(email_context)
context = email_context
if hasattr(context['queue'], 'locale'):
locale = getattr(context['queue'], 'locale', '')
@ -99,13 +93,8 @@ def send_templated_mail(template_name,
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
from django.template import engines
template_func = engines['django'].from_string
text_part = template_func(
"%s{%% include '%s' %%}" % (t.plain_text, footer_file)
@ -119,16 +108,12 @@ def send_templated_mail(template_name,
html_txt = html_txt.replace('\r\n', '<br>')
context['comment'] = mark_safe(html_txt)
# 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)
# 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,

View File

@ -27,19 +27,13 @@ from optparse import make_option
from email_reply_parser import EmailReplyParser
from django import VERSION
from django.core.files.base import ContentFile
from django.core.management.base import BaseCommand
from django.db.models import Q
from django.utils.translation import ugettext as _
from django.utils import six
from django.utils import six, timezone
from helpdesk import settings
try:
from django.utils import timezone
except ImportError:
from datetime import datetime as timezone
from helpdesk.lib import send_templated_mail, safe_template_context
from helpdesk.models import Queue, Ticket, FollowUp, Attachment, IgnoreEmail

View File

@ -13,14 +13,10 @@ from django.contrib.contenttypes.models import ContentType
from django.core.exceptions import ObjectDoesNotExist
from django.db import models
from django.conf import settings
from django.utils import timezone
from django.utils.translation import ugettext_lazy as _, ugettext
from django.utils.encoding import python_2_unicode_compatible
try:
from django.utils import timezone
except ImportError:
from datetime import datetime as timezone
@python_2_unicode_compatible
class Queue(models.Model):

View File

@ -9,7 +9,6 @@ views/staff.py - The bulk of the application - provides most business logic and
from __future__ import unicode_literals
from datetime import datetime, timedelta
from django import VERSION
from django.conf import settings
from django.contrib.auth import get_user_model
from django.contrib.auth.decorators import user_passes_test
@ -24,11 +23,7 @@ from django.utils.dates import MONTHS_3
from django.utils.translation import ugettext as _
from django.utils.html import escape
from django import forms
try:
from django.utils import timezone
except ImportError:
from datetime import datetime as timezone
from django.utils import timezone
from helpdesk.forms import (
TicketForm, UserSettingsForm, EmailIgnoreForm, EditTicketForm, TicketCCForm,
@ -407,25 +402,14 @@ def update_ticket(request, ticket_id, public=False):
# We need to allow the 'ticket' and 'queue' contexts to be applied to the
# comment.
from django.template import loader, Context
context = safe_template_context(ticket)
# this line sometimes creates problems if code is sent as a comment.
# 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.
# 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
# RemovedInDjango110Warning: render() must be called with a dict, not a Context.
if VERSION < (1, 8):
context = Context(context)
from django.template import engines
template_func = engines['django'].from_string
comment = template_func(comment).render(context)
if owner is -1 and ticket.assigned_to:

View File

@ -61,41 +61,9 @@ class QuickDjangoTest(object):
def __init__(self, *args, **kwargs):
self.apps = args
# Get the version of the test suite
self.version = self.get_test_version()
# Call the appropriate one
if self.version == 'new':
self._new_tests()
else:
self._old_tests()
self._tests()
def get_test_version(self):
"""
Figure out which version of Django's test suite we have to play with.
"""
if django.VERSION >= (1, 2):
return 'new'
else:
return 'old'
def _old_tests(self):
"""
Fire up the Django test suite from before version 1.2
"""
settings.configure(DEBUG=True,
DATABASE_ENGINE='sqlite3',
DATABASE_NAME=os.path.join(self.DIRNAME, 'database.db'),
INSTALLED_APPS=self.INSTALLED_APPS + self.apps
)
from django.test.simple import run_tests
failures = run_tests(self.apps, verbosity=1)
if failures:
sys.exit(failures)
def _new_tests(self):
"""
Fire up the Django test suite developed for version 1.2
"""
def _tests(self):
settings.configure(
DEBUG=True,
@ -116,20 +84,9 @@ class QuickDjangoTest(object):
TEMPLATES=self.TEMPLATES
)
# 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.runner import DiscoverRunner
test_runner = DiscoverRunner(verbosity=1)
django.setup()
failures = test_runner.run_tests(self.apps)
if failures: