PageRenderTime 101ms CodeModel.GetById 40ms app.highlight 1ms RepoModel.GetById 59ms app.codeStats 0ms

/README.txt

http://django-granular-permissions.googlecode.com/
Plain Text | 47 lines | 33 code | 14 blank | 0 comment | 0 complexity | 416a60ca999a214a097fed141ad62b5a MD5 | raw file
 1
 2
 3Django Granular Permissions allow you to setup per-row permissions.
 4
 5This project is injecting new methods into Django's auth.User and auth.Group in a non-invasive way (doesn't require modifying Django's code).
 6
 7Simple permission checks within views and templates with templatetags.
 8
 9You just simply have to install django-granular-permissions somewhere on your PYTHONPATH and add 'django_granular_permissions' to your installed apps and invoke
10
11python manage.py syncdb
12
13Note: superusers will always have True returned on has_row_perm(), also not active users will always get False
14
15Example:
16
17# adding permission 'edit' to a user 'Bart' on an instance of a MyObject from myapp.models
18>>> from django.contrib.auth.models import User, Group
19>>> from myapp.models import MyObject
20>>> user = User.objects.get(username='Bart')
21>>> obj = MyObject()
22>>> obj.save()
23>>> user.add_row_perm(obj, 'edit')
24>>> user.has_row_perm(obj, 'edit')
25True
26>>> user.has_row_perm(obj, 'delete')
27False 
28
29# similar for groups
30>>> group = Group.objects.get(pk=1) # get first group in the db
31>>> group.add_row_perm(obj, 'read')
32
33# now we'll add the user to the group and he will inherit the 'read' permission
34>>> user.groups.add(group)
35>>> user.has_row_perm(obj, 'read')
36True
37
38# now to remove permission
39>>> user.del_row_perm(obj, 'edit')
40>>> user.has_row_perm(obj, 'edit')
41False
42
43# note that when you try to remove a permission from a user that is granted to him through group nothing changes
44>>> user.del_row_perm(obj, 'read')
45>>> user.has_row_perm(obj, 'read')
46True
47