mirror of
https://github.com/jazzband/django-authority.git
synced 2026-04-22 15:54:45 +00:00
33 lines
921 B
Text
33 lines
921 B
Text
.. _tips-tricks:
|
|
|
|
======================
|
|
Hints, tips and tricks
|
|
======================
|
|
|
|
Within a permission class, you can refer to the user and group using self::
|
|
|
|
class CampaignPermission(permissions.BasePermission):
|
|
label = 'campaign_permission'
|
|
checks = ('do_foo',)
|
|
|
|
def do_foo(self, campaign=None):
|
|
print self.user
|
|
print self.group
|
|
# ...
|
|
|
|
You can unregister permission classes and re-register them::
|
|
|
|
authority.unregister(Campaign)
|
|
authority.register(Campaign, CampaignPermission)
|
|
|
|
Within a permission class, you can refer to Django's basic permissions::
|
|
|
|
class FlagpagePermisson(permissions.BasePermission):
|
|
label = 'flatpage_permission'
|
|
checks = ('do_foo',)
|
|
|
|
def do_foo(self, campaign=None):
|
|
if foo and self.change_flatpage():
|
|
# ...
|
|
|
|
authority.register(Flatpage, FlagpagePermisson)
|