Skip to content

Commit 17f4980

Browse files
committed
Update for compatability issues
1 parent 6d9b12e commit 17f4980

15 files changed

+120
-77
lines changed

.editorconfig

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ charset = utf-8
88
indent_style = space
99
end_of_line = lf
1010
insert_final_newline = true
11+
max_line_length = 79
1112
trim_trailing_whitespace = true
1213

1314
[*.{py,rst,ini}]

.travis.yml

+11-7
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ language: python
33
sudo: false
44

55
python:
6-
- 2.6
76
- 2.7
87
- 3.2
98
- 3.3
@@ -13,6 +12,7 @@ env:
1312
- DJANGO="Django>=1.6,<1.7"
1413
- DJANGO="Django>=1.7,<1.8"
1514
- DJANGO="Django>=1.8,<1.9"
15+
- DJANGO="Django>=1.9a,<1.10"
1616

1717
install:
1818
- pip install -U 'coverage<4' codecov $DJANGO
@@ -22,21 +22,25 @@ script: coverage run setup.py test
2222

2323
matrix:
2424
exclude:
25-
- python: 2.6
26-
env: DJANGO="Django>=1.6,<1.7"
27-
- python: 2.6
28-
env: DJANGO="Django>=1.7,<1.8"
29-
- python: 2.6
30-
env: DJANGO="Django>=1.8,<1.9"
3125
- python: 3.2
3226
env: DJANGO="Django>=1.4,<1.5"
3327
- python: 3.3
3428
env: DJANGO="Django>=1.4,<1.5"
29+
- python: 3.2
30+
env: DJANGO="Django>=1.9a,<1.10"
31+
- python: 3.3
32+
env: DJANGO="Django>=1.9a,<1.10"
3533

3634
include:
35+
- python: 2.6
36+
env: DJANGO="Django>=1.4,<1.5"
3737
- python: 3.4
3838
env: DJANGO="Django>=1.7,<1.8"
3939
- python: 3.4
4040
env: DJANGO="Django>=1.8,<1.9"
41+
- python: 3.5
42+
env: DJANGO="Django>=1.8,<1.9"
43+
- python: 3.5
44+
env: DJANGO="Django>=1.9a,<1.10"
4145

4246
after_success: codecov

docs/conf.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@
9595

9696
# The theme to use for HTML and HTML Help pages. See the documentation for
9797
# a list of builtin themes.
98-
html_theme = 'default'
98+
# html_theme = 'default'
9999

100100
# Theme options are theme-specific and customize the look and feel of a theme
101101
# further. For a list of options available for each theme, see the

docs/usage.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ settings:
4343
]
4444
4545
If you do not want to use the middleware, you can explicitly indicate
46-
the user making the change as documented in :ref:`recording_user`.
46+
the user making the change as documented in :doc:`/advanced`.
4747

4848
Models
4949
~~~~~~
@@ -121,7 +121,7 @@ An example of admin integration for the ``Poll`` and ``Choice`` models:
121121
admin.site.register(Poll, SimpleHistoryAdmin)
122122
admin.site.register(Choice, SimpleHistoryAdmin)
123123
124-
Changing a history-tracked model from the admin interface will automatically record the user who made the change (see :ref:`recording_user`).
124+
Changing a history-tracked model from the admin interface will automatically record the user who made the change (see :doc:`/advanced`).
125125

126126

127127
Querying history

runtests.py

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
#!/usr/bin/env python
2-
import sys
3-
from shutil import rmtree
2+
import logging
43
from os.path import abspath, dirname, join
4+
from shutil import rmtree
5+
import sys
6+
import warnings
57

68
import django
79
from django.conf import settings
810

9-
1011
sys.path.insert(0, abspath(dirname(__file__)))
1112

12-
1313
media_root = join(abspath(dirname(__file__)), 'test_files')
1414
rmtree(media_root, ignore_errors=True)
1515

@@ -39,6 +39,10 @@
3939
'django.contrib.auth.middleware.AuthenticationMiddleware',
4040
'django.contrib.messages.middleware.MessageMiddleware',
4141
],
42+
TEMPLATES=[{
43+
'BACKEND': 'django.template.backends.django.DjangoTemplates',
44+
'APP_DIRS': True,
45+
}],
4246
)
4347

4448
if django.VERSION >= (1, 5):
@@ -62,4 +66,5 @@ def main():
6266

6367

6468
if __name__ == "__main__":
69+
logging.basicConfig()
6570
main()

setup.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
import simple_history
33

44
tests_require = [
5-
"Django>=1.4", "webtest==2.0.6", "django-webtest==1.7", "mock==1.0.1"
6-
]
5+
'Django>=1.4', 'WebTest==2.0.18', 'django-webtest==1.7.8', 'mock==1.0.1']
76
try:
87
from unittest import skipUnless
98
except ImportError: # Python 2.6 compatibility

simple_history/admin.py

+12-10
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22

