Skip to content

Commit

Permalink
Remove Python2 support
Browse files Browse the repository at this point in the history
  • Loading branch information
dodobas committed Jul 25, 2018
1 parent 913186d commit 87ed085
Show file tree
Hide file tree
Showing 47 changed files with 78 additions and 166 deletions.
6 changes: 0 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ language: python
sudo: false

python:
- 2.7
- 3.4
- 3.5
- 3.6
Expand All @@ -11,11 +10,6 @@ env:
- DJANGO_VERSION=1.11.14
- DJANGO_VERSION=2.0.7

matrix:
exclude:
- python: 2.7
env: DJANGO_VERSION=2.0.7

install:
- pip install -q -r requirements/base.txt
- pip install -q -r requirements/tests.txt
Expand Down
3 changes: 2 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
2.0.0 (2018-07-16)
2.0.0 (2018-07-25)
==================

* Add support for Django 2.0, drop support for Django 1.9 and Django 1.10
* Drop support for Python2

1.11.9 (2018-05-3)
===================
Expand Down
1 change: 0 additions & 1 deletion requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ django>=1.11,<2.1
django_compressor
pytz
redis
six
sqlparse
xlrd
xlwt
1 change: 0 additions & 1 deletion requirements/tests.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
psycopg2
mock
funcsigs
flake8
2 changes: 0 additions & 2 deletions smartmin/backends.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import unicode_literals

from django.contrib.auth import get_user_model
from django.contrib.auth.backends import ModelBackend

Expand Down
3 changes: 0 additions & 3 deletions smartmin/csv_imports/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations
from django.conf import settings

Expand Down
4 changes: 0 additions & 4 deletions smartmin/csv_imports/migrations/0002_auto_20161118_1920.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.6 on 2016-11-18 19:20
from __future__ import unicode_literals

from django.db import migrations, models
import smartmin.csv_imports.models

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import migrations, models


Expand Down
4 changes: 0 additions & 4 deletions smartmin/csv_imports/migrations/0004_auto_20170223_0917.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.4 on 2017-02-23 09:17
from __future__ import unicode_literals

from django.db import migrations, models
import django.utils.timezone

Expand Down
3 changes: 1 addition & 2 deletions smartmin/csv_imports/models.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
from __future__ import unicode_literals

import os

from django.db import models
from django.utils import timezone
from django.utils.module_loading import import_string

from smartmin.models import SmartModel


Expand Down
13 changes: 4 additions & 9 deletions smartmin/csv_imports/tasks.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
from __future__ import unicode_literals
from io import StringIO

import six
from celery.task import task

from django.db import transaction
from django.utils import timezone
from django.utils.module_loading import import_string
from .models import ImportTask

# python2 and python3 support
try:
from StringIO import StringIO
except ImportError:
from io import StringIO
from .models import ImportTask


@task(track_started=True)
Expand Down Expand Up @@ -42,7 +37,7 @@ def csv_import(task_id): # pragma: no cover

task_obj.task_status = ImportTask.FAILURE

task_obj.log("\nError: %s\n" % six.text_type(e))
task_obj.log("\nError: %s\n" % str(e))
task_obj.log(log.getvalue())
task_obj.save()

Expand Down
3 changes: 1 addition & 2 deletions smartmin/csv_imports/tests.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from __future__ import unicode_literals

from django.test import TestCase

from .models import ImportTask, generate_file_path


Expand Down
2 changes: 0 additions & 2 deletions smartmin/csv_imports/urls.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import unicode_literals

from smartmin.csv_imports.views import ImportTaskCRUDL


Expand Down
3 changes: 1 addition & 2 deletions smartmin/csv_imports/views.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from __future__ import unicode_literals

from django.utils.module_loading import import_string

from smartmin.csv_imports.models import ImportTask
from smartmin.views import SmartCRUDL, SmartListView, SmartReadView

Expand Down
2 changes: 0 additions & 2 deletions smartmin/email.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import unicode_literals

from django.conf import settings
from django.utils.module_loading import import_string

Expand Down
6 changes: 2 additions & 4 deletions smartmin/management/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
from __future__ import unicode_literals

import six
import sys

from django.apps import apps
Expand All @@ -9,6 +6,7 @@
from django.contrib.auth.models import Permission, Group
from django.core.exceptions import ObjectDoesNotExist
from django.db.models.signals import post_migrate

from smartmin.perms import assign_perm, remove_perm

permissions_app_name = None
Expand Down Expand Up @@ -88,7 +86,7 @@ def check_role_permissions(role, permissions, current_permissions):

# remove any that are extra
for permission in current_permissions:
if isinstance(permission, six.text_type):
if isinstance(permission, str):
key = permission
else:
key = "%s.%s" % (permission.content_type.app_label, permission.codename)
Expand Down
15 changes: 6 additions & 9 deletions smartmin/management/commands/collect_sql.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
from __future__ import print_function, unicode_literals

import six
import sqlparse

from collections import OrderedDict
from datetime import datetime
from django.core.management.base import BaseCommand
from django.db.migrations import RunSQL
from django.db.migrations.executor import MigrationExecutor
from enum import Enum
from six.moves import filter

