Ticket #5447: add_delete_change_permission.diff

File add_delete_change_permission.diff, 7.3 KB (added by anonymous, 17 years ago)
  • django/newforms/fields.py

     
    643643        RegexField.__init__(self, ipv4_re,
    644644                            error_message=ugettext(u'Enter a valid IPv4 address.'),
    645645                            *args, **kwargs)
     646
  • django/newforms/widgets.py

     
    528528
    529529    def decompress(self, value):
    530530        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
    532533        return [None, None]
    533    
    534  No newline at end of file
     534
  • django/contrib/admin/options.py

     
    264264        return forms.Media(js=['%s%s' % (settings.ADMIN_MEDIA_PREFIX, url) for url in js])
    265265    media = property(_media)
    266266   
    267     def has_add_permission(self, request):
     267    def has_add_permission(self, request=None):
    268268        "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       
    269273        opts = self.opts
    270274        return request.user.has_perm(opts.app_label + '.' + opts.get_add_permission())
    271275
    272     def has_change_permission(self, request, obj):
     276    def has_change_permission(self, request=None, obj=None):
    273277        """
    274278        Returns True if the given request has permission to change the given
    275279        Django model instance.
     
    277281        If `obj` is None, this should return True if the given request has
    278282        permission to change *any* object of the given type.
    279283        """
     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
    280287        opts = self.opts
    281288        return request.user.has_perm(opts.app_label + '.' + opts.get_change_permission())
    282289
    283     def has_delete_permission(self, request, obj):
     290    def has_delete_permission(self, request=None, obj=None):
    284291        """
    285292        Returns True if the given request has permission to change the given
    286293        Django model instance.
     
    288295        If `obj` is None, this should return True if the given request has
    289296        permission to delete *any* object of the given type.
    290297        """
     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
    291301        opts = self.opts
    292302        return request.user.has_perm(opts.app_label + '.' + opts.get_delete_permission())
    293303
     
    597607            'is_popup': cl.is_popup,
    598608            'cl': cl,
    599609        })
    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()]}),
    601611        return render_to_response(['admin/%s/%s/change_list.html' % (app_label, opts.object_name.lower()),
    602612                                'admin/%s/change_list.html' % app_label,
    603613                                'admin/change_list.html'], context_instance=c)
  • django/contrib/admin/views/main.py

     
    119119    extra_context = {
    120120        'add': add,
    121121        '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()],
    124125        'has_file_field': True, # FIXME - this should check if form or formsets have a FileField,
    125126        'has_absolute_url': hasattr(model, 'get_absolute_url'),
    126127        'ordered_objects': ordered_objects,
  • django/contrib/admin/widgets.py

     
    130130        if rel_to in self.admin_site._registry: # If the related object has an admin interface:
    131131            # TODO: "id_" is hard-coded here. This should instead use the correct
    132132            # 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)
    136137        return u''.join(output)
    137138
    138139    def __deepcopy__(self, memo):
  • django/contrib/admin/sites.py

     
    262262
    263263            if has_module_perms:
    264264                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())),
    268268                }
    269 
     269               
    270270                # Check whether user has any perm for this module.
    271271                # If so, add the module to the model_list.
    272272                if True in perms.values():
Back to Top