Django

Code

Ticket #2927: fix_admin_add_buttons.patch

File fix_admin_add_buttons.patch, 3.8 kB (added by SmileyChris, 2 years ago)

Here's the patch to make this all work.

  • django/contrib/admin/templates/widget/foreign.html

    old new  
    77        <a href="{{ bound_field.related_url }}" class="related-lookup" id="lookup_{{ bound_field.element_id }}" onclick="return showRelatedObjectLookupPopup(this);"> <img src="{% admin_media_prefix %}img/admin/selector-search.gif" width="16" height="16" alt="Lookup"></a> 
    88    {% endif %} 
    99{% else %} 
    10 {% if bound_field.needs_add_label %} 
     10{% if bound_field.needs_add_label and has_add_permission %} 
    1111    <a href="{{ bound_field.related_url }}add/" class="add-another" id="add_{{ bound_field.element_id }}" onclick="return showAddAnotherPopup(this);"> <img src="{% admin_media_prefix %}img/admin/icon_addlink.gif" width="10" height="10" alt="Add Another"/></a> 
    1212{% endif %}{% endif %} 
    1313{% if change %} 
  • django/contrib/admin/templatetags/admin_modify.py

    old new  
    4242        'show_delete_link': (not is_popup and context['has_delete_permission'] 
    4343                              and (change or context['show_delete'])), 
    4444        'show_save_as_new': not is_popup and change and opts.admin.save_as, 
    45         'show_save_and_add_another': not is_popup and (not opts.admin.save_as or context['add']), 
     45        'show_save_and_add_another': not is_popup and (not opts.admin.save_as or context['add']) 
     46                                       and context['has_add_permission'], 
    4647        'show_save_and_continue': not is_popup and context['has_change_permission'], 
    4748        'show_save': True 
    4849    } 
     
    9596    def render(self, context): 
    9697        bound_field = template.resolve_variable(self.bound_field_var, context) 
    9798 
     99        # Pass through the add permission for related fields. 
     100        opts = bound_field.field.rel and bound_field.field.rel.to._meta 
     101        if opts: 
     102            has_add_permission = context['perms'][opts.app_label][opts.get_add_permission()] 
     103 
    98104        context.push() 
    99105        context['bound_field'] = bound_field 
     106        if opts: 
     107            context['has_add_permission'] = has_add_permission 
    100108 
    101109        output = self.get_nodelist(bound_field.field.__class__).render(context) 
    102110        context.pop() 
     
    239247    return { 
    240248        'add': context['add'], 
    241249        'change': context['change'], 
     250        'perms': context['perms'], 
    242251        'bound_fields': bound_fields, 
    243252        'class_names': " ".join(class_names), 
    244253    } 
  • django/contrib/admin/views/auth.py

    old new  
    3030        'is_popup': request.REQUEST.has_key('_popup'), 
    3131        'add': True, 
    3232        'change': False, 
     33        'has_add_permission': True, 
    3334        'has_delete_permission': False, 
    3435        'has_change_permission': True, 
    3536        'has_file_field': False, 
  • django/contrib/admin/views/main.py

    old new  
    199199    extra_context = { 
    200200        'add': add, 
    201201        'change': change, 
     202        'has_add_permission': context['perms'][app_label][opts.get_add_permission()], 
    202203        'has_delete_permission': context['perms'][app_label][opts.get_delete_permission()], 
    203204        'has_change_permission': context['perms'][app_label][opts.get_change_permission()], 
    204205        'has_file_field': opts.has_field_type(models.FileField),