import sqlparse
from sqlparse import sql
from sqlparse import tokens as sql_tokens
from textwrap import dedent

from django.core.management.base import BaseCommand
from django.db.migrations import RunSQL
from django.db.migrations.executor import MigrationExecutor


class InvalidSQLException(Exception):
def __init__(self, s):
Expand All @@ -29,7 +27,6 @@ class SqlType(Enum):
TRIGGER = 3


@six.python_2_unicode_compatible
class SqlObjectOperation(object):
def __init__(self, statement, sql_type, obj_name, is_create):
self.statement = statement
Expand Down
4 changes: 1 addition & 3 deletions smartmin/management/commands/migrate_manual.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
from __future__ import unicode_literals

import time
from importlib import import_module

from django.core.management.base import BaseCommand, CommandError
from django.core.management.sql import emit_pre_migrate_signal, emit_post_migrate_signal
from django.db import DEFAULT_DB_ALIAS, connections
from django.db.migrations.executor import MigrationExecutor
from django.db.migrations.loader import AmbiguityError
from importlib import import_module

APPLY_FUNCTION = 'apply_manual'

Expand Down
4 changes: 2 additions & 2 deletions smartmin/management/tests.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from __future__ import unicode_literals
from unittest.mock import patch, call

from django.core.management import call_command
from django.db.migrations import RunSQL, RunPython
from django.test import TestCase
from mock import patch, call

from .commands.collect_sql import SqlType, SqlObjectOperation


Expand Down
38 changes: 24 additions & 14 deletions smartmin/middleware.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
from __future__ import unicode_literals

import os
import sys
from io import StringIO

from django.conf import settings
from django.http import HttpResponseRedirect, HttpResponse
from django.utils import timezone
from six.moves import StringIO

try:
from django.utils.deprecation import MiddlewareMixin
except ImportError:
class MiddlewareMixin(object):
pass

class AjaxRedirect:

def __init__(self, get_response=None):
self.get_response = get_response

def __call__(self, request):
response = self.get_response(request)

class AjaxRedirect(MiddlewareMixin):
def process_response(self, request, response):
if request.is_ajax():
if type(response) == HttpResponseRedirect:
# This is our own AJAX friend redirect to allow
Expand All @@ -27,9 +25,13 @@ def process_response(self, request, response):
return response


class ProfileMiddleware(MiddlewareMixin):
class ProfileMiddleware:
def __init__(self, get_response=None):
pass
self.get_response = get_response

def __call__(self, request):
response = self.get_response(request)
return response

def process_view(self, request, view, *args, **kwargs):
import hotshot, hotshot.stats # noqa
Expand Down Expand Up @@ -69,9 +71,17 @@ def process_view(self, request, view, *args, **kwargs):
return None


class TimezoneMiddleware(MiddlewareMixin):
def process_request(self, request):
class TimezoneMiddleware:

def __init__(self, get_response=None):
self.get_response = get_response

def __call__(self, request):
response = self.get_response(request)

user_tz = getattr(settings, 'USER_TIME_ZONE', None)

if user_tz:
timezone.activate(user_tz)

return response
1 change: 0 additions & 1 deletion smartmin/mixins.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import unicode_literals
"""
simple mixins that keep you from writing so much code
"""
Expand Down
3 changes: 1 addition & 2 deletions smartmin/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import unicode_literals

import csv
import datetime
import traceback
Expand All @@ -10,6 +8,7 @@
from django.conf import settings
from django.db import models
from django.utils import timezone

from xlrd import open_workbook, xldate_as_tuple, XL_CELL_DATE, XLRDError


Expand Down
5 changes: 2 additions & 3 deletions smartmin/pdf.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from __future__ import unicode_literals
import os
from io import StringIO

import ho.pisa as pisa
import os
import StringIO

from django.conf import settings
from django.http import HttpResponse
Expand Down
2 changes: 0 additions & 2 deletions smartmin/perms.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import unicode_literals

from django.contrib.auth.models import Permission


Expand Down
3 changes: 1 addition & 2 deletions smartmin/templatetags/smartmin.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
from __future__ import unicode_literals

import json
import pytz
import re

from datetime import datetime, timedelta

from django import template
from django.conf import settings
from django.urls import reverse
Expand Down
6 changes: 2 additions & 4 deletions smartmin/tests.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
from __future__ import unicode_literals

import six
from urllib.parse import urlparse

from django.conf import settings
from django.contrib.auth import get_user_model
from django.contrib.auth.models import Group
from django.urls import reverse
from django.test.testcases import TestCase
from django.utils.encoding import force_str
from six.moves.urllib.parse import urlparse


class SmartminTestMixin(object):
Expand Down Expand Up @@ -72,7 +70,7 @@ def assertNoFormErrors(self, response, post_data=None):

if not form.is_valid():
errors = []
for k, v in six.iteritems(form.errors):
for k, v in form.errors.items():
errors.append("%s=%s" % (k, force_str(v)))
self.fail("Create failed with form errors: %s, Posted: %s" % (",".join(errors), post_data))

Expand Down
1 change: 0 additions & 1 deletion smartmin/users/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
from __future__ import unicode_literals
Loading

0 comments on commit 87ed085

Please sign in to comment.