33
from django import http
44
from django.core.exceptions import PermissionDenied
5-
from django.conf.urls import patterns, url
6-
from django.contrib.admin import helpers, ModelAdmin
5+
from django.conf.urls import url
6+
from django.contrib import admin
7+
from django.contrib.admin import helpers
78
from django.contrib.contenttypes.models import ContentType
89
from django.core.urlresolvers import reverse
910
from django.shortcuts import get_object_or_404, render
@@ -27,7 +28,7 @@
2728
SIMPLE_HISTORY_EDIT = getattr(settings, 'SIMPLE_HISTORY_EDIT', False)
2829

2930

30-
class SimpleHistoryAdmin(ModelAdmin):
31+
class SimpleHistoryAdmin(admin.ModelAdmin):
3132
object_history_template = "simple_history/object_history.html"
3233
object_history_form_template = "simple_history/object_history_form.html"
3334

@@ -40,16 +41,16 @@ def get_urls(self):
4041
info = opts.app_label, opts.model_name
4142
except AttributeError: # Django < 1.7
4243
info = opts.app_label, opts.module_name
43-
history_urls = patterns(
44-
"",
44+
history_urls = [
4545
url("^([^/]+)/history/([^/]+)/$",
4646
admin_site.admin_view(self.history_form_view),
4747
name='%s_%s_simple_history' % info),
48-
)
48+
]
4949
return history_urls + urls
5050

5151
def history_view(self, request, object_id, extra_context=None):
52-
"The 'history' admin view for this model."
52+
"""The 'history' admin view for this model."""
53+
request.current_app = self.admin_site.name
5354
model = self.model
5455
opts = model._meta
5556
app_label = opts.app_label
@@ -81,7 +82,7 @@ def history_view(self, request, object_id, extra_context=None):
8182
}
8283
context.update(extra_context or {})
8384
return render(request, template_name=self.object_history_template,
84-
dictionary=context, current_app=self.admin_site.name)
85+
dictionary=context, current_app=request.current_app)
8586

8687
def response_change(self, request, obj):
8788
if '_change_history' in request.POST and SIMPLE_HISTORY_EDIT:
@@ -101,6 +102,7 @@ def response_change(self, request, obj):
101102
request, obj)
102103

103104
def history_form_view(self, request, object_id, version_id):
105+
request.current_app = self.admin_site.name
104106
original_opts = self.model._meta
105107
model = getattr(
106108
self.model,
@@ -120,7 +122,7 @@ def history_form_view(self, request, object_id, version_id):
120122
change_history = False
121123

122124
if '_change_history' in request.POST and SIMPLE_HISTORY_EDIT:
123-
obj = obj.history.get(pk=version_id)
125+
obj = obj.history.get(pk=version_id).instance
124126

125127
formsets = []
126128
form_class = self.get_form(request, obj)
@@ -186,7 +188,7 @@ def history_form_view(self, request, object_id, version_id):
186188
'root_path': getattr(self.admin_site, 'root_path', None),
187189
}
188190
return render(request, template_name=self.object_history_form_template,
189-
dictionary=context, current_app=self.admin_site.name)
191+
dictionary=context, current_app=request.current_app)
190192

191193
def save_model(self, request, obj, form, change):
192194
"""Set special model attribute to user for reference after save"""

simple_history/models.py

+17-16
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,14 @@
1616
from django.utils.timezone import now
1717
from django.utils.translation import string_concat
1818

19-
try:
20-
import importlib
21-
except ImportError:
22-
from django.utils import importlib
2319
try:
2420
from django.apps import apps
2521
except ImportError: # Django < 1.7
26-
from django.db.models.loading import get_app
27-
apps = None
28-
else:
29-
get_app = apps.get_app
22+
from django.db.models import get_app
23+
try:
24+
import importlib
25+
except ImportError: # Python < 2.7
26+
from django.utils import importlib
3027
try:
3128
from south.modelsinspector import add_introspection_rules
3229
except ImportError: # south not present
@@ -103,14 +100,14 @@ def create_history_model(self, model):
103100
# registered under different app
104101
attrs['__module__'] = self.module
105102
elif app_module != self.module:
106-
if apps is None: # Django < 1.7
107-
# has meta options with app_label
108-
app = get_app(model._meta.app_label)
109-
attrs['__module__'] = app.__name__ # full dotted name
110-
else:
103+
try:
111104
# Abuse an internal API because the app registry is loading.
112105
app = apps.app_configs[model._meta.app_label]
113-
attrs['__module__'] = app.name # full dotted name
106+
except NameError: # Django < 1.7
107+
models_module = get_app(model._meta.app_label).__name__
108+
else:
109+
models_module = app.name
110+
attrs['__module__'] = models_module
114111

115112
fields = self.copy_fields(model)
116113
attrs.update(fields)
@@ -130,7 +127,10 @@ def copy_fields(self, model):
130127
fields = {}
131128
for field in model._meta.fields:
132129
field = copy.copy(field)
133-
field.rel = copy.copy(field.rel)
130+
try:
131+
field.remote_field = copy.copy(field.remote_field)
132+
except AttributeError:
133+
field.rel = copy.copy(field.rel)
134134
if isinstance(field, OrderWrt):
135135
# OrderWrt is a proxy field, switch to a plain IntegerField
136136
field.__class__ = models.IntegerField
@@ -146,7 +146,8 @@ def copy_fields(self, model):
146146
field_arguments['db_constraint'] = False
147147
if getattr(old_field, 'to_fields', []):
148148
field_arguments['to_field'] = old_field.to_fields[0]
149-
elif django.get_version() < "1.6" and old_field.rel.field_name != 'id':
149+
elif (django.get_version() < "1.6" and
150+
old_field.rel.field_name != 'id'):
150151
field_arguments['to_field'] = old_field.rel.field_name
151152
if getattr(old_field, 'db_column', None):
152153
field_arguments['db_column'] = old_field.db_column

simple_history/templates/simple_history/object_history.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{% extends "admin/object_history.html" %}
22
{% load i18n %}
3-
{% load url from future %}
3+
{% load url from simple_history_compat %}
44
{% load admin_urls %}
55

66

simple_history/templates/simple_history/object_history_form.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{% extends "admin/change_form.html" %}
22
{% load i18n %}
3-
{% load url from future %}
3+
{% load url from simple_history_compat %}
44

55
{% block breadcrumbs %}
66
<div class="breadcrumbs">

simple_history/templatetags/__init__.py

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from django import template
2+
3+
try: # Django < 1.5
4+
from django.templatetags.future import url
5+
except ImportError:
6+
from django.template.defaulttags import url
7+
8+
register = template.Library()
9+
10+
register.tag(url)

simple_history/tests/tests/test_admin.py

+13-13
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
from datetime import datetime, timedelta
22

3-
from mock import patch, MagicMock, PropertyMock, ANY
3+
from mock import patch, ANY
44
from django_webtest import WebTest
55
from django.contrib.admin import AdminSite
6-
from django.contrib.contenttypes.models import ContentType
76
from django.contrib.messages.storage.fallback import FallbackStorage
87
from django.test.utils import override_settings
98
from django.test.client import RequestFactory
@@ -248,9 +247,8 @@ def test_deleteting_user(self):
248247
self.assertEqual(historical_poll.history_user, None)
249248

250249
def test_missing_one_to_one(self):
251-
"""
252-
A relation to a missing one-to-one model should still show history
253-
"""
250+
"""A relation to a missing one-to-one model should still show
251+
history"""
254252
self.login()
255253
manager = Employee.objects.create()
256254
employee = Employee.objects.create(manager=manager)
@@ -315,7 +313,8 @@ def test_response_change_change_history_setting_off(self):
315313
response = admin.response_change(request, poll)
316314

317315
with patch(
318-
'simple_history.admin.ModelAdmin.response_change') as m_admin:
316+
'simple_history.admin.admin.ModelAdmin.response_change'
317+
) as m_admin:
319318
m_admin.return_value = 'it was called'
320319
response = admin.response_change(request, poll)
321320

@@ -335,7 +334,8 @@ def test_response_change_no_change_history(self):
335334
admin = SimpleHistoryAdmin(Poll, admin_site)
336335

337336
with patch(
338-
'simple_history.admin.ModelAdmin.response_change') as m_admin:
337+
'simple_history.admin.admin.ModelAdmin.response_change'
338+
) as m_admin:
339339
m_admin.return_value = 'it was called'
340340
response = admin.response_change(request, poll)
341341

@@ -372,7 +372,7 @@ def test_history_form_view_without_getting_history(self):
372372
'app_label': 'tests',
373373
'original_opts': ANY,
374374
'changelist_url': '/admin/tests/poll/',
375-
'change_url': '/admin/tests/poll/1/',
375+
'change_url': ANY,
376376
'history_url': '/admin/tests/poll/1/history/',
377377
'add': False,
378378
'change': True,
@@ -416,10 +416,10 @@ def test_history_form_view_getting_history(self):
416416

417417
context = {
418418
# Verify this is set for history object not poll object
419-
'original': history,
419+
'original': history.instance,
420420
'change_history': True,
421421

422-
'title': 'Revert %s' % force_text(history),
422+
'title': 'Revert %s' % force_text(history.instance),
423423
'adminform': ANY,
424424
'object_id': poll.id,
425425
'is_popup': False,
@@ -428,8 +428,8 @@ def test_history_form_view_getting_history(self):
428428
'app_label': 'tests',
429429
'original_opts': ANY,
430430
'changelist_url': '/admin/tests/poll/',
431-
'change_url': '/admin/tests/poll/2/',
432-
'history_url': '/admin/tests/poll/2/history/',
431+
'change_url': ANY,
432+
'history_url': '/admin/tests/poll/{}/history/'.format(poll.pk),
433433
'add': False,
434434
'change': True,
435435
'has_add_permission': admin.has_add_permission(request),
@@ -484,7 +484,7 @@ def test_history_form_view_getting_history_with_setting_off(self):
484484
'app_label': 'tests',
485485
'original_opts': ANY,
486486
'changelist_url': '/admin/tests/poll/',
487-
'change_url': '/admin/tests/poll/1/',
487+
'change_url': ANY,
488488
'history_url': '/admin/tests/poll/1/history/',
489489
'add': False,
490490
'change': True,

0 commit comments

Comments
 (0)