Ticket #19002: sites.diff
File sites.diff, 6.4 KB (added by , 12 years ago) |
---|
-
sites.py
old new 10 10 from django.core.urlresolvers import reverse, NoReverseMatch 11 11 from django.template.response import TemplateResponse 12 12 from django.utils.safestring import mark_safe 13 from django.utils import six14 13 from django.utils.text import capfirst 15 14 from django.utils.translation import ugettext as _ 16 15 from django.views.decorators.cache import never_cache … … 134 133 """ 135 134 Get all the enabled actions as an iterable of (name, func). 136 135 """ 137 return s ix.iteritems(self._actions)136 return self._actions.iteritems() 138 137 139 138 def has_permission(self, request): 140 139 """ … … 189 188 """ 190 189 def inner(request, *args, **kwargs): 191 190 if not self.has_permission(request): 192 if request.path == reverse(' admin:logout',191 if request.path == reverse('%s:logout' % self.name, 193 192 current_app=self.name): 194 index_path = reverse(' admin:index', current_app=self.name)193 index_path = reverse('%s:index' % self.name, current_app=self.name) 195 194 return HttpResponseRedirect(index_path) 196 195 return self.login(request) 197 196 return view(request, *args, **kwargs) … … 232 231 wrap(self.i18n_javascript, cacheable=True), 233 232 name='jsi18n'), 234 233 url(r'^r/(?P<content_type_id>\d+)/(?P<object_id>.+)/$', 235 wrap(contenttype_views.shortcut), 236 name='view_on_site'), 234 wrap(contenttype_views.shortcut)), 237 235 url(r'^(?P<app_label>\w+)/$', 238 236 wrap(self.app_index), 239 237 name='app_list') 240 238 ) 241 239 242 240 # Add in each model's views. 243 for model, model_admin in s ix.iteritems(self._registry):241 for model, model_admin in self._registry.iteritems(): 244 242 urlpatterns += patterns('', 245 243 url(r'^%s/%s/' % (model._meta.app_label, model._meta.module_name), 246 244 include(model_admin.urls)) … … 251 249 def urls(self): 252 250 return self.get_urls(), self.app_name, self.name 253 251 254 def password_change(self, request ):252 def password_change(self, request, extra_context = None): 255 253 """ 256 254 Handles the "change password" task -- both form display and validation. 257 255 """ 258 256 from django.contrib.auth.views import password_change 259 url = reverse(' admin:password_change_done', current_app=self.name)257 url = reverse('%s:password_change_done' % self.name, current_app=self.name) 260 258 defaults = { 261 'current_app': self.name, 259 'current_app': self.name, 'extra_context': extra_context or {}, 262 260 'post_change_redirect': url 263 261 } 264 262 if self.password_change_template is not None: … … 345 343 # Check whether user has any perm for this module. 346 344 # If so, add the module to the model_list. 347 345 if True in perms.values(): 348 info = ( app_label, model._meta.module_name)346 info = (self.name, app_label, model._meta.module_name) 349 347 model_dict = { 350 348 'name': capfirst(model._meta.verbose_name_plural), 351 349 'perms': perms, 352 350 } 353 351 if perms.get('change', False): 354 352 try: 355 model_dict['admin_url'] = reverse(' admin:%s_%s_changelist' % info, current_app=self.name)353 model_dict['admin_url'] = reverse('%s:%s_%s_changelist' % info, current_app=self.name) 356 354 except NoReverseMatch: 357 355 pass 358 356 if perms.get('add', False): 359 357 try: 360 model_dict['add_url'] = reverse(' admin:%s_%s_add' % info, current_app=self.name)358 model_dict['add_url'] = reverse('%s:%s_%s_add' % info, current_app=self.name) 361 359 except NoReverseMatch: 362 360 pass 363 361 if app_label in app_dict: … … 365 363 else: 366 364 app_dict[app_label] = { 367 365 'name': app_label.title(), 368 'app_url': reverse(' admin:app_list', kwargs={'app_label': app_label}, current_app=self.name),366 'app_url': reverse('%s:app_list' % self.name, kwargs={'app_label': app_label}, current_app=self.name), 369 367 'has_module_perms': has_module_perms, 370 368 'models': [model_dict], 371 369 } 372 370 373 371 # Sort the apps alphabetically. 374 app_list = list(six.itervalues(app_dict))372 app_list = app_dict.values() 375 373 app_list.sort(key=lambda x: x['name']) 376 374 377 375 # Sort the models alphabetically within each app. … … 399 397 # Check whether user has any perm for this module. 400 398 # If so, add the module to the model_list. 401 399 if True in perms.values(): 402 info = ( app_label, model._meta.module_name)400 info = (self.name, app_label, model._meta.module_name) 403 401 model_dict = { 404 402 'name': capfirst(model._meta.verbose_name_plural), 405 403 'perms': perms, 406 404 } 407 405 if perms.get('change', False): 408 406 try: 409 model_dict['admin_url'] = reverse(' admin:%s_%s_changelist' % info, current_app=self.name)407 model_dict['admin_url'] = reverse('%s:%s_%s_changelist' % info, current_app=self.name) 410 408 except NoReverseMatch: 411 409 pass 412 410 if perms.get('add', False): 413 411 try: 414 model_dict['add_url'] = reverse(' admin:%s_%s_add' % info, current_app=self.name)412 model_dict['add_url'] = reverse('%s:%s_%s_add' % info, current_app=self.name) 415 413 except NoReverseMatch: 416 414 pass 417 415 if app_dict: