Django

Code

Changeset 8474

Show
Ignore:
Timestamp:
08/22/08 23:00:15 (11 months ago)
Author:
brosner
Message:

Fixed #1390 -- Added an app index in the admin interface. Thanks juliae and ext for their work on patches.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/AUTHORS

    r8467 r8474  
    208208    Michael Josephson <http://www.sdjournal.com/> 
    209209    jpellerin@gmail.com 
     210    juliae 
    210211    junzhang.jn@gmail.com 
    211212    Antti Kaihola <http://akaihola.blogspot.com/> 
  • django/trunk/django/contrib/admin/media/css/global.css

    r8240 r8474  
    55a:hover { color: #036; } 
    66a img { border:none; } 
     7a.section:link, a.section:visited { color: white; text-decoration:none; } 
    78 
    89/* GLOBAL DEFAULTS */ 
  • django/trunk/django/contrib/admin/options.py

    r8469 r8474  
    523523            'errors': helpers.AdminErrorList(form, formsets), 
    524524            'root_path': self.admin_site.root_path, 
     525            'app_label': app_label, 
    525526        } 
    526527        context.update(extra_context or {}) 
     
    601602            'errors': helpers.AdminErrorList(form, formsets), 
    602603            'root_path': self.admin_site.root_path, 
     604            'app_label': app_label, 
    603605        } 
    604606        context.update(extra_context or {}) 
     
    632634            'has_add_permission': self.has_add_permission(request), 
    633635            'root_path': self.admin_site.root_path, 
     636            'app_label': app_label, 
    634637        } 
    635638        context.update(extra_context or {}) 
     
    686689            "opts": opts, 
    687690            "root_path": self.admin_site.root_path, 
     691            "app_label": app_label, 
    688692        } 
    689693        context.update(extra_context or {}) 
  • django/trunk/django/contrib/admin/sites.py

    r8473 r8474  
    171171            if '/' in url: 
    172172                return self.model_page(request, *url.split('/', 2)) 
     173            else: 
     174                return self.app_index(request, url) 
    173175 
    174176        raise http.Http404('The requested admin page does not exist.') 
     
    316318                        app_dict[app_label] = { 
    317319                            'name': app_label.title(), 
     320                            'app_url': app_label, 
    318321                            'has_module_perms': has_module_perms, 
    319322                            'models': [model_dict], 
     
    361364            context_instance=template.RequestContext(request) 
    362365        ) 
    363  
     366         
     367    def app_index(self, request, app_label): 
     368        user = request.user 
     369        has_module_perms = user.has_module_perms(app_label) 
     370        app_dict = {} 
     371        for model, model_admin in self._registry.items(): 
     372            if app_label == model._meta.app_label: 
     373                if has_module_perms: 
     374                    perms = { 
     375                        'add': user.has_perm("%s.%s" % (app_label, model._meta.get_add_permission())), 
     376                        'change': user.has_perm("%s.%s" % (app_label, model._meta.get_change_permission())), 
     377                        'delete': user.has_perm("%s.%s" % (app_label, model._meta.get_delete_permission())), 
     378                    } 
     379                    # Check whether user has any perm for this module. 
     380                    # If so, add the module to the model_list. 
     381                    if True in perms.values(): 
     382                        model_dict = { 
     383                            'name': capfirst(model._meta.verbose_name_plural), 
     384                            'admin_url': '%s/' % model.__name__.lower(), 
     385                            'perms': perms, 
     386                        } 
     387                    if app_dict: 
     388                        app_dict['models'].append(model_dict), 
     389                    else: 
     390                        app_dict = { 
     391                            'name': app_label.title(), 
     392                            'app_url': '', 
     393                            'has_module_perms': has_module_perms, 
     394                            'models': [model_dict], 
     395                        } 
     396                    if not app_dict: 
     397                        raise http.Http404('The requested admin page does not exist.') 
     398        # Sort the models alphabetically within each app. 
     399        app_dict['models'].sort(lambda x, y: cmp(x['name'], y['name'])) 
     400        return render_to_response('admin/app_index.html', { 
     401            'title': _('%s administration' % capfirst(app_label)), 
     402            'app_list': [app_dict] 
     403        }, context_instance=template.RequestContext(request)) 
    364404 
    365405# This global object represents the default admin site, for the common case. 
  • django/trunk/django/contrib/admin/templates/admin/change_form.html

    r8385 r8474  
    1616<div class="breadcrumbs"> 
    1717     <a href="../../../">{% trans "Home" %}</a> &rsaquo; 
     18     <a href="../../">{{ app_label|capfirst|escape }}</a> &rsaquo;  
    1819     <a href="../">{{ opts.verbose_name_plural|capfirst }}</a> &rsaquo; 
    1920     {% if add %}{% trans "Add" %} {{ opts.verbose_name }}{% else %}{{ original|truncatewords:"18" }}{% endif %} 
  • django/trunk/django/contrib/admin/templates/admin/change_list.html

    r7967 r8474  
    66{% block bodyclass %}change-list{% endblock %} 
    77 
    8 {% 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 %} 
     8{% if not is_popup %}{% block breadcrumbs %}<div class="breadcrumbs"><a href="../../">{% trans "Home" %}</a> &rsaquo; <a href="../">{{ app_label|capfirst|escape }}</a> &rsaquo; {{ cl.opts.verbose_name_plural|capfirst|escape }}</div>{% endblock %}{% endif %} 
    99 
    1010{% block coltype %}flex{% endblock %} 
  • django/trunk/django/contrib/admin/templates/admin/delete_confirmation.html

    r7967 r8474  
    55<div class="breadcrumbs"> 
    66     <a href="../../../../">{% trans "Home" %}</a> &rsaquo; 
     7     <a href="../../../">{{ app_label|capfirst|escape }}</a> &rsaquo;  
    78     <a href="../../">{{ opts.verbose_name_plural|capfirst }}</a> &rsaquo; 
    89     <a href="../">{{ object|escape|truncatewords:"18" }}</a> &rsaquo; 
  • django/trunk/django/contrib/admin/templates/admin/index.html

    r7967 r8474  
    1717        <div class="module"> 
    1818        <table summary="{% blocktrans with app.name as name %}Models available in the {{ name }} application.{% endblocktrans %}"> 
    19         <caption>{% blocktrans with app.name as name %}{{ name }}{% endblocktrans %}</caption> 
     19        <caption><a href="{{ app.app_url }}" class="section">{% blocktrans with app.name as name %}{{ name }}{% endblocktrans %}</a></caption> 
    2020        {% for model in app.models %} 
    2121            <tr>