Ticket #5500: adminindex.diff
File adminindex.diff, 4.7 KB (added by , 17 years ago) |
---|
-
django/core/management/commands/adminindex.py
1 1 from django.core.management.base import AppCommand 2 from django.utils.encoding import force_unicode3 from django.utils.text import capfirst4 2 5 MODULE_TEMPLATE = ''' {%% if perms.%(app)s.%(addperm)s or perms.%(app)s.%(changeperm)s %%}6 <tr>7 <th>{%% if perms.%(app)s.%(changeperm)s %%}<a href="%(app)s/%(mod)s/">{%% endif %%}%(name)s{%% if perms.%(app)s.%(changeperm)s %%}</a>{%% endif %%}</th>8 <td class="x50">{%% if perms.%(app)s.%(addperm)s %%}<a href="%(app)s/%(mod)s/add/" class="addlink">{%% endif %%}Add{%% if perms.%(app)s.%(addperm)s %%}</a>{%% endif %%}</td>9 <td class="x75">{%% if perms.%(app)s.%(changeperm)s %%}<a href="%(app)s/%(mod)s/" class="changelink">{%% endif %%}Change{%% if perms.%(app)s.%(changeperm)s %%}</a>{%% endif %%}</td>10 </tr>11 {%% endif %%}'''12 13 3 class Command(AppCommand): 14 4 help = 'Prints the admin-index template snippet for the given app name(s).' 15 5 16 6 def handle_app(self, app, **options): 17 from django.db.models import get_models 18 output = [] 19 app_models = get_models(app) 20 app_label = app_models[0]._meta.app_label 21 output.append('{%% if perms.%s %%}' % app_label) 22 output.append('<div class="module"><h2>%s</h2><table>' % app_label.title()) 23 for model in app_models: 24 if model._meta.admin: 25 output.append(MODULE_TEMPLATE % { 26 'app': app_label, 27 'mod': model._meta.module_name, 28 'name': force_unicode(capfirst(model._meta.verbose_name_plural)), 29 'addperm': model._meta.get_add_permission(), 30 'changeperm': model._meta.get_change_permission(), 31 }) 32 output.append('</table></div>') 33 output.append('{% endif %}') 34 return '\n'.join(output) 7 from django.contrib.admin.templatetags.admin_list import admin_index 8 return admin_index(app) -
django/contrib/admin/templatetags/admin_list.py
16 16 17 17 DOT = '.' 18 18 19 MODULE_TEMPLATE = ''' {%% if perms.%(app)s.%(addperm)s or perms.%(app)s.%(changeperm)s %%} 20 <tr> 21 <th>{%% if perms.%(app)s.%(changeperm)s %%}<a href="%(app)s/%(mod)s/">{%% endif %%}%(name)s{%% if perms.%(app)s.%(changeperm)s %%}</a>{%% endif %%}</th> 22 <td class="x50">{%% if perms.%(app)s.%(addperm)s %%}<a href="%(app)s/%(mod)s/add/" class="addlink">{%% endif %%}Add{%% if perms.%(app)s.%(addperm)s %%}</a>{%% endif %%}</td> 23 <td class="x75">{%% if perms.%(app)s.%(changeperm)s %%}<a href="%(app)s/%(mod)s/" class="changelink">{%% endif %%}Change{%% if perms.%(app)s.%(changeperm)s %%}</a>{%% endif %%}</td> 24 </tr> 25 {%% endif %%}''' 26 27 def admin_index(app): 28 from django.db.models import get_models 29 output = [] 30 app_models = get_models(app) 31 app_label = app_models[0]._meta.app_label 32 output.append('{%% if perms.%s %%}' % app_label) 33 output.append('<div class="module"><h2>%s</h2><table>' % app_label.title()) 34 for model in app_models: 35 if model._meta.admin: 36 output.append(MODULE_TEMPLATE % { 37 'app': app_label, 38 'mod': model._meta.module_name, 39 'name': force_unicode(capfirst(model._meta.verbose_name_plural)), 40 'addperm': model._meta.get_add_permission(), 41 'changeperm': model._meta.get_change_permission(), 42 }) 43 output.append('</table></div>') 44 output.append('{% endif %}') 45 return '\n'.join(output) 46 admin_index = register.simple_tag(admin_index) 47 19 48 def paginator_number(cl,i): 20 49 if i == DOT: 21 50 return u'... ' -
docs/django-admin.txt
83 83 Use admin-index template snippets if you want to customize the look and feel of 84 84 your admin's index page. See `Tutorial 2`_ for more information. 85 85 86 **New in Django development version** 87 88 You can also use a template tag to show the admin index in your own templates:: 89 90 {% load admin_list %} 91 {% admin_index %} 92 93 Just make sure ``django.contrib.admin`` is in your ``INSTALLED_APS`` setting. 94 86 95 .. _Tutorial 2: ../tutorial02/ 87 96 88 97 createcachetable <tablename>