Ticket #13325: check_perms_related_widget.diff
File check_perms_related_widget.diff, 2.2 KB (added by , 15 years ago) |
---|
-
django/contrib/admin/options.py
109 109 # rendered output. formfield can be None if it came from a 110 110 # OneToOneField with parent_link=True or a M2M intermediary. 111 111 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) 113 113 114 114 return formfield 115 115 -
django/contrib/admin/widgets.py
205 205 This class is a wrapper to a given widget to add the add icon for the 206 206 admin interface. 207 207 """ 208 def __init__(self, widget, rel, admin_site ):208 def __init__(self, widget, rel, admin_site, request): 209 209 self.is_hidden = widget.is_hidden 210 210 self.needs_multipart_form = widget.needs_multipart_form 211 211 self.attrs = widget.attrs … … 214 214 self.rel = rel 215 215 # so we can check if the related object is registered with this AdminSite 216 216 self.admin_site = admin_site 217 self.request = request 217 218 218 219 def __deepcopy__(self, memo): 219 220 obj = copy.copy(self) … … 236 237 related_url = '%s%s/%s/add/' % info 237 238 self.widget.choices = self.choices 238 239 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: 240 241 # TODO: "id_" is hard-coded here. This should instead use the correct 241 242 # API to determine the ID dynamically. 242 243 output.append(u'<a href="%s" class="add-another" id="add_id_%s" onclick="return showAddAnotherPopup(this);"> ' % \