1
0
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:
Simon Willison 2008-06-15 18:21:11 +00:00
parent faae7c0faf
commit e8cd4084b7
8 changed files with 16 additions and 14 deletions

View File

@ -479,6 +479,7 @@ class ModelAdmin(BaseModelAdmin):
'content_type_id': ContentType.objects.get_for_model(model).id,
'save_as': self.save_as,
'save_on_top': self.save_on_top,
'root_path': self.admin_site.root_path,
})
return render_to_response(self.change_form_template or [
"admin/%s/%s/change_form.html" % (app_label, opts.object_name.lower()),
@ -537,6 +538,7 @@ class ModelAdmin(BaseModelAdmin):
'show_delete': False,
'media': mark_safe(media),
'inline_admin_formsets': inline_admin_formsets,
'root_path': self.admin_site.root_path,
}
context.update(extra_context or {})
return self.render_change_form(request, model, context, add=True)
@ -613,6 +615,7 @@ class ModelAdmin(BaseModelAdmin):
'is_popup': request.REQUEST.has_key('_popup'),
'media': mark_safe(media),
'inline_admin_formsets': inline_admin_formsets,
'root_path': self.admin_site.root_path,
}
context.update(extra_context or {})
return self.render_change_form(request, model, context, change=True, obj=obj)
@ -641,8 +644,9 @@ class ModelAdmin(BaseModelAdmin):
'title': cl.title,
'is_popup': cl.is_popup,
'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 {})
return render_to_response(self.change_list_template or [
'admin/%s/%s/change_list.html' % (app_label, opts.object_name.lower()),
@ -695,6 +699,7 @@ class ModelAdmin(BaseModelAdmin):
"deleted_objects": deleted_objects,
"perms_lacking": perms_needed,
"opts": opts,
"root_path": self.admin_site.root_path,
}
context.update(extra_context or {})
return render_to_response(self.delete_confirmation_template or [
@ -720,6 +725,7 @@ class ModelAdmin(BaseModelAdmin):
'action_list': action_list,
'module_name': capfirst(opts.verbose_name_plural),
'object': obj,
'root_path': self.admin_site.root_path,
}
context.update(extra_context or {})
return render_to_response(self.object_history_template or [

View File

@ -99,6 +99,9 @@ class AdminSite(object):
`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.
# The 'logout' view doesn't require that the person is logged in.
@ -295,6 +298,7 @@ class AdminSite(object):
context = {
'title': _('Site administration'),
'app_list': app_list,
'root_path': self.root_path,
}
context.update(extra_context or {})
return render_to_response(self.index_template or 'admin/index.html', context,
@ -316,7 +320,8 @@ class AdminSite(object):
'title': _('Log in'),
'app_path': request.path,
'post_data': post_data,
'error_message': error_message
'error_message': error_message,
'root_path': self.root_path,
}
context.update(extra_context or {})
return render_to_response(self.login_template or 'admin/login.html', context,

View File

@ -5,7 +5,6 @@
{% endblock %}
{% block stylesheet %}{% admin_media_prefix %}css/forms.css{% 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 %}
<div class="breadcrumbs">
<a href="../../../../">{% trans "Home" %}</a> &rsaquo;

View File

@ -22,7 +22,7 @@
{% block branding %}{% endblock %}
</div>
{% 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 %}
{% block nav-global %}{% endblock %}
</div>

View File

@ -12,8 +12,6 @@
{% 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 %}
<div class="breadcrumbs">
<a href="../../../">{% trans "Home" %}</a> &rsaquo;

View File

@ -5,8 +5,6 @@
{% 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> &rsaquo; {{ cl.opts.verbose_name_plural|capfirst|escape }}</div>{% endblock %}{% endif %}
{% block coltype %}flex{% endblock %}

View File

@ -1,8 +1,6 @@
{% extends "admin/base_site.html" %}
{% 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 %}
<div class="breadcrumbs">
<a href="../../../../">{% trans "Home" %}</a> &rsaquo;

View File

@ -1,8 +1,6 @@
{% extends "admin/base_site.html" %}
{% 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 %}
<div class="breadcrumbs"><a href="../../../../">{% trans 'Home' %}</a> &rsaquo; <a href="../../">{{ module_name }}</a> &rsaquo; <a href="../">{{ object|truncatewords:"18" }}</a> &rsaquo; {% trans 'History' %}</div>
{% endblock %}