mirror of https://github.com/django/django.git
More installation streamlining/automation: Added adminapplist templatetag library and changed the default admin index.html template to display all installed apps that have admins
git-svn-id: http://code.djangoproject.com/svn/django/trunk@127 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
a2a7fd0b82
commit
cfcf3ca1e3
|
@ -6,6 +6,24 @@
|
|||
{% block content %}
|
||||
<div id="content-main">
|
||||
|
||||
{% load adminapplist %}
|
||||
|
||||
{% get_admin_app_list as app_list %}
|
||||
{% for app in app_list %}
|
||||
<div class="module">
|
||||
<h2>{{ app.name }}</h2>
|
||||
<table>
|
||||
{% for model in app.models %}
|
||||
<tr>
|
||||
<th><a href="{{ model.admin_url }}">{{ model.name }}</a></th>
|
||||
<td class="x50"><a href="{{ model.admin_url }}add/" class="addlink">Add</a></td>
|
||||
<td class="x75"><a href="{{ model.admin_url }}" class="changelink">Change</a></td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
</div>
|
||||
{% endfor %}
|
||||
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
from django.core import template
|
||||
|
||||
class AdminApplistNode(template.Node):
|
||||
def __init__(self, varname):
|
||||
self.varname = varname
|
||||
|
||||
def render(self, context):
|
||||
from django.core import meta
|
||||
app_list = []
|
||||
for app in meta.get_installed_model_modules():
|
||||
app_label = app.__name__[app.__name__.rindex('.')+1:]
|
||||
model_list = [{'name': meta.capfirst(m._meta.verbose_name_plural),
|
||||
'admin_url': '%s/%s/' % (app_label, m._meta.module_name)} \
|
||||
for m in app._MODELS if m._meta.admin]
|
||||
if model_list:
|
||||
app_list.append({
|
||||
'name': app_label.title(),
|
||||
'models': model_list,
|
||||
})
|
||||
context[self.varname] = app_list
|
||||
return ''
|
||||
|
||||
def get_admin_app_list(parser, token):
|
||||
"""
|
||||
{% get_admin_app_list as app_list %}
|
||||
"""
|
||||
tokens = token.contents.split()
|
||||
if len(tokens) < 3:
|
||||
raise template.TemplateSyntaxError, "'%s' tag requires two arguments" % tokens[0]
|
||||
if tokens[1] != 'as':
|
||||
raise template.TemplateSyntaxError, "First argument to '%s' tag must be 'as'" % tokens[0]
|
||||
return AdminApplistNode(tokens[2])
|
||||
|
||||
template.register_tag('get_admin_app_list', get_admin_app_list)
|
Loading…
Reference in New Issue