Utilities — django-guardian v1.0.0.beta1 documentation

### Navigation

- index
- modules |
- next |
- previous |
- django-guardian v1.0.0.beta1 documentation »
- API Reference »

# Utilities

django-guardian helper functions.

## get_anonymous_user

`guardian.utils.` `get_anonymous_user`()

  Returns `User` instance (not `AnonymousUser`) depending on `ANONYMOUS_USER_ID` configuration.

## get_identity

`guardian.utils.` `get_identity`(identity)

  Returns (user_obj, None) or (None, group_obj) tuple depending on what is given. Also accepts AnonymousUser instance but would return `User` instead - it is convenient and needed for authorization backend to support anonymous users.

  Parameters: | identity – either `User` or `Group` instance
  Raises NotUserNorGroup:
  | if cannot return proper identity instance

  Examples:

      >>> user = User.objects.create(username='joe')
      >>> get_identity(user)
      (<User: joe>, None)

      >>> group = Group.objects.create(name='users')
      >>> get_identity(group)
      (None, <Group: users>)

      >>> anon = AnonymousUser()
      >>> get_identity(anon)
      (<User: AnonymousUser>, None)

      >>> get_identity("not instance")
      ...
      NotUserNorGroup: User/AnonymousUser or Group instance is required (got )

## clean_orphan_obj_perms

`guardian.utils.` `clean_orphan_obj_perms`()

  Seeks and removes all object permissions entries pointing at non-existing targets.

  Returns number of removed objects.

### Navigation

- index
- modules |
- next |
- previous |
- django-guardian v1.0.0.beta1 documentation »
- API Reference »