Ticket #5447: add_delete_change_permission.diff
File add_delete_change_permission.diff, 7.3 KB (added by , 17 years ago) |
---|
-
django/newforms/fields.py
643 643 RegexField.__init__(self, ipv4_re, 644 644 error_message=ugettext(u'Enter a valid IPv4 address.'), 645 645 *args, **kwargs) 646 -
django/newforms/widgets.py
528 528 529 529 def decompress(self, value): 530 530 if value: 531 return [value.date(), value.time()] 531 t=value.time() 532 return [value.date(), '%s:%s:%s'%(t.hour,t.minute,t.second)] # format so we make sure we don't get microseconds 532 533 return [None, None] 533 534 No newline at end of file 534 -
django/contrib/admin/options.py
264 264 return forms.Media(js=['%s%s' % (settings.ADMIN_MEDIA_PREFIX, url) for url in js]) 265 265 media = property(_media) 266 266 267 def has_add_permission(self, request ):267 def has_add_permission(self, request=None): 268 268 "Returns True if the given request has permission to add an object." 269 270 if not request: return True # we are asking to the ModelAdmin if add is supported (model-wide) 271 # user permission check is made with request!=None 272 269 273 opts = self.opts 270 274 return request.user.has_perm(opts.app_label + '.' + opts.get_add_permission()) 271 275 272 def has_change_permission(self, request , obj):276 def has_change_permission(self, request=None, obj=None): 273 277 """ 274 278 Returns True if the given request has permission to change the given 275 279 Django model instance. … … 277 281 If `obj` is None, this should return True if the given request has 278 282 permission to change *any* object of the given type. 279 283 """ 284 if not request and not obj: return True # we are asking to the ModelAdmin if change is supported (model-wide). 285 # user permission check is made with request != None and obj !=None 286 280 287 opts = self.opts 281 288 return request.user.has_perm(opts.app_label + '.' + opts.get_change_permission()) 282 289 283 def has_delete_permission(self, request , obj):290 def has_delete_permission(self, request=None, obj=None): 284 291 """ 285 292 Returns True if the given request has permission to change the given 286 293 Django model instance. … … 288 295 If `obj` is None, this should return True if the given request has 289 296 permission to delete *any* object of the given type. 290 297 """ 298 if not request and not obj: return True # we are asking to the ModelAdmin if delete is supported (model-wide). 299 # user permission check is made with request !=None and obj !=None 300 291 301 opts = self.opts 292 302 return request.user.has_perm(opts.app_label + '.' + opts.get_delete_permission()) 293 303 … … 597 607 'is_popup': cl.is_popup, 598 608 'cl': cl, 599 609 }) 600 c.update({'has_add_permission': c['perms'][app_label][opts.get_add_permission()]}),610 c.update({'has_add_permission': self.admin_site._registry[self.model].has_add_permission() and c['perms'][app_label][opts.get_add_permission()]}), 601 611 return render_to_response(['admin/%s/%s/change_list.html' % (app_label, opts.object_name.lower()), 602 612 'admin/%s/change_list.html' % app_label, 603 613 'admin/change_list.html'], context_instance=c) -
django/contrib/admin/views/main.py
119 119 extra_context = { 120 120 'add': add, 121 121 'change': change, 122 'has_delete_permission': context['perms'][app_label][opts.get_delete_permission()], 123 'has_change_permission': context['perms'][app_label][opts.get_change_permission()], 122 'has_add_permission': model_admin.has_add_permission() and context['perms'][app_label][opts.get_add_permission()], 123 'has_delete_permission': model_admin.has_delete_permission() and context['perms'][app_label][opts.get_delete_permission()], 124 'has_change_permission': model_admin.has_change_permission() and context['perms'][app_label][opts.get_change_permission()], 124 125 'has_file_field': True, # FIXME - this should check if form or formsets have a FileField, 125 126 'has_absolute_url': hasattr(model, 'get_absolute_url'), 126 127 'ordered_objects': ordered_objects, -
django/contrib/admin/widgets.py
130 130 if rel_to in self.admin_site._registry: # If the related object has an admin interface: 131 131 # TODO: "id_" is hard-coded here. This should instead use the correct 132 132 # API to determine the ID dynamically. 133 output.append(u'<a href="%sadd/" class="add-another" id="add_id_%s" onclick="return showAddAnotherPopup(this);"> ' % \ 134 (related_url, name)) 135 output.append(u'<img src="%simg/admin/icon_addlink.gif" width="10" height="10" alt="Add Another"/></a>' % settings.ADMIN_MEDIA_PREFIX) 133 if self.admin_site._registry[rel_to].has_add_permission(): 134 output.append(u'<a href="%sadd/" class="add-another" id="add_id_%s" onclick="return showAddAnotherPopup(this);"> ' % \ 135 (related_url, name)) 136 output.append(u'<img src="%simg/admin/icon_addlink.gif" width="10" height="10" alt="Add Another"/></a>' % settings.ADMIN_MEDIA_PREFIX) 136 137 return u''.join(output) 137 138 138 139 def __deepcopy__(self, memo): -
django/contrib/admin/sites.py
262 262 263 263 if has_module_perms: 264 264 perms = { 265 'add': user.has_perm("%s.%s" % (app_label, model._meta.get_add_permission())),266 'change': user.has_perm("%s.%s" % (app_label, model._meta.get_change_permission())),267 'delete': user.has_perm("%s.%s" % (app_label, model._meta.get_delete_permission())),265 'add': model_admin.has_add_permission() and user.has_perm("%s.%s" % (app_label, model._meta.get_add_permission())), 266 'change': model_admin.has_change_permission() and user.has_perm("%s.%s" % (app_label, model._meta.get_change_permission())), 267 'delete': model_admin.has_delete_permission() and user.has_perm("%s.%s" % (app_label, model._meta.get_delete_permission())), 268 268 } 269 269 270 270 # Check whether user has any perm for this module. 271 271 # If so, add the module to the model_list. 272 272 if True in perms.values():