Ticket #2927: fix_admin_add_buttons.2.patch

File fix_admin_add_buttons.2.patch, 4.0 KB (added by Chris Beaven, 18 years ago)

less brittle patch as requested

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

     
    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

     
    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        user = context.get('user', None)
     102       
     103        has_add_permission = opts and user and user.has_perm('%s.%s' % (opts.app_label, opts.get_add_permission()))
     104       
     105       
     106        #raise TypeError, '%s.%s' % (opts.app_label, opts.get_add_permission())
     107
    98108        context.push()
    99109        context['bound_field'] = bound_field
     110        context['has_add_permission'] = has_add_permission
    100111
    101112        output = self.get_nodelist(bound_field.field.__class__).render(context)
    102113        context.pop()
     
    239250    return {
    240251        'add': context['add'],
    241252        'change': context['change'],
     253        'user': context['user'],
    242254        'bound_fields': bound_fields,
    243255        'class_names': " ".join(class_names),
    244256    }
  • django/contrib/admin/views/auth.py

     
    3131        'is_popup': request.REQUEST.has_key('_popup'),
    3232        'add': True,
    3333        'change': False,
     34        'has_add_permission': True,
    3435        'has_delete_permission': False,
    3536        'has_change_permission': True,
    3637        'has_file_field': False,
  • django/contrib/admin/views/main.py

     
    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),
Back to Top