Skip to content

Commit 7f28b79

Browse files
committed
Cleanup and linting
1 parent 64c3809 commit 7f28b79

File tree

4 files changed

+11
-36
lines changed

4 files changed

+11
-36
lines changed

simple_history/manager.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ def _as_of_set(self, date):
8989
queryset.order_by().values_list(pk_attr, flat=True)):
9090
changes = queryset.filter(**{pk_attr: original_pk})
9191
last_change = changes.latest('history_date')
92-
if changes.filter(history_date=last_change.history_date, history_type='-').exists():
92+
if changes.filter(history_date=last_change.history_date,
93+
history_type='-').exists():
9394
continue
9495
yield last_change.instance

simple_history/models.py

Lines changed: 6 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,12 @@
1111
from django.db.models.related import RelatedObject
1212
from django.conf import settings
1313
from django.contrib import admin
14-
from django.utils import importlib
14+
from django.utils import importlib, six
15+
from django.utils.encoding import python_2_unicode_compatible
1516
try:
1617
from django.utils.encoding import smart_text
1718
except ImportError:
18-
smart_text = unicode
19-
try:
20-
from django.utils.six import text_type
21-
except ImportError:
22-
text_type = unicode
19+
from django.utils.encoding import smart_unicode as smart_text
2320
try:
2421
from django.utils.timezone import now
2522
except ImportError:
@@ -28,29 +25,6 @@
2825
from django.utils.translation import string_concat
2926
from .manager import HistoryDescriptor
3027

31-
try:
32-
basestring
33-
except NameError:
34-
basestring = str # Python 3 has no basestring
35-
36-
try:
37-
from django.utils.encoding import python_2_unicode_compatible
38-
except ImportError: # django 1.3 compatibility
39-
import sys
40-
41-
# copy of django function without use of six
42-
def python_2_unicode_compatible(klass):
43-
"""
44-
Decorator defining __unicode__ and __str__ as appropriate for Py2/3
45-
46-
Usage: define __str__ method and apply this decorator to the class.
47-
"""
48-
if sys.version_info[0] != 3:
49-
klass.__unicode__ = klass.__str__
50-
klass.__str__ = lambda self: self.__unicode__().encode('utf-8')
51-
return klass
52-
53-
5428
registered_models = {}
5529

5630

@@ -62,7 +36,7 @@ def __init__(self, verbose_name=None, bases=(models.Model,),
6236
self.user_set_verbose_name = verbose_name
6337
self.user_related_name = user_related_name
6438
try:
65-
if isinstance(bases, basestring):
39+
if isinstance(bases, six.string_types):
6640
raise TypeError
6741
self.bases = tuple(bases)
6842
except TypeError:
@@ -254,7 +228,7 @@ def get_one_to_one_field(self, to_field, other):
254228
# recursive
255229
temp_field = self.__class__(to_field.rel.to._meta.object_name)
256230
for key, val in to_field.__dict__.items():
257-
if (isinstance(key, basestring)
231+
if (isinstance(key, six.string_types)
258232
and not key.startswith('_')):
259233
setattr(temp_field, key, val)
260234
field = self.__class__.get_field(
@@ -295,7 +269,7 @@ def get_field(self, other, cls):
295269
"blank",
296270
)
297271
for key, val in to_field.__dict__.items():
298-
if (isinstance(key, basestring)
272+
if (isinstance(key, six.string_types)
299273
and not key.startswith(excluded_prefixes)
300274
and key not in excluded_attributes):
301275
setattr(field, key, val)

simple_history/tests/tests/test_admin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ def test_middleware_saves_user(self):
192192
self.assertEqual(historical_poll.history_user, self.user,
193193
"Middleware should make the request available to "
194194
"retrieve history_user.")
195-
195+
196196
def test_middleware_anonymous_user(self):
197197
overridden_settings = {
198198
'MIDDLEWARE_CLASSES':

simple_history/tests/urls.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
from __future__ import unicode_literals
22

33
try:
4-
from django.conf.urls import patterns, include, url
4+
from django.conf.urls import include, url
55
except ImportError:
6-
from django.conf.urls.defaults import patterns, include, url
6+
from django.conf.urls.defaults import include, url
77

88
from django.contrib import admin
99
from . import other_admin

0 commit comments

Comments
 (0)