Remove old python2/six code

This commit is contained in:
Garret Wassermann 2018-12-28 03:13:52 -05:00
parent 41d71e9062
commit 696d10db12
34 changed files with 52 additions and 142 deletions

View File

@ -11,6 +11,17 @@ scripts/get_email.py - Designed to be run from cron, this script checks the
helpdesk, creating tickets from the new messages (or
adding to existing tickets if needed)
"""
from django.core.files.base import ContentFile
from django.core.files.uploadedfile import SimpleUploadedFile
from django.core.management.base import BaseCommand
from django.db.models import Q
from django.utils.translation import ugettext as _
from django.utils import encoding, timezone
from django.contrib.auth.models import User
from helpdesk import settings
from helpdesk.lib import safe_template_context, process_attachments
from helpdesk.models import Queue, Ticket, TicketCC, FollowUp, IgnoreEmail
from datetime import timedelta
import base64
@ -31,18 +42,6 @@ from bs4 import BeautifulSoup
from email_reply_parser import EmailReplyParser
from django.core.files.base import ContentFile
from django.core.files.uploadedfile import SimpleUploadedFile
from django.core.management.base import BaseCommand
from django.db.models import Q
from django.utils.translation import ugettext as _
from django.utils import encoding, timezone
from helpdesk import settings
from helpdesk.lib import safe_template_context, process_attachments
from helpdesk.models import Queue, Ticket, TicketCC, FollowUp, IgnoreEmail
from django.contrib.auth.models import User
import logging

View File

@ -9,7 +9,6 @@ forms.py - Definitions of newforms-based forms for creating and maintaining
from django.core.exceptions import ObjectDoesNotExist
from django.utils.six import StringIO
from django import forms
from django.forms import widgets
from django.conf import settings

View File

@ -8,17 +8,15 @@ scripts/create_escalation_exclusion.py - Easy way to routinely add particular
days to the list of days on which no
escalation should take place.
"""
from __future__ import print_function
from django.core.management.base import BaseCommand, CommandError
from helpdesk.models import EscalationExclusion, Queue
from datetime import timedelta, date
import getopt
from optparse import make_option
import sys
from django.core.management.base import BaseCommand, CommandError
from helpdesk.models import EscalationExclusion, Queue
class Command(BaseCommand):

View File

