22
33from django import http
44from 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
78from django .contrib .contenttypes .models import ContentType
89from django .core .urlresolvers import reverse
910from django .shortcuts import get_object_or_404 , render
2728SIMPLE_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"""
0 commit comments