mirror of
https://github.com/django/django.git
synced 2025-07-04 09:49:12 +00:00
AdminSite.root() now figures out the base URL of the admin site and stashes it as self.root_path. This is made available to admin templates, avoiding the need to use relative URLs for links to higher level admin pages. One consequence of this change is that you can now reliably over-ride the userlinks block in a custom base_site.html template.
git-svn-id: http://code.djangoproject.com/svn/django/branches/newforms-admin@7638 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
faae7c0faf
commit
e8cd4084b7
@ -479,6 +479,7 @@ class ModelAdmin(BaseModelAdmin):
|
|||||||
'content_type_id': ContentType.objects.get_for_model(model).id,
|
'content_type_id': ContentType.objects.get_for_model(model).id,
|
||||||
'save_as': self.save_as,
|
'save_as': self.save_as,
|
||||||
'save_on_top': self.save_on_top,
|
'save_on_top': self.save_on_top,
|
||||||
|
'root_path': self.admin_site.root_path,
|
||||||
})
|
})
|
||||||
return render_to_response(self.change_form_template or [
|
return render_to_response(self.change_form_template or [
|
||||||
"admin/%s/%s/change_form.html" % (app_label, opts.object_name.lower()),
|
"admin/%s/%s/change_form.html" % (app_label, opts.object_name.lower()),
|
||||||
@ -537,6 +538,7 @@ class ModelAdmin(BaseModelAdmin):
|
|||||||
'show_delete': False,
|
'show_delete': False,
|
||||||
'media': mark_safe(media),
|
'media': mark_safe(media),
|
||||||
'inline_admin_formsets': inline_admin_formsets,
|
'inline_admin_formsets': inline_admin_formsets,
|
||||||
|
'root_path': self.admin_site.root_path,
|
||||||
}
|
}
|
||||||
context.update(extra_context or {})
|
context.update(extra_context or {})
|
||||||
return self.render_change_form(request, model, context, add=True)
|
return self.render_change_form(request, model, context, add=True)
|
||||||
@ -613,6 +615,7 @@ class ModelAdmin(BaseModelAdmin):
|
|||||||
'is_popup': request.REQUEST.has_key('_popup'),
|
'is_popup': request.REQUEST.has_key('_popup'),
|
||||||
'media': mark_safe(media),
|
'media': mark_safe(media),
|
||||||
'inline_admin_formsets': inline_admin_formsets,
|
'inline_admin_formsets': inline_admin_formsets,
|
||||||
|
'root_path': self.admin_site.root_path,
|
||||||
}
|
}
|
||||||
context.update(extra_context or {})
|
context.update(extra_context or {})
|
||||||
return self.render_change_form(request, model, context, change=True, obj=obj)
|
return self.render_change_form(request, model, context, change=True, obj=obj)
|
||||||
@ -641,8 +644,9 @@ class ModelAdmin(BaseModelAdmin):
|
|||||||
'title': cl.title,
|
'title': cl.title,
|
||||||
'is_popup': cl.is_popup,
|
'is_popup': cl.is_popup,
|
||||||
'cl': cl,
|
'cl': cl,
|
||||||
|
'has_add_permission': self.has_add_permission(request),
|
||||||
|
'root_path': self.admin_site.root_path,
|
||||||
}
|
}
|
||||||
context.update({'has_add_permission': self.has_add_permission(request)}),
|
|
||||||
context.update(extra_context or {})
|
context.update(extra_context or {})
|
||||||
return render_to_response(self.change_list_template or [
|
return render_to_response(self.change_list_template or [
|
||||||
'admin/%s/%s/change_list.html' % (app_label, opts.object_name.lower()),
|
'admin/%s/%s/change_list.html' % (app_label, opts.object_name.lower()),
|
||||||
@ -695,6 +699,7 @@ class ModelAdmin(BaseModelAdmin):
|
|||||||
"deleted_objects": deleted_objects,
|
"deleted_objects": deleted_objects,
|
||||||
"perms_lacking": perms_needed,
|
"perms_lacking": perms_needed,
|
||||||
"opts": opts,
|
"opts": opts,
|
||||||
|
"root_path": self.admin_site.root_path,
|
||||||
}
|
}
|
||||||
context.update(extra_context or {})
|
context.update(extra_context or {})
|
||||||
return render_to_response(self.delete_confirmation_template or [
|
return render_to_response(self.delete_confirmation_template or [
|
||||||
@ -720,6 +725,7 @@ class ModelAdmin(BaseModelAdmin):
|
|||||||
'action_list': action_list,
|
'action_list': action_list,
|
||||||
'module_name': capfirst(opts.verbose_name_plural),
|
'module_name': capfirst(opts.verbose_name_plural),
|
||||||
'object': obj,
|
'object': obj,
|
||||||
|
'root_path': self.admin_site.root_path,
|
||||||
}
|
}
|
||||||
context.update(extra_context or {})
|
context.update(extra_context or {})
|
||||||
return render_to_response(self.object_history_template or [
|
return render_to_response(self.object_history_template or [
|
||||||
|
@ -94,11 +94,14 @@ class AdminSite(object):
|
|||||||
return request.user.is_authenticated() and request.user.is_staff
|
return request.user.is_authenticated() and request.user.is_staff
|
||||||
|
|
||||||
def root(self, request, url):
|
def root(self, request, url):
|
||||||
"""
|
"""
|
||||||
Handles main URL routing for the admin app.
|
Handles main URL routing for the admin app.
|
||||||
|
|
||||||
`url` is the remainder of the URL -- e.g. 'comments/comment/'.
|
`url` is the remainder of the URL -- e.g. 'comments/comment/'.
|
||||||
"""
|
"""
|
||||||
|
# Figure out the admin base URL path and stash it for later use
|
||||||
|
self.root_path = re.sub(re.escape(url) + '$', '', request.path)
|
||||||
|
|
||||||
url = url.rstrip('/') # Trim trailing slash, if it exists.
|
url = url.rstrip('/') # Trim trailing slash, if it exists.
|
||||||
|
|
||||||
# The 'logout' view doesn't require that the person is logged in.
|
# The 'logout' view doesn't require that the person is logged in.
|
||||||
@ -295,6 +298,7 @@ class AdminSite(object):
|
|||||||
context = {
|
context = {
|
||||||
'title': _('Site administration'),
|
'title': _('Site administration'),
|
||||||
'app_list': app_list,
|
'app_list': app_list,
|
||||||
|
'root_path': self.root_path,
|
||||||
}
|
}
|
||||||
context.update(extra_context or {})
|
context.update(extra_context or {})
|
||||||
return render_to_response(self.index_template or 'admin/index.html', context,
|
return render_to_response(self.index_template or 'admin/index.html', context,
|
||||||
@ -316,7 +320,8 @@ class AdminSite(object):
|
|||||||
'title': _('Log in'),
|
'title': _('Log in'),
|
||||||
'app_path': request.path,
|
'app_path': request.path,
|
||||||
'post_data': post_data,
|
'post_data': post_data,
|
||||||
'error_message': error_message
|
'error_message': error_message,
|
||||||
|
'root_path': self.root_path,
|
||||||
}
|
}
|
||||||
context.update(extra_context or {})
|
context.update(extra_context or {})
|
||||||
return render_to_response(self.login_template or 'admin/login.html', context,
|
return render_to_response(self.login_template or 'admin/login.html', context,
|
||||||
|
@ -5,7 +5,6 @@
|
|||||||
{% endblock %}
|
{% endblock %}
|
||||||
{% block stylesheet %}{% admin_media_prefix %}css/forms.css{% endblock %}
|
{% block stylesheet %}{% admin_media_prefix %}css/forms.css{% endblock %}
|
||||||
{% block bodyclass %}{{ opts.app_label }}-{{ opts.object_name.lower }} change-form{% endblock %}
|
{% block bodyclass %}{{ opts.app_label }}-{{ opts.object_name.lower }} change-form{% endblock %}
|
||||||
{% block userlinks %}<a href="../../../../doc/">{% trans 'Documentation' %}</a> / <a href="../../../../password_change/">{% trans 'Change password' %}</a> / <a href="../../../../logout/">{% trans 'Log out' %}</a>{% endblock %}
|
|
||||||
{% block breadcrumbs %}{% if not is_popup %}
|
{% block breadcrumbs %}{% if not is_popup %}
|
||||||
<div class="breadcrumbs">
|
<div class="breadcrumbs">
|
||||||
<a href="../../../../">{% trans "Home" %}</a> ›
|
<a href="../../../../">{% trans "Home" %}</a> ›
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
{% block branding %}{% endblock %}
|
{% block branding %}{% endblock %}
|
||||||
</div>
|
</div>
|
||||||
{% if user.is_authenticated and user.is_staff %}
|
{% if user.is_authenticated and user.is_staff %}
|
||||||
<div id="user-tools">{% trans 'Welcome,' %} <strong>{% if user.first_name %}{{ user.first_name|escape }}{% else %}{{ user.username }}{% endif %}</strong>. {% block userlinks %}<a href="doc/">{% trans 'Documentation' %}</a> / <a href="password_change/">{% trans 'Change password' %}</a> / <a href="logout/">{% trans 'Log out' %}</a>{% endblock %}</div>
|
<div id="user-tools">{% trans 'Welcome,' %} <strong>{% if user.first_name %}{{ user.first_name|escape }}{% else %}{{ user.username }}{% endif %}</strong>. {% block userlinks %}<a href="{{ root_path }}doc/">{% trans 'Documentation' %}</a> / <a href="{{ root_path }}password_change/">{% trans 'Change password' %}</a> / <a href="{{ root_path }}logout/">{% trans 'Log out' %}</a>{% endblock %}</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% block nav-global %}{% endblock %}
|
{% block nav-global %}{% endblock %}
|
||||||
</div>
|
</div>
|
||||||
|
@ -12,8 +12,6 @@
|
|||||||
|
|
||||||
{% block bodyclass %}{{ opts.app_label }}-{{ opts.object_name.lower }} change-form{% endblock %}
|
{% block bodyclass %}{{ opts.app_label }}-{{ opts.object_name.lower }} change-form{% endblock %}
|
||||||
|
|
||||||
{% block userlinks %}<a href="../../../doc/">{% trans 'Documentation' %}</a> / <a href="../../../password_change/">{% trans 'Change password' %}</a> / <a href="../../../logout/">{% trans 'Log out' %}</a>{% endblock %}
|
|
||||||
|
|
||||||
{% block breadcrumbs %}{% if not is_popup %}
|
{% block breadcrumbs %}{% if not is_popup %}
|
||||||
<div class="breadcrumbs">
|
<div class="breadcrumbs">
|
||||||
<a href="../../../">{% trans "Home" %}</a> ›
|
<a href="../../../">{% trans "Home" %}</a> ›
|
||||||
|
@ -5,8 +5,6 @@
|
|||||||
|
|
||||||
{% block bodyclass %}change-list{% endblock %}
|
{% block bodyclass %}change-list{% endblock %}
|
||||||
|
|
||||||
{% block userlinks %}<a href="../../doc/">{% trans 'Documentation' %}</a> / <a href="../../password_change/">{% trans 'Change password' %}</a> / <a href="../../logout/">{% trans 'Log out' %}</a>{% endblock %}
|
|
||||||
|
|
||||||
{% if not is_popup %}{% block breadcrumbs %}<div class="breadcrumbs"><a href="../../">{% trans "Home" %}</a> › {{ cl.opts.verbose_name_plural|capfirst|escape }}</div>{% endblock %}{% endif %}
|
{% if not is_popup %}{% block breadcrumbs %}<div class="breadcrumbs"><a href="../../">{% trans "Home" %}</a> › {{ cl.opts.verbose_name_plural|capfirst|escape }}</div>{% endblock %}{% endif %}
|
||||||
|
|
||||||
{% block coltype %}flex{% endblock %}
|
{% block coltype %}flex{% endblock %}
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
{% extends "admin/base_site.html" %}
|
{% extends "admin/base_site.html" %}
|
||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
|
|
||||||
{% block userlinks %}<a href="../../../../doc/">{% trans 'Documentation' %}</a> / <a href="../../../../password_change/">{% trans 'Change password' %}</a> / <a href="../../../../logout/">{% trans 'Log out' %}</a>{% endblock %}
|
|
||||||
|
|
||||||
{% block breadcrumbs %}
|
{% block breadcrumbs %}
|
||||||
<div class="breadcrumbs">
|
<div class="breadcrumbs">
|
||||||
<a href="../../../../">{% trans "Home" %}</a> ›
|
<a href="../../../../">{% trans "Home" %}</a> ›
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
{% extends "admin/base_site.html" %}
|
{% extends "admin/base_site.html" %}
|
||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
|
|
||||||
{% block userlinks %}<a href="../../../../doc/">{% trans 'Documentation' %}</a> / <a href="../../../../password_change/">{% trans 'Change password' %}</a> / <a href="../../../../logout/">{% trans 'Log out' %}</a>{% endblock %}
|
|
||||||
|
|
||||||
{% block breadcrumbs %}
|
{% block breadcrumbs %}
|
||||||
<div class="breadcrumbs"><a href="../../../../">{% trans 'Home' %}</a> › <a href="../../">{{ module_name }}</a> › <a href="../">{{ object|truncatewords:"18" }}</a> › {% trans 'History' %}</div>
|
<div class="breadcrumbs"><a href="../../../../">{% trans 'Home' %}</a> › <a href="../../">{{ module_name }}</a> › <a href="../">{{ object|truncatewords:"18" }}</a> › {% trans 'History' %}</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user