Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

More installation streamlining/automation: Added adminapplist templat…

…etag 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
  • Loading branch information...
commit cfcf3ca1e3fc116388e9f95064acc0cf2233a93f 1 parent a2a7fd0
@adrianholovaty adrianholovaty authored
View
18 django/conf/admin_templates/index.html
@@ -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 %}
View
34 django/templatetags/adminapplist.py
@@ -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)
Please sign in to comment.
Something went wrong with that request. Please try again.