oscarmlage / django-cruds-adminlte

django-cruds is simple drop-in django app that creates CRUD for faster prototyping
BSD 3-Clause "New" or "Revised" License
424 stars 82 forks source link

customs perm functions :) #64

Closed luisza closed 6 years ago

luisza commented 6 years ago

Hi, based in this #62 issue I create a functionality that check if perm is a function and if it's call the function, so now it's possible to have a custom permission mechanism.

See http://django-cruds-adminlte.readthedocs.io/en/latest/usage.html#permissions , now only text permission are sopported and always call user.has_perm(xxx), but with this pull request it's possible to do:

def mypermsystem(user, view):
     # view is one of this 'list', 'add', 'update', 'detail'
     return True or False

class Myclass(CRUDView):
    model = Customer
    perms = { 'create': ['applabel.mycustom_perm'],
              'list': [mypermsystem],
              'delete': [],
              'update': [],
              'detail': []
            }