diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py
index 8297eca..6a7e884 100644
a
|
b
|
class ModelAdmin(BaseModelAdmin):
|
235 | 235 | url(r'^add/$', |
236 | 236 | wrap(self.add_view), |
237 | 237 | name='%sadmin_%s_%s_add' % info), |
238 | | url(r'^(.+)/history/$', |
| 238 | url(r'^(?P<object_id>.+)/history/$', |
239 | 239 | wrap(self.history_view), |
240 | 240 | name='%sadmin_%s_%s_history' % info), |
241 | | url(r'^(.+)/delete/$', |
| 241 | url(r'^(?P<object_id>.+)/delete/$', |
242 | 242 | wrap(self.delete_view), |
243 | 243 | name='%sadmin_%s_%s_delete' % info), |
244 | | url(r'^(.+)/$', |
| 244 | url(r'^(?P<object_id>.+)/$', |
245 | 245 | wrap(self.change_view), |
246 | 246 | name='%sadmin_%s_%s_change' % info), |
247 | 247 | ) |
… |
… |
class ModelAdmin(BaseModelAdmin):
|
581 | 581 | 'save_as': self.save_as, |
582 | 582 | 'save_on_top': self.save_on_top, |
583 | 583 | 'root_path': self.admin_site.root_path, |
| 584 | 'admin_site': self.admin_site.name, |
584 | 585 | }) |
585 | 586 | return render_to_response(self.change_form_template or [ |
586 | 587 | "admin/%s/%s/change_form.html" % (app_label, opts.object_name.lower()), |
… |
… |
class ModelAdmin(BaseModelAdmin):
|
778 | 779 | 'errors': helpers.AdminErrorList(form, formsets), |
779 | 780 | 'root_path': self.admin_site.root_path, |
780 | 781 | 'app_label': opts.app_label, |
| 782 | 'admin_site': self.admin_site.name, |
781 | 783 | } |
782 | 784 | context.update(extra_context or {}) |
783 | 785 | return self.render_change_form(request, context, form_url=form_url, add=True) |
… |
… |
class ModelAdmin(BaseModelAdmin):
|
866 | 868 | 'inline_admin_formsets': inline_admin_formsets, |
867 | 869 | 'errors': helpers.AdminErrorList(form, formsets), |
868 | 870 | 'root_path': self.admin_site.root_path, |
| 871 | 'admin_site': self.admin_site.name, |
869 | 872 | 'app_label': opts.app_label, |
870 | 873 | } |
871 | 874 | context.update(extra_context or {}) |
… |
… |
class ModelAdmin(BaseModelAdmin):
|
971 | 974 | 'media': media, |
972 | 975 | 'has_add_permission': self.has_add_permission(request), |
973 | 976 | 'root_path': self.admin_site.root_path, |
| 977 | 'admin_site': self.admin_site.name, |
974 | 978 | 'app_label': app_label, |
975 | 979 | 'action_form': action_form, |
976 | 980 | 'actions_on_top': self.actions_on_top, |
… |
… |
class ModelAdmin(BaseModelAdmin):
|
1029 | 1033 | "perms_lacking": perms_needed, |
1030 | 1034 | "opts": opts, |
1031 | 1035 | "root_path": self.admin_site.root_path, |
| 1036 | 'admin_site': self.admin_site.name, |
1032 | 1037 | "app_label": app_label, |
1033 | 1038 | } |
1034 | 1039 | context.update(extra_context or {}) |
… |
… |
class ModelAdmin(BaseModelAdmin):
|
1056 | 1061 | 'module_name': capfirst(force_unicode(opts.verbose_name_plural)), |
1057 | 1062 | 'object': obj, |
1058 | 1063 | 'root_path': self.admin_site.root_path, |
| 1064 | 'admin_site': self.admin_site.name, |
1059 | 1065 | 'app_label': app_label, |
1060 | 1066 | } |
1061 | 1067 | context.update(extra_context or {}) |
diff --git a/django/contrib/admin/sites.py b/django/contrib/admin/sites.py
index 6e9ef11..1ad86fd 100644
a
|
b
|
from django.contrib.admin import ModelAdmin
|
4 | 4 | from django.contrib.admin import actions |
5 | 5 | from django.contrib.auth import authenticate, login |
6 | 6 | from django.db.models.base import ModelBase |
| 7 | from django.core.urlresolvers import reverse |
7 | 8 | from django.core.exceptions import ImproperlyConfigured |
8 | 9 | from django.shortcuts import render_to_response |
9 | 10 | from django.utils.functional import update_wrapper |
… |
… |
class AdminSite(object):
|
40 | 41 | |
41 | 42 | def __init__(self, name=None): |
42 | 43 | self._registry = {} # model_class class -> admin_class instance |
43 | | # TODO Root path is used to calculate urls under the old root() method |
44 | | # in order to maintain backwards compatibility we are leaving that in |
45 | | # so root_path isn't needed, not sure what to do about this. |
46 | | self.root_path = 'admin/' |
| 44 | self.root_path = None |
47 | 45 | if name is None: |
48 | 46 | name = '' |
49 | 47 | else: |
… |
… |
class AdminSite(object):
|
199 | 197 | name='%sadmin_index' % self.name), |
200 | 198 | url(r'^logout/$', |
201 | 199 | wrap(self.logout), |
202 | | name='%sadmin_logout'), |
| 200 | name='%sadmin_logout' % self.name), |
203 | 201 | url(r'^password_change/$', |
204 | 202 | wrap(self.password_change), |
205 | 203 | name='%sadmin_password_change' % self.name), |
… |
… |
class AdminSite(object):
|
233 | 231 | Handles the "change password" task -- both form display and validation. |
234 | 232 | """ |
235 | 233 | from django.contrib.auth.views import password_change |
236 | | return password_change(request, |
237 | | post_change_redirect='%spassword_change/done/' % self.root_path) |
| 234 | if self.root_path is not None: |
| 235 | url = '%spassword_change/done/' % self.root_path |
| 236 | else: |
| 237 | url = reverse('%sadmin_password_change_done' % self.name) |
| 238 | return password_change(request, post_change_redirect=url) |
238 | 239 | |
239 | 240 | def password_change_done(self, request): |
240 | 241 | """ |
… |
… |
class AdminSite(object):
|
360 | 361 | 'title': _('Site administration'), |
361 | 362 | 'app_list': app_list, |
362 | 363 | 'root_path': self.root_path, |
| 364 | 'admin_site': self.name |
363 | 365 | } |
364 | 366 | context.update(extra_context or {}) |
365 | 367 | return render_to_response(self.index_template or 'admin/index.html', context, |
… |
… |
class AdminSite(object):
|
374 | 376 | 'app_path': request.get_full_path(), |
375 | 377 | 'error_message': error_message, |
376 | 378 | 'root_path': self.root_path, |
| 379 | 'admin_site': self.name, |
377 | 380 | } |
378 | 381 | context.update(extra_context or {}) |
379 | 382 | return render_to_response(self.login_template or 'admin/login.html', context, |
… |
… |
class AdminSite(object):
|
417 | 420 | 'title': _('%s administration') % capfirst(app_label), |
418 | 421 | 'app_list': [app_dict], |
419 | 422 | 'root_path': self.root_path, |
| 423 | 'admin_site': self.name, |
420 | 424 | } |
421 | 425 | context.update(extra_context or {}) |
422 | 426 | return render_to_response(self.app_index_template or ('admin/%s/app_index.html' % app_label, |
diff --git a/django/contrib/admin/templates/admin/base.html b/django/contrib/admin/templates/admin/base.html
index 8cab439..cbbbd54 100644
a
|
b
|
|
23 | 23 | {% block branding %}{% endblock %} |
24 | 24 | </div> |
25 | 25 | {% if user.is_authenticated and user.is_staff %} |
26 | | <div id="user-tools">{% trans 'Welcome,' %} <strong>{% firstof user.first_name user.username %}</strong>. {% block userlinks %}{% url django-admindocs-docroot as docsroot %}{% if docsroot %}<a href="{{ docsroot }}">{% trans 'Documentation' %}</a> / {% endif %}<a href="{{ root_path }}password_change/">{% trans 'Change password' %}</a> / <a href="{{ root_path }}logout/">{% trans 'Log out' %}</a>{% endblock %}</div> |
| 26 | <div id="user-tools"> |
| 27 | {% trans 'Welcome,' %} |
| 28 | <strong>{% firstof user.first_name user.username %}</strong>. |
| 29 | {% block userlinks %} |
| 30 | {% url django-admindocs-docroot as docsroot %} |
| 31 | {% if docsroot %} |
| 32 | <a href="{{ docsroot }}"> |
| 33 | {% trans 'Documentation' %} |
| 34 | </a> / |
| 35 | {% endif %} |
| 36 | {% url admin_site:admin_password_change as password_change_url %} |
| 37 | {% if password_change_url %} |
| 38 | <a href="{{ password_change_url }}"> |
| 39 | {% else %} |
| 40 | <a href="{{ root_path }}password_change/"> |
| 41 | {% endif %} |
| 42 | {% trans 'Change password' %} |
| 43 | </a> / |
| 44 | {% url admin_site:admin_logout as logout_url %} |
| 45 | {% if logout_url %} |
| 46 | <a href="{{ logout_url }}"> |
| 47 | {% else %} |
| 48 | <a href="{{ root_path }}logout/"> |
| 49 | {% endif %} |
| 50 | {% trans 'Log out' %} |
| 51 | </a> |
| 52 | {% endblock %} |
| 53 | </div> |
27 | 54 | {% endif %} |
28 | 55 | {% block nav-global %}{% endblock %} |
29 | 56 | </div> |
diff --git a/django/contrib/auth/admin.py b/django/contrib/auth/admin.py
index 34691c0..48dc3e5 100644
a
|
b
|
class UserAdmin(admin.ModelAdmin):
|
92 | 92 | 'save_as': False, |
93 | 93 | 'username_help_text': self.model._meta.get_field('username').help_text, |
94 | 94 | 'root_path': self.admin_site.root_path, |
| 95 | 'admin_site': self.admin_site.name, |
95 | 96 | 'app_label': self.model._meta.app_label, |
96 | 97 | }, context_instance=template.RequestContext(request)) |
97 | 98 | |
… |
… |
class UserAdmin(admin.ModelAdmin):
|
122 | 123 | 'save_as': False, |
123 | 124 | 'show_save': True, |
124 | 125 | 'root_path': self.admin_site.root_path, |
| 126 | 'admin_site': self.admin_site.name, |
125 | 127 | }, context_instance=RequestContext(request)) |
126 | 128 | |
127 | 129 | |
diff --git a/django/contrib/comments/views/moderation.py b/django/contrib/comments/views/moderation.py
index 3334b09..880c6d7 100644
a
|
b
|
from django.core.paginator import Paginator, InvalidPage
|
7 | 7 | from django.http import Http404 |
8 | 8 | from django.contrib import comments |
9 | 9 | from django.contrib.comments import signals |
| 10 | from django.contrib import admin |
10 | 11 | |
11 | 12 | #@login_required |
12 | 13 | def flag(request, comment_id, next=None): |
… |
… |
def moderation_queue(request):
|
185 | 186 | 'previous': page - 1, |
186 | 187 | 'pages': paginator.num_pages, |
187 | 188 | 'hits' : paginator.count, |
188 | | 'page_range' : paginator.page_range |
| 189 | 'page_range' : paginator.page_range, |
| 190 | 'admin_site': admin.site.name, |
189 | 191 | }, context_instance=template.RequestContext(request)) |
190 | 192 | |
191 | 193 | moderation_queue = permission_required("comments.can_moderate")(moderation_queue) |
diff --git a/django/core/urlresolvers.py b/django/core/urlresolvers.py
index ac83756..32ba34c 100644
a
|
b
|
def resolve(path, urlconf=None):
|
257 | 257 | return get_resolver(urlconf).resolve(path) |
258 | 258 | |
259 | 259 | def reverse(viewname, urlconf=None, args=None, kwargs=None, prefix=None): |
| 260 | if isinstance(viewname, basestring): |
| 261 | viewname = ''.join(viewname.split(':')) |
260 | 262 | args = args or [] |
261 | 263 | kwargs = kwargs or {} |
262 | 264 | if prefix is None: |
diff --git a/django/template/defaulttags.py b/django/template/defaulttags.py
index a61dd8b..630078c 100644
a
|
b
|
class URLNode(Node):
|
357 | 357 | |
358 | 358 | def render(self, context): |
359 | 359 | from django.core.urlresolvers import reverse, NoReverseMatch |
| 360 | view_name_parts = [] |
| 361 | for part in self.view_name[:-1]: |
| 362 | try: |
| 363 | view_name_parts.append(Variable(part).resolve(context)) |
| 364 | except VariableDoesNotExist: |
| 365 | view_name_parts.append(part) |
| 366 | view_name_parts.append(self.view_name[-1]) |
| 367 | view_name = ':'.join(view_name_parts) |
360 | 368 | args = [arg.resolve(context) for arg in self.args] |
361 | 369 | kwargs = dict([(smart_str(k,'ascii'), v.resolve(context)) |
362 | 370 | for k, v in self.kwargs.items()]) |
… |
… |
class URLNode(Node):
|
367 | 375 | # {% url ... as var %} construct in which cause return nothing. |
368 | 376 | url = '' |
369 | 377 | try: |
370 | | url = reverse(self.view_name, args=args, kwargs=kwargs) |
| 378 | url = reverse(view_name, args=args, kwargs=kwargs) |
371 | 379 | except NoReverseMatch, e: |
372 | 380 | if settings.SETTINGS_MODULE: |
373 | 381 | project_name = settings.SETTINGS_MODULE.split('.')[0] |
374 | 382 | try: |
375 | | url = reverse(project_name + '.' + self.view_name, |
| 383 | url = reverse(project_name + '.' + view_name, |
376 | 384 | args=args, kwargs=kwargs) |
377 | 385 | except NoReverseMatch: |
378 | 386 | if self.asvar is None: |
379 | 387 | # Re-raise the original exception, not the one with |
380 | | # the path relative to the project. This makes a |
| 388 | # the path relative to the project. This makes a |
381 | 389 | # better error message. |
382 | 390 | raise e |
383 | 391 | else: |
… |
… |
def url(parser, token):
|
1105 | 1113 | raise TemplateSyntaxError("'%s' takes at least one argument" |
1106 | 1114 | " (path to a view)" % bits[0]) |
1107 | 1115 | viewname = bits[1] |
| 1116 | if ':' in viewname: |
| 1117 | viewname = viewname.split(':') |
| 1118 | else: |
| 1119 | viewname = [viewname] |
1108 | 1120 | args = [] |
1109 | 1121 | kwargs = {} |
1110 | 1122 | asvar = None |
diff --git a/tests/regressiontests/admin_views/tests.py b/tests/regressiontests/admin_views/tests.py
index 8e7010b..283a41b 100644
a
|
b
|
class AdminViewBasicTest(TestCase):
|
203 | 203 | response = self.client.get('/test_admin/%s/admin_views/thing/' % self.urlbit, {'color__id__exact': 'StringNotInteger!'}) |
204 | 204 | self.assertRedirects(response, '/test_admin/%s/admin_views/thing/?e=1' % self.urlbit) |
205 | 205 | |
| 206 | def testLogoutAndPasswordChangeURLs(self): |
| 207 | response = self.client.get('/test_admin/%s/admin_views/article/' % self.urlbit) |
| 208 | self.failIf('<a href="/test_admin/%s/logout/">' % self.urlbit not in response.content) |
| 209 | self.failIf('<a href="/test_admin/%s/password_change/">' % self.urlbit not in response.content) |
| 210 | |
206 | 211 | def testNamedGroupFieldChoicesChangeList(self): |
207 | 212 | """ |
208 | 213 | Ensures the admin changelist shows correct values in the relevant column |
diff --git a/tests/urls.py b/tests/urls.py
index 6704829..31faea5 100644
a
|
b
|
urlpatterns = patterns('',
|
21 | 21 | # test urlconf for middleware tests |
22 | 22 | (r'^middleware/', include('regressiontests.middleware.urls')), |
23 | 23 | |
| 24 | # admin widget tests |
| 25 | (r'widget_admin/', include('regressiontests.admin_widgets.urls')), |
| 26 | |
24 | 27 | # admin view tests |
25 | 28 | (r'^test_admin/', include('regressiontests.admin_views.urls')), |
26 | 29 | (r'^generic_inline_admin/', include('regressiontests.generic_inline_admin.urls')), |
27 | 30 | |
28 | | # admin widget tests |
29 | | (r'widget_admin/', include('regressiontests.admin_widgets.urls')), |
30 | 31 | |
31 | 32 | (r'^utils/', include('regressiontests.utils.urls')), |
32 | 33 | |