Generic object permissions checker class being the heart of
Once checked for single object, permissions are stored and we don’t hit database again if another check is called for this object. This is great for templates, views or other request based checks (assuming we don’t have hundreds of permissions on a single object as we fetch all permissions for checked object).
On the other hand, if we call
has_permfor perm1/object1, then we change permission state and call
has_permagain for same perm1/object1 on same instance of ObjectPermissionChecker we won’t see a difference as permissions are already fetched and stored within cache dictionary.
Constructor for ObjectPermissionChecker.
Parameters: user_or_group – should be an
Returns cache key for
Returns list of
codename’s of all permissions for given
Parameters: obj – Django model instance for which permission should be checked
Checks if user/group has given permission for object.
- perm – permission as string, may or may not contain app_label
prefix (if not prefixed, we grab app_label from
- obj – Django model instance for which permission should be checked
- perm – permission as string, may or may not contain app_label prefix (if not prefixed, we grab app_label from
Prefetches the permissions for objects in
objectsand puts them in the cache.
Parameters: objects – Iterable of Django model objects