Ticket #13325: check_perms_related_widget.diff

File check_perms_related_widget.diff, 2.2 KB (added by anthony@…, 15 years ago)
  • django/contrib/admin/options.py

     
    109109            # rendered output. formfield can be None if it came from a
    110110            # OneToOneField with parent_link=True or a M2M intermediary.
    111111            if formfield and db_field.name not in self.raw_id_fields:
    112                 formfield.widget = widgets.RelatedFieldWidgetWrapper(formfield.widget, db_field.rel, self.admin_site)
     112                formfield.widget = widgets.RelatedFieldWidgetWrapper(formfield.widget, db_field.rel, self.admin_site, request)
    113113
    114114            return formfield
    115115
  • django/contrib/admin/widgets.py

     
    205205    This class is a wrapper to a given widget to add the add icon for the
    206206    admin interface.
    207207    """
    208     def __init__(self, widget, rel, admin_site):
     208    def __init__(self, widget, rel, admin_site, request):
    209209        self.is_hidden = widget.is_hidden
    210210        self.needs_multipart_form = widget.needs_multipart_form
    211211        self.attrs = widget.attrs
     
    214214        self.rel = rel
    215215        # so we can check if the related object is registered with this AdminSite
    216216        self.admin_site = admin_site
     217        self.request = request
    217218
    218219    def __deepcopy__(self, memo):
    219220        obj = copy.copy(self)
     
    236237            related_url = '%s%s/%s/add/' % info
    237238        self.widget.choices = self.choices
    238239        output = [self.widget.render(name, value, *args, **kwargs)]
    239         if rel_to in self.admin_site._registry: # If the related object has an admin interface:
     240        if rel_to in self.admin_site._registry and self.admin_site._registry[rel_to].has_add_permission(self.request): # If the related object has an admin interface:
    240241            # TODO: "id_" is hard-coded here. This should instead use the correct
    241242            # API to determine the ID dynamically.
    242243            output.append(u'<a href="%s" class="add-another" id="add_id_%s" onclick="return showAddAnotherPopup(this);"> ' % \
Back to Top