diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py index 5271e021ef..2825c99988 100644 --- a/django/contrib/admin/options.py +++ b/django/contrib/admin/options.py @@ -11,6 +11,7 @@ from django.contrib import messages from django.views.decorators.csrf import csrf_protect from django.core.exceptions import PermissionDenied, ValidationError from django.core.paginator import Paginator +from django.core.urlresolvers import reverse from django.db import models, transaction, router from django.db.models.related import RelatedObject from django.db.models.fields import BLANK_CHOICE_DASH, FieldDoesNotExist @@ -776,9 +777,12 @@ class ModelAdmin(BaseModelAdmin): # redirect to the change-list page for this object. Otherwise, # redirect to the admin index. if self.has_change_permission(request, None): - post_url = '../' + post_url = reverse('admin:%s_%s_changelist' % + (opts.app_label, opts.module_name), + current_app=self.admin_site.name) else: - post_url = '../../../' + post_url = reverse('admin:index', + current_app=self.admin_site.name) return HttpResponseRedirect(post_url) def response_change(self, request, obj): @@ -787,11 +791,14 @@ class ModelAdmin(BaseModelAdmin): """ opts = obj._meta - # Handle proxy models automatically created by .only() or .defer() + # Handle proxy models automatically created by .only() or .defer(). + # Refs #14529 verbose_name = opts.verbose_name + module_name = opts.module_name if obj._deferred: opts_ = opts.proxy_for_model._meta verbose_name = opts_.verbose_name + module_name = opts_.module_name pk_value = obj._get_pk_val() @@ -805,19 +812,28 @@ class ModelAdmin(BaseModelAdmin): elif "_saveasnew" in request.POST: msg = _('The %(name)s "%(obj)s" was added successfully. You may edit it again below.') % {'name': force_unicode(verbose_name), 'obj': obj} self.message_user(request, msg) - return HttpResponseRedirect("../%s/" % pk_value) + return HttpResponseRedirect(reverse('admin:%s_%s_change' % + (opts.app_label, module_name), + args=(pk_value,), + current_app=self.admin_site.name)) elif "_addanother" in request.POST: self.message_user(request, msg + ' ' + (_("You may add another %s below.") % force_unicode(verbose_name))) - return HttpResponseRedirect("../add/") + return HttpResponseRedirect(reverse('admin:%s_%s_add' % + (opts.app_label, module_name), + current_app=self.admin_site.name)) else: self.message_user(request, msg) # Figure out where to redirect. If the user has change permission, # redirect to the change-list page for this object. Otherwise, # redirect to the admin index. if self.has_change_permission(request, None): - return HttpResponseRedirect('../') + post_url = reverse('admin:%s_%s_changelist' % + (opts.app_label, module_name), + current_app=self.admin_site.name) else: - return HttpResponseRedirect('../../../') + post_url = reverse('admin:index', + current_app=self.admin_site.name) + return HttpResponseRedirect(post_url) def response_action(self, request, queryset): """ @@ -990,7 +1006,9 @@ class ModelAdmin(BaseModelAdmin): raise Http404(_('%(name)s object with primary key %(key)r does not exist.') % {'name': force_unicode(opts.verbose_name), 'key': escape(object_id)}) if request.method == 'POST' and "_saveasnew" in request.POST: - return self.add_view(request, form_url='../add/') + return self.add_view(request, form_url=reverse('admin:%s_%s_add' % + (opts.app_label, opts.module_name), + current_app=self.admin_site.name)) ModelForm = self.get_form(request, obj) formsets = [] @@ -1246,8 +1264,11 @@ class ModelAdmin(BaseModelAdmin): self.message_user(request, _('The %(name)s "%(obj)s" was deleted successfully.') % {'name': force_unicode(opts.verbose_name), 'obj': force_unicode(obj_display)}) if not self.has_change_permission(request, None): - return HttpResponseRedirect("../../../../") - return HttpResponseRedirect("../../") + return HttpResponseRedirect(reverse('admin:index', + current_app=self.admin_site.name)) + return HttpResponseRedirect(reverse('admin:%s_%s_changelist' % + (opts.app_label, opts.module_name), + current_app=self.admin_site.name)) object_name = force_unicode(opts.verbose_name) @@ -1292,6 +1313,7 @@ class ModelAdmin(BaseModelAdmin): 'module_name': capfirst(force_unicode(opts.verbose_name_plural)), 'object': obj, 'app_label': app_label, + 'opts': opts, } context.update(extra_context or {}) return TemplateResponse(request, self.object_history_template or [ diff --git a/django/contrib/admin/sites.py b/django/contrib/admin/sites.py index 9bb9f4ab46..3a5c12b70a 100644 --- a/django/contrib/admin/sites.py +++ b/django/contrib/admin/sites.py @@ -339,9 +339,11 @@ class AdminSite(object): # Check whether user has any perm for this module. # If so, add the module to the model_list. if True in perms.values(): + info = (app_label, model._meta.module_name) model_dict = { 'name': capfirst(model._meta.verbose_name_plural), - 'admin_url': mark_safe('%s/%s/' % (app_label, model.__name__.lower())), + 'admin_url': reverse('admin:%s_%s_changelist' % info, current_app=self.name), + 'add_url': reverse('admin:%s_%s_add' % info, current_app=self.name), 'perms': perms, } if app_label in app_dict: @@ -349,7 +351,7 @@ class AdminSite(object): else: app_dict[app_label] = { 'name': app_label.title(), - 'app_url': app_label + '/', + 'app_url': reverse('admin:app_list', kwargs={'app_label': app_label}, current_app=self.name), 'has_module_perms': has_module_perms, 'models': [model_dict], } @@ -383,9 +385,11 @@ class AdminSite(object): # Check whether user has any perm for this module. # If so, add the module to the model_list. if True in perms.values(): + info = (app_label, model._meta.module_name) model_dict = { 'name': capfirst(model._meta.verbose_name_plural), - 'admin_url': '%s/' % model.__name__.lower(), + 'admin_url': reverse('admin:%s_%s_changelist' % info, current_app=self.name), + 'add_url': reverse('admin:%s_%s_add' % info, current_app=self.name), 'perms': perms, } if app_dict: diff --git a/django/contrib/admin/templates/admin/500.html b/django/contrib/admin/templates/admin/500.html index b30e43170d..eeb9e8da79 100644 --- a/django/contrib/admin/templates/admin/500.html +++ b/django/contrib/admin/templates/admin/500.html @@ -1,7 +1,13 @@ {% extends "admin/base_site.html" %} {% load i18n %} +{% load url from future %} -{% block breadcrumbs %}
{% endblock %} +{% block breadcrumbs %} + +{% endblock %} {% block title %}{% trans 'Server error (500)' %}{% endblock %} diff --git a/django/contrib/admin/templates/admin/app_index.html b/django/contrib/admin/templates/admin/app_index.html index 120433d708..4616b16d3d 100644 --- a/django/contrib/admin/templates/admin/app_index.html +++ b/django/contrib/admin/templates/admin/app_index.html @@ -1,15 +1,17 @@ -{% extends "admin/index.html" %} -{% load i18n %} +{% extends "admin/index.html" %} +{% load i18n %} +{% load url from future %} {% if not is_popup %} - {% block breadcrumbs %} - +{% endblock %} +{% endif %} -{% endif %} - -{% block sidebar %}{% endblock %} \ No newline at end of file +{% block sidebar %}{% endblock %} diff --git a/django/contrib/admin/templates/admin/auth/user/change_password.html b/django/contrib/admin/templates/admin/auth/user/change_password.html index b18b0aabf3..f79eacd459 100644 --- a/django/contrib/admin/templates/admin/auth/user/change_password.html +++ b/django/contrib/admin/templates/admin/auth/user/change_password.html @@ -1,21 +1,24 @@ {% extends "admin/base_site.html" %} {% load i18n admin_static admin_modify %} {% load url from future %} +{% load admin_urls %} + {% block extrahead %}{{ block.super }} {% url 'admin:jsi18n' as jsi18nurl %} {% endblock %} {% block extrastyle %}{{ block.super }}{% endblock %} {% block bodyclass %}{{ opts.app_label }}-{{ opts.object_name.lower }} change-form{% endblock %} -{% block breadcrumbs %}{% if not is_popup %} - -{% endif %}{% endblock %} +{% endblock %} +{% endif %} {% block content %}{% trans "Something's wrong with your database installation. Make sure the appropriate database tables have been created, and make sure the database is readable by the appropriate user." %}
diff --git a/django/contrib/admin/templates/admin/object_history.html b/django/contrib/admin/templates/admin/object_history.html index 5ae7847cfa..ebd19609cd 100644 --- a/django/contrib/admin/templates/admin/object_history.html +++ b/django/contrib/admin/templates/admin/object_history.html @@ -1,13 +1,15 @@ {% extends "admin/base_site.html" %} {% load i18n %} +{% load url from future %} +{% load admin_urls %} {% block breadcrumbs %} {% endblock %} diff --git a/django/contrib/admin/templates/registration/logged_out.html b/django/contrib/admin/templates/registration/logged_out.html index d339ef0a49..e95d864803 100644 --- a/django/contrib/admin/templates/registration/logged_out.html +++ b/django/contrib/admin/templates/registration/logged_out.html @@ -1,12 +1,13 @@ {% extends "admin/base_site.html" %} {% load i18n %} +{% load url from future %} -{% block breadcrumbs %} {% endblock %} +{% block breadcrumbs %} {% endblock %} {% block content %}{% trans "Thanks for spending some quality time with the Web site today." %}
- + {% endblock %} diff --git a/django/contrib/admin/templates/registration/password_change_done.html b/django/contrib/admin/templates/registration/password_change_done.html index 0c0690d5e2..863fc9671d 100644 --- a/django/contrib/admin/templates/registration/password_change_done.html +++ b/django/contrib/admin/templates/registration/password_change_done.html @@ -1,8 +1,13 @@ {% extends "admin/base_site.html" %} {% load i18n %} {% load url from future %} -{% block userlinks %}{% url 'django-admindocs-docroot' as docsroot %}{% if docsroot %}{% trans 'Documentation' %} / {% endif %}{% trans 'Change password' %} / {% trans 'Log out' %}{% endblock %} -{% block breadcrumbs %} {% endblock %} +{% block userlinks %}{% url 'django-admindocs-docroot' as docsroot %}{% if docsroot %}{% trans 'Documentation' %} / {% endif %}{% trans 'Change password' %} / {% trans 'Log out' %}{% endblock %} +{% block breadcrumbs %} + +{% endblock %} {% block title %}{% trans 'Password change successful' %}{% endblock %} diff --git a/django/contrib/admin/templates/registration/password_change_form.html b/django/contrib/admin/templates/registration/password_change_form.html index f76692d185..0e4ea535af 100644 --- a/django/contrib/admin/templates/registration/password_change_form.html +++ b/django/contrib/admin/templates/registration/password_change_form.html @@ -2,8 +2,13 @@ {% load i18n static %} {% load url from future %} {% block extrastyle %}{{ block.super }}{% endblock %} -{% block userlinks %}{% url 'django-admindocs-docroot' as docsroot %}{% if docsroot %}{% trans 'Documentation' %} / {% endif %} {% trans 'Change password' %} / {% trans 'Log out' %}{% endblock %} -{% block breadcrumbs %} {% endblock %} +{% block userlinks %}{% url 'django-admindocs-docroot' as docsroot %}{% if docsroot %}{% trans 'Documentation' %} / {% endif %} {% trans 'Change password' %} / {% trans 'Log out' %}{% endblock %} +{% block breadcrumbs %} + +{% endblock %} {% block title %}{% trans 'Password change' %}{% endblock %} diff --git a/django/contrib/admin/templates/registration/password_reset_complete.html b/django/contrib/admin/templates/registration/password_reset_complete.html index fceb167a88..7c07707f09 100644 --- a/django/contrib/admin/templates/registration/password_reset_complete.html +++ b/django/contrib/admin/templates/registration/password_reset_complete.html @@ -1,7 +1,13 @@ {% extends "admin/base_site.html" %} {% load i18n %} +{% load url from future %} -{% block breadcrumbs %} {% endblock %} +{% block breadcrumbs %} + +{% endblock %} {% block title %}{% trans 'Password reset complete' %}{% endblock %} diff --git a/django/contrib/admin/templates/registration/password_reset_confirm.html b/django/contrib/admin/templates/registration/password_reset_confirm.html index df9cf1b316..d5299ebd91 100644 --- a/django/contrib/admin/templates/registration/password_reset_confirm.html +++ b/django/contrib/admin/templates/registration/password_reset_confirm.html @@ -1,7 +1,13 @@ {% extends "admin/base_site.html" %} {% load i18n %} +{% load url from future %} -{% block breadcrumbs %} {% endblock %} +{% block breadcrumbs %} + +{% endblock %} {% block title %}{% trans 'Password reset' %}{% endblock %} diff --git a/django/contrib/admin/templates/registration/password_reset_done.html b/django/contrib/admin/templates/registration/password_reset_done.html index e223bdb9de..fd73af8928 100644 --- a/django/contrib/admin/templates/registration/password_reset_done.html +++ b/django/contrib/admin/templates/registration/password_reset_done.html @@ -1,7 +1,13 @@ {% extends "admin/base_site.html" %} {% load i18n %} +{% load url from future %} -{% block breadcrumbs %} {% endblock %} +{% block breadcrumbs %} + +{% endblock %} {% block title %}{% trans 'Password reset successful' %}{% endblock %} diff --git a/django/contrib/admin/templates/registration/password_reset_form.html b/django/contrib/admin/templates/registration/password_reset_form.html index d3a128428a..2b591fe22e 100644 --- a/django/contrib/admin/templates/registration/password_reset_form.html +++ b/django/contrib/admin/templates/registration/password_reset_form.html @@ -1,7 +1,13 @@ {% extends "admin/base_site.html" %} {% load i18n %} +{% load url from future %} -{% block breadcrumbs %} {% endblock %} +{% block breadcrumbs %} + +{% endblock %} {% block title %}{% trans "Password reset" %}{% endblock %} diff --git a/django/contrib/admin/templatetags/admin_urls.py b/django/contrib/admin/templatetags/admin_urls.py new file mode 100644 index 0000000000..53dc65b567 --- /dev/null +++ b/django/contrib/admin/templatetags/admin_urls.py @@ -0,0 +1,8 @@ +from django.core.urlresolvers import reverse, NoReverseMatch +from django import template + +register = template.Library() + +@register.filter +def admin_urlname(value, arg): + return 'admin:%s_%s_%s' % (value.app_label, value.module_name, arg) diff --git a/django/contrib/admindocs/templates/admin_doc/bookmarklets.html b/django/contrib/admindocs/templates/admin_doc/bookmarklets.html index 64475299c2..baa717c4b3 100644 --- a/django/contrib/admindocs/templates/admin_doc/bookmarklets.html +++ b/django/contrib/admindocs/templates/admin_doc/bookmarklets.html @@ -1,6 +1,14 @@ {% extends "admin/base_site.html" %} +{% load i18n %} +{% load url from future %} -{% block breadcrumbs %}{% load i18n %} {% endblock %} +{% block breadcrumbs %} + +{% endblock %} {% block title %}{% trans "Documentation bookmarklets" %}{% endblock %} {% block content %} diff --git a/django/contrib/admindocs/templates/admin_doc/index.html b/django/contrib/admindocs/templates/admin_doc/index.html index a8b21c330d..652fbfd576 100644 --- a/django/contrib/admindocs/templates/admin_doc/index.html +++ b/django/contrib/admindocs/templates/admin_doc/index.html @@ -1,6 +1,13 @@ {% extends "admin/base_site.html" %} {% load i18n %} -{% block breadcrumbs %} {% endblock %} +{% load url from future %} + +{% block breadcrumbs %} + +{% endblock %} {% block title %}Documentation{% endblock %} {% block content %} diff --git a/django/contrib/admindocs/templates/admin_doc/missing_docutils.html b/django/contrib/admindocs/templates/admin_doc/missing_docutils.html index 97c9d4711c..34c18ffb7d 100644 --- a/django/contrib/admindocs/templates/admin_doc/missing_docutils.html +++ b/django/contrib/admindocs/templates/admin_doc/missing_docutils.html @@ -1,6 +1,12 @@ {% extends "admin/base_site.html" %} {% load i18n %} -{% block breadcrumbs %} {% endblock %} +{% load url from future %} + +{% block breadcrumbs %} + {% block title %}Please install docutils{% endblock %} {% block content %} diff --git a/django/contrib/admindocs/templates/admin_doc/model_detail.html b/django/contrib/admindocs/templates/admin_doc/model_detail.html index 828df18377..82cb405639 100644 --- a/django/contrib/admindocs/templates/admin_doc/model_detail.html +++ b/django/contrib/admindocs/templates/admin_doc/model_detail.html @@ -1,5 +1,7 @@ {% extends "admin/base_site.html" %} {% load i18n %} +{% load url from future %} + {% block extrahead %} {{ block.super }} {% endblock %} -{% block breadcrumbs %} {% endblock %} +{% block breadcrumbs %} + +{% endblock %} {% block title %}Model: {{ name }}{% endblock %} @@ -41,6 +50,6 @@‹ Back to Models Documentation
+‹ Back to Models Documentation
{% endblock %} diff --git a/django/contrib/admindocs/templates/admin_doc/model_index.html b/django/contrib/admindocs/templates/admin_doc/model_index.html index 47c94c0c70..4eb3cf69c9 100644 --- a/django/contrib/admindocs/templates/admin_doc/model_index.html +++ b/django/contrib/admindocs/templates/admin_doc/model_index.html @@ -1,7 +1,16 @@ {% extends "admin/base_site.html" %} {% load i18n %} +{% load url from future %} + {% block coltype %}colSM{% endblock %} -{% block breadcrumbs %} {% endblock %} + +{% block breadcrumbs %} + +{% endblock %} {% block title %}Models{% endblock %} @@ -19,7 +28,7 @@{{ model.object_name }} | +{{ model.object_name }} |
---|
{{ meta.Templates }}
{% endif %} - + {% endblock %} diff --git a/django/contrib/admindocs/templates/admin_doc/view_index.html b/django/contrib/admindocs/templates/admin_doc/view_index.html index 6b10fa65e3..e508c84e19 100644 --- a/django/contrib/admindocs/templates/admin_doc/view_index.html +++ b/django/contrib/admindocs/templates/admin_doc/view_index.html @@ -1,7 +1,15 @@ {% extends "admin/base_site.html" %} {% load i18n %} +{% load url from future %} + {% block coltype %}colSM{% endblock %} -{% block breadcrumbs %} {% endblock %} +{% block breadcrumbs %} + +{% endblock %} {% block title %}Views{% endblock %} {% block content %} @@ -29,8 +37,8 @@ {% for view in site_views.list|dictsort:"url" %} {% ifchanged %} -View function: {{ view.module }}.{{ view.name }}
+View function: {{ view.full_name }}
{{ view.title }}