mirror of
https://gitea.mueller.network/extern/django-helpdesk.git
synced 2024-11-25 01:13:31 +01:00
remove special-case imports for legacy versions
standardise use, or avoidance, of timezone, template from_string, and Context
This commit is contained in:
parent
b4aa7767bd
commit
7738bba2ab
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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
|
||||
|
||||
|
@ -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):
|
||||
|
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user