Ticket #1035: add_popup.diff

File add_popup.diff, 3.2 KB (added by Esaj <jason at jasondavies.com>, 19 years ago)
  • django/contrib/admin/templatetags/admin_modify.py

     
    246246
    247247    return {
    248248        'add': context['add'],
     249        'app_permission': context['app_permission'],
    249250        'change': context['change'],
    250251        'bound_fields': bound_fields,
    251252        'class_names': " ".join(class_names),
     
    257258    return bound_manip.get_ordered_object_pk(ordered_obj)
    258259
    259260object_pk = register.simple_tag(object_pk)
     261
     262#@register.filter
     263def has_perm(perm_obj, perm):
     264    if perm_obj:
     265        return perm_obj[perm]
     266    return False
     267
     268has_perm = register.filter(has_perm)
  • django/contrib/admin/views/main.py

     
    286286        self.is_date_time = isinstance(field, meta.DateTimeField)
    287287        self.is_file_field = isinstance(field, meta.FileField)
    288288        self.needs_add_label = field.rel and isinstance(field.rel, meta.ManyToOne) or isinstance(field.rel, meta.ManyToMany) and field.rel.to.admin
     289        self.add_permission = self.needs_add_label and "can_add_%s" % (field.rel.to.verbose_name)
    289290        self.hidden = isinstance(self.field, meta.AutoField)
    290291        self.first = False
    291292
     
    375376        return ""
    376377
    377378def render_change_form(opts, manipulator, app_label, context, add=False, change=False, show_delete=False, form_url=''):
     379    app_permission = context['perms'][app_label]
    378380    extra_context = {
    379381        'add': add,
    380382        'change': change,
    381383        'bound_manipulator': AdminBoundManipulator(opts, manipulator, context['form']),
    382         'has_delete_permission': context['perms'][app_label][opts.get_delete_permission()],
     384        'has_delete_permission': app_permission[opts.get_delete_permission()],
     385        'app_permission': app_permission,
    383386        'form_url': form_url,
    384387        'app_label': app_label,
    385388    }
  • django/contrib/admin/templates/widget/foreign.html

     
    44    <a href="../../../{{ bound_field.field.rel.to.app_label }}/{{ bound_field.field.rel.to.module_name }}/" 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>
    55{% else %}
    66{% if bound_field.needs_add_label %}
     7{% if app_permission|has_perm:bound_field.add_permission %}
    78    <a href="../../../{{ bound_field.field.rel.to.app_label }}/{{ bound_field.field.rel.to.module_name }}/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>
    8 {% endif %}{% endif %}
     9{% endif %}{% endif %}{% endif %}
Back to Top