PageRenderTime 50ms CodeModel.GetById 0ms RepoModel.GetById 0ms 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. Django Granular Permissions allow you to setup per-row permissions.
  2. This 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).
  3. Simple permission checks within views and templates with templatetags.
  4. You just simply have to install django-granular-permissions somewhere on your PYTHONPATH and add 'django_granular_permissions' to your installed apps and invoke
  5. python manage.py syncdb
  6. Note: superusers will always have True returned on has_row_perm(), also not active users will always get False
  7. Example:
  8. # adding permission 'edit' to a user 'Bart' on an instance of a MyObject from myapp.models
  9. >>> from django.contrib.auth.models import User, Group
  10. >>> from myapp.models import MyObject
  11. >>> user = User.objects.get(username='Bart')
  12. >>> obj = MyObject()
  13. >>> obj.save()
  14. >>> user.add_row_perm(obj, 'edit')
  15. >>> user.has_row_perm(obj, 'edit')
  16. True
  17. >>> user.has_row_perm(obj, 'delete')
  18. False
  19. # similar for groups
  20. >>> group = Group.objects.get(pk=1) # get first group in the db
  21. >>> group.add_row_perm(obj, 'read')
  22. # now we'll add the user to the group and he will inherit the 'read' permission
  23. >>> user.groups.add(group)
  24. >>> user.has_row_perm(obj, 'read')
  25. True
  26. # now to remove permission
  27. >>> user.del_row_perm(obj, 'edit')
  28. >>> user.has_row_perm(obj, 'edit')
  29. False
  30. # note that when you try to remove a permission from a user that is granted to him through group nothing changes
  31. >>> user.del_row_perm(obj, 'read')
  32. >>> user.has_row_perm(obj, 'read')
  33. True