2
2
3
3
from django import http
4
4
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
7
8
from django .contrib .contenttypes .models import ContentType
8
9
from django .core .urlresolvers import reverse
9
10
from django .shortcuts import get_object_or_404 , render
27
28
SIMPLE_HISTORY_EDIT = getattr (settings , 'SIMPLE_HISTORY_EDIT' , False )
28
29
29
30
30
- class SimpleHistoryAdmin (ModelAdmin ):
31
+ class SimpleHistoryAdmin (admin . ModelAdmin ):
31
32
object_history_template = "simple_history/object_history.html"
32
33
object_history_form_template = "simple_history/object_history_form.html"
33
34
@@ -40,16 +41,16 @@ def get_urls(self):
40
41
info = opts .app_label , opts .model_name
41
42
except AttributeError : # Django < 1.7
42
43
info = opts .app_label , opts .module_name
43
- history_urls = patterns (
44
- "" ,
44
+ history_urls = [
45
45
url ("^([^/]+)/history/([^/]+)/$" ,
46
46
admin_site .admin_view (self .history_form_view ),
47
47
name = '%s_%s_simple_history' % info ),
48
- )
48
+ ]
49
49
return history_urls + urls
50
50
51
51
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
53
54
model = self .model
54
55
opts = model ._meta
55
56
app_label = opts .app_label
@@ -81,7 +82,7 @@ def history_view(self, request, object_id, extra_context=None):
81
82
}
82
83
context .update (extra_context or {})
83
84
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 )
85
86
86
87
def response_change (self , request , obj ):
87
88
if '_change_history' in request .POST and SIMPLE_HISTORY_EDIT :
@@ -101,6 +102,7 @@ def response_change(self, request, obj):
101
102
request , obj )
102
103
103
104
def history_form_view (self , request , object_id , version_id ):
105
+ request .current_app = self .admin_site .name
104
106
original_opts = self .model ._meta
105
107
model = getattr (
106
108
self .model ,
@@ -120,7 +122,7 @@ def history_form_view(self, request, object_id, version_id):
120
122
change_history = False
121
123
122
124
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
124
126
125
127
formsets = []
126
128
form_class = self .get_form (request , obj )
@@ -186,7 +188,7 @@ def history_form_view(self, request, object_id, version_id):
186
188
'root_path' : getattr (self .admin_site , 'root_path' , None ),
187
189
}
188
190
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 )
190
192
191
193
def save_model (self , request , obj , form , change ):
192
194
"""Set special model attribute to user for reference after save"""
0 commit comments