@ -7,7 +7,6 @@ django-helpdesk - A Django powered ticket tracker for small enterprise.
scripts/escalate_tickets.py - Easy way to escalate tickets based on their age,
designed to be run from Cron or similar.
"""
from __future__ import print_function
from datetime import timedelta, date
import getopt
@ -17,11 +16,7 @@ import sys
from django.core.management.base import BaseCommand, CommandError
from django.db.models import Q
from django.utils.translation import ugettext as _
try:
from django.utils import timezone
except ImportError:
from datetime import datetime as timezone
from django.utils import timezone
from helpdesk.models import Queue, Ticket, FollowUp, EscalationExclusion, TicketChange
from helpdesk.lib import safe_template_context

View File

@ -1,9 +1,8 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
import django.utils.timezone
from django.conf import settings
import helpdesk.models

View File

@ -1,6 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.contrib.auth import get_user_model
from django.db import models, migrations

View File

@ -1,6 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import os
from sys import path

View File

@ -1,6 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
from django.conf import settings

View File

@ -1,6 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations

View File

@ -1,6 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations

View File

@ -1,6 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations

View File

@ -1,6 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations

View File

@ -1,6 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.core.exceptions import ObjectDoesNotExist
from django.db import migrations
from django.db.utils import IntegrityError

View File

@ -1,6 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations

View File

@ -1,6 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations

View File

@ -1,7 +1,5 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.2 on 2016-02-15 21:37
from __future__ import unicode_literals
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion

View File

@ -1,7 +1,5 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.1 on 2016-09-14 23:47
from __future__ import unicode_literals
from django.db import migrations, models

View File

@ -1,6 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
from django.conf import settings

View File

@ -1,7 +1,5 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.5 on 2017-02-10 19:27
from __future__ import unicode_literals
from django.db import migrations, models

View File

@ -1,7 +1,5 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.2 on 2017-03-08 17:51
from __future__ import unicode_literals
from django.db import migrations

View File

@ -1,8 +1,5 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.2 on 2018-01-19 09:48
from __future__ import unicode_literals
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion

View File

@ -1,5 +1,4 @@
# Generated by Django 2.0.1 on 2018-09-07 21:22
from django.db import migrations, models
import helpdesk.models

View File

@ -1,5 +1,4 @@
# Generated by Django 2.0.1 on 2018-09-07 21:22
from django.db import migrations, models
import helpdesk.models

View File

@ -1,8 +1,8 @@
# Generated by Django 2.0.7 on 2018-10-19 14:11
from django.db import migrations, models
import helpdesk.models
def unpickle_settings(settings_pickled):
# return a python dictionary representing the pickled data.
try:
@ -11,13 +11,11 @@ def unpickle_settings(settings_pickled):
import cPickle as pickle
from helpdesk.lib import b64decode
try:
if six.PY2:
return pickle.loads(b64decode(str(settings_pickled)))
else:
return pickle.loads(b64decode(settings_pickled.encode('utf-8')))
return pickle.loads(b64decode(settings_pickled.encode('utf-8')))
except Exception:
return {}
def move_old_values(apps, schema_editor):
UserSettings = apps.get_model("helpdesk", "UserSettings")
db_alias = schema_editor.connection.alias
@ -28,6 +26,7 @@ def move_old_values(apps, schema_editor):
for setting, value in settings_dict.items():
user_settings.__set_attr__(setting, value)
class Migration(migrations.Migration):
dependencies = [

View File

@ -1,5 +1,4 @@
# Generated by Django 2.1.2 on 2018-10-17 17:37
from django.conf import settings
from django.db import migrations, models

View File

@ -7,7 +7,6 @@ models.py - Model (and hence database) definitions. This is the core of the
helpdesk structure.
"""
from __future__ import unicode_literals
from django.contrib.auth.models import Permission
from django.contrib.auth import get_user_model
from django.contrib.contenttypes.models import ContentType
@ -15,18 +14,15 @@ from django.core.exceptions import ObjectDoesNotExist
from django.db import models
from django.conf import settings
from django.utils import timezone
from django.utils import six
from django.utils.translation import ugettext_lazy as _, ugettext
from django.utils.encoding import python_2_unicode_compatible
from io import StringIO
import re
import six
import uuid
from .templated_email import send_templated_mail
@python_2_unicode_compatible
class Queue(models.Model):
"""
A queue is a collection of tickets into what would generally be business
@ -358,7 +354,6 @@ def mk_secret():
return str(uuid.uuid4())
@python_2_unicode_compatible
class Ticket(models.Model):
"""
To allow a ticket to be entered as quickly as possible, only the
@ -694,7 +689,6 @@ class FollowUpManager(models.Manager):
return self.filter(public=True)
@python_2_unicode_compatible
class FollowUp(models.Model):
"""
A FollowUp is a comment and/or change to a ticket. We keep a simple
@ -776,7 +770,6 @@ class FollowUp(models.Model):
super(FollowUp, self).save(*args, **kwargs)
@python_2_unicode_compatible
class TicketChange(models.Model):
"""
For each FollowUp, any changes to the parent ticket (eg Title, Priority,
@ -839,7 +832,6 @@ def attachment_path(instance, filename):
return os.path.join(path, filename)
@python_2_unicode_compatible
class Attachment(models.Model):
"""
Represents a file attached to a follow-up. This could come from an e-mail
@ -882,7 +874,6 @@ class Attachment(models.Model):
verbose_name_plural = _('Attachments')
@python_2_unicode_compatible
class PreSetReply(models.Model):
"""
We can allow the admin to define a number of pre-set replies, used to
@ -924,7 +915,6 @@ class PreSetReply(models.Model):
return '%s' % self.name
@python_2_unicode_compatible
class EscalationExclusion(models.Model):
"""
An 'EscalationExclusion' lets us define a date on which escalation should
@ -961,7 +951,6 @@ class EscalationExclusion(models.Model):
verbose_name_plural = _('Escalation exclusions')
@python_2_unicode_compatible
class EmailTemplate(models.Model):
"""
Since these are more likely to be changed than other templates, we store
@ -1021,7 +1010,6 @@ class EmailTemplate(models.Model):
verbose_name_plural = _('e-mail templates')
@python_2_unicode_compatible
class KBCategory(models.Model):
"""
Lets help users help themselves: the Knowledge Base is a categorised
@ -1054,7 +1042,6 @@ class KBCategory(models.Model):
return reverse('helpdesk:kb_category', kwargs={'slug': self.slug})
@python_2_unicode_compatible
class KBItem(models.Model):
"""
An item within the knowledgebase. Very straightforward question/answer
@ -1123,7 +1110,6 @@ class KBItem(models.Model):
return reverse('helpdesk:kb_item', args=(self.id,))
@python_2_unicode_compatible
class SavedSearch(models.Model):
"""
Allow a user to save a ticket search, eg their filtering and sorting
@ -1195,7 +1181,6 @@ def use_email_as_submitter_default():
return get_default_setting('use_email_as_submitter')
@python_2_unicode_compatible
class UserSettings(models.Model):
"""
A bunch of user-specific settings that we want to be able to define, such
@ -1275,7 +1260,6 @@ def create_usersettings(sender, instance, created, **kwargs):
models.signals.post_save.connect(create_usersettings, sender=settings.AUTH_USER_MODEL)
@python_2_unicode_compatible
class IgnoreEmail(models.Model):
"""
This model lets us easily ignore e-mails from certain senders when
@ -1362,7 +1346,6 @@ class IgnoreEmail(models.Model):
return False
@python_2_unicode_compatible
class TicketCC(models.Model):
"""
Often, there are people who wish to follow a ticket who aren't the
@ -1433,7 +1416,6 @@ class CustomFieldManager(models.Manager):
return super(CustomFieldManager, self).get_queryset().order_by('ordering')
@python_2_unicode_compatible
class CustomField(models.Model):
"""
Definitions for custom fields that are glued onto each ticket.
@ -1517,7 +1499,6 @@ class CustomField(models.Model):
)
def _choices_as_array(self):
from django.utils.six import StringIO
valuebuffer = StringIO(self.list_values)
choices = [[item.strip(), item.strip()] for item in valuebuffer.readlines()]
valuebuffer.close()
@ -1547,7 +1528,6 @@ class CustomField(models.Model):
verbose_name_plural = _('Custom fields')
@python_2_unicode_compatible
class TicketCustomFieldValue(models.Model):
ticket = models.ForeignKey(
Ticket,
@ -1572,7 +1552,6 @@ class TicketCustomFieldValue(models.Model):
verbose_name_plural = _('Ticket custom field values')
@python_2_unicode_compatible
class TicketDependency(models.Model):
"""
The ticket identified by `ticket` cannot be resolved until the ticket in `depends_on` has been resolved.

View File

@ -4,7 +4,6 @@ django-helpdesk - A Django powered ticket tracker for small enterprise.
templatetags/load_helpdesk_settings.py - returns the settings as defined in
django-helpdesk/helpdesk/settings.py
"""
from __future__ import print_function
from django.template import Library
from helpdesk import settings as helpdesk_settings_config

View File

@ -5,9 +5,9 @@ templatetags/saved_queries.py - This template tag returns previously saved
queries. Therefore you don't need to modify
any views.
"""
from __future__ import print_function
from django.template import Library
from django.db.models import Q
from helpdesk.models import SavedSearch

View File

@ -10,15 +10,14 @@ templatetags/ticket_to_link.py - Used in ticket comments to allow wiki-style
to show the status of that ticket (eg a closed
ticket would have a strikethrough).
"""
import re
from django import template
from django.urls import reverse
from django.utils.safestring import mark_safe
from helpdesk.models import Ticket
import re
def num_to_link(text):
if text == '':

View File

@ -22,11 +22,7 @@ def get_staff_user(username='helpdesk.staff', password='password'):
def reload_urlconf(urlconf=None):
from django.utils import six
if six.PY2:
from imp import reload
else:
from importlib import reload
from importlib import reload
if urlconf is None:
from django.conf import settings

View File

@ -1,10 +1,4 @@
# vim: set fileencoding=utf-8 :
from __future__ import unicode_literals
import os
import shutil
from tempfile import gettempdir
from django.core.files.uploadedfile import SimpleUploadedFile
from django.urls import reverse
from django.test import override_settings, TestCase
@ -12,12 +6,12 @@ from django.utils.encoding import smart_text
from helpdesk import lib, models
try:
# Python >= 3.3
from unittest import mock
except ImportError:
# Python < 3.3
import mock
import os
import shutil
from tempfile import gettempdir
from unittest import mock
MEDIA_DIR = os.path.join(gettempdir(), 'helpdesk_test_media')

View File

@ -1,30 +1,21 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from helpdesk.models import Queue, Ticket, TicketCC, FollowUp, Attachment
from django.test import TestCase
from django.core.management import call_command
from django.utils import six
from django.shortcuts import get_object_or_404
from django.contrib.auth.models import User
from django.contrib.auth.hashers import make_password
from helpdesk.models import Queue, Ticket, TicketCC, FollowUp, Attachment
import itertools
from shutil import rmtree
import sys
from tempfile import mkdtemp
try: # python 3
from urllib.parse import urlparse
except ImportError: # python 2
from urlparse import urlparse
try:
# Python >= 3.3
from unittest import mock
except ImportError:
# Python < 3.3
import mock
from urllib.parse import urlparse
from unittest import mock
# class A addresses can't have first octet of 0
unrouted_socks_server = "0.0.0.1"
@ -100,7 +91,7 @@ class GetEmailParametricTemplate(object):
if self.method == 'local':
with mock.patch('helpdesk.email.listdir') as mocked_listdir, \
mock.patch('helpdesk.email.isfile') as mocked_isfile, \
mock.patch('builtins.open' if six.PY3 else '__builtin__.open', mock.mock_open(read_data=test_email)):
mock.patch('builtins.open', mock.mock_open(read_data=test_email)):
mocked_isfile.return_value = True
mocked_listdir.return_value = ['filename1', 'filename2']
@ -173,7 +164,7 @@ class GetEmailParametricTemplate(object):
if self.method == 'local':
with mock.patch('helpdesk.email.listdir') as mocked_listdir, \
mock.patch('helpdesk.email.isfile') as mocked_isfile, \
mock.patch('builtins.open' if six.PY3 else '__builtin__.open', mock.mock_open(read_data=test_email)):
mock.patch('builtins.open', mock.mock_open(read_data=test_email)):
mocked_isfile.return_value = True
mocked_listdir.return_value = ['filename1', 'filename2']
@ -286,7 +277,7 @@ class GetEmailParametricTemplate(object):
if self.method == 'local':
with mock.patch('helpdesk.email.listdir') as mocked_listdir, \
mock.patch('helpdesk.email.isfile') as mocked_isfile, \
mock.patch('builtins.open' if six.PY3 else '__builtin__.open', mock.mock_open(read_data=msg.as_string())):
mock.patch('builtins.open', mock.mock_open(read_data=msg.as_string())):
mocked_isfile.return_value = True
mocked_listdir.return_value = ['filename1', 'filename2']
@ -533,7 +524,7 @@ a9eiiQ+3V1v+7wWHXCzq
if self.method == 'local':
with mock.patch('helpdesk.email.listdir') as mocked_listdir, \
mock.patch('helpdesk.email.isfile') as mocked_isfile, \
mock.patch('builtins.open' if six.PY3 else '__builtin__.open', mock.mock_open(read_data=test_email)):
mock.patch('builtins.open', mock.mock_open(read_data=test_email)):
mocked_isfile.return_value = True
mocked_listdir.return_value = ['filename1']
@ -703,7 +694,7 @@ class GetEmailCCHandling(TestCase):
with mock.patch('helpdesk.email.listdir') as mocked_listdir, \
mock.patch('helpdesk.email.isfile') as mocked_isfile, \
mock.patch('builtins.open' if six.PY3 else '__builtin__.open', mock.mock_open(read_data=test_email)):
mock.patch('builtins.open', mock.mock_open(read_data=test_email)):
mocked_isfile.return_value = True
mocked_listdir.return_value = ['filename1']

View File

@ -6,10 +6,6 @@ django-helpdesk - A Django powered ticket tracker for small enterprise.
views/staff.py - The bulk of the application - provides most business logic and
renders all staff-facing views.
"""
from __future__ import unicode_literals
from datetime import date, datetime, timedelta
import re
from django import VERSION as DJANGO_VERSION
from django.conf import settings
from django.contrib.auth import get_user_model
@ -27,14 +23,9 @@ from django.utils.html import escape
from django import forms
from django.utils import timezone
from django.views.generic.edit import FormView, UpdateView
from django.utils import six
# For datatables serverside
from django.core.cache import cache
from rest_framework import viewsets, status
from rest_framework.response import Response
from rest_framework.decorators import api_view
from helpdesk.lib import query_tickets_by_args
from helpdesk.serializers import TicketSerializer
@ -57,6 +48,14 @@ from helpdesk.models import (
from helpdesk import settings as helpdesk_settings
from helpdesk.views.permissions import MustBeStaffMixin
from rest_framework import viewsets, status
from rest_framework.response import Response
from rest_framework.decorators import api_view
from datetime import date, datetime, timedelta
import re
User = get_user_model()
if helpdesk_settings.HELPDESK_ALLOW_NON_STAFF_TICKET_UPDATE:

View File

@ -6,7 +6,7 @@ from distutils.util import convert_path
from fnmatch import fnmatchcase
from setuptools import setup, find_packages
version = '0.3.0.dev1'
version = '0.3.0.dev2'
# Provided as an attribute, so you can append to these instead
# of replicating them: