akvo.rsr.models.user module

class akvo.rsr.models.user.CustomUserManager(*args, **kwargs)[source]

Bases: BaseUserManager

create_superuser(username, email, password, **extra_fields)[source]
create_user(username, email, password=None, **extra_fields)[source]
class akvo.rsr.models.user.User(*args, **kwargs)[source]

Bases: AbstractBaseUser, PermissionsMixin

A fully featured User model with admin-compliant permissions that uses a full-length email field as the username. Email and password are required. Other fields are optional.

exception DoesNotExist

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: MultipleObjectsReturned

REQUIRED_FIELDS = ['email']
USERNAME_FIELD = 'username'
admin_of(org)[source]

Checks if the user is an Admin of this organisation.

:param org; an Organisation instance.

admin_projects()[source]

Return all projects of orgs where user is an admin.

api_key

Accessor to the related object on the reverse side of a one-to-one relation.

In the example:

class Restaurant(Model):
    place = OneToOneField(Place, related_name='restaurant')

Place.restaurant is a ReverseOneToOneDescriptor instance.

approved_employments(group_names=None)[source]

Return approved employments.

When no group_names are provided, all the employments are returned.

group_names can be used to filter employments in specific groups.

approved_organisations(group_names=None)[source]

Return all approved organisations of the user.

approved_period_updates

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

assigned_indicators

Accessor to the related objects manager on the forward and reverse sides of a many-to-many relation.

In the example:

class Pizza(Model):
    toppings = ManyToManyField(Topping, related_name='pizzas')

Pizza.toppings and Topping.pizzas are ManyToManyDescriptor instances.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

auth_token

Accessor to the related object on the reverse side of a one-to-one relation.

In the example:

class Restaurant(Model):
    place = OneToOneField(Place, related_name='restaurant')

Place.restaurant is a ReverseOneToOneDescriptor instance.

avatar

Just like the FileDescriptor, but for ImageFields. The only difference is assigning the width/height to the width_field/height_field, if appropriate.

cacheable_url
can_create_project()[source]

Check to see if the user can create a project.

can_create_projects_in_program(program)[source]

Check to see if the user can create a project in a program.

can_edit_access(project)[source]

Check if the user can edit access to a project.

can_edit_enumerator_access(project)[source]
can_edit_project(project, use_cached_attr=False)[source]

Check if the user can edit a project.

The `use_cached_attr’ should be used when this call is being made on a list of projects, in a single request. Turning on this flag caches the list of projects on the user object, and uses that to determine if a project is editable, or not.

can_edit_settings(project)[source]

Check if the user can edit settings of a project.

can_import_results(project)[source]

Check to see if the user can import results to the specified project.

can_publish_project(project)[source]

Check if the user can publish a project.

can_view_project(project)[source]

Check if the user can view a project.

check_password(raw_password)[source]

Returns a boolean of whether the raw_password was correct. Handles hashing formats behind the scenes.

created_period_updates

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

date_joined

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

email

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

email_user(subject, message, from_email=None)[source]

Sends an email to this User.

employers

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

employments_dict(org_list)[source]

Represent User as dict with employments. The org_list is a list of approved organisations of the original user. Based on this, the original user will have the option to approve / delete the employment.

enforce_2fa

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

enumerator_projects()[source]

Return all projects where user is an enumerator.

first_name

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

first_organisation()[source]
get_absolute_url()[source]
get_admin_employment_orgs()[source]

Return all organisations of the user where they are Admins

property get_api_key
get_full_name()[source]
get_next_by_date_joined(*, field=<django.db.models.fields.DateTimeField: date_joined>, is_next=True, **kwargs)
get_non_admin_employment_orgs()[source]

Return all organisations of the user where they are not Admins

get_organisation_names()[source]
get_owned_org_users()[source]
get_permission_filter(permission, project_relation, include_user_owned=True)[source]

Convert a rules permission predicate into a queryset filter using Q objects.

project_relation is the string for constructing a field lookup to the corresponding Project of the queryset’s model.

get_previous_by_date_joined(*, field=<django.db.models.fields.DateTimeField: date_joined>, is_next=False, **kwargs)
get_short_name()[source]

Returns only the first_name, but is needed because the default admin templates use this method.

groups

Accessor to the related objects manager on the forward and reverse sides of a many-to-many relation.

In the example:

class Pizza(Model):
    toppings = ManyToManyField(Topping, related_name='pizzas')

Pizza.toppings and Topping.pizzas are ManyToManyDescriptor instances.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

has_role_in_org(org, group)[source]

Helper function to determine if a user is in a certain group at an organisation.

:param org; an Organisation instance. :param group; a Group instance.

iati_exports

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

in_group(group, organisation=None)[source]

Returns whether a user is part of a group. Optionally an organisation can be added to check if a user is part of a group for the organisation.

indicatorperioddatacomment_set

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

is_active

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

is_admin

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

is_staff

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

is_superuser

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

is_support

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

last_login

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

last_name

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

latest_update_date()[source]
logentry_set

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

me_manager_for_project(project)[source]

Checks if the user is an M&E Manager for this project

:param project; a Project instance

me_manager_of(org)[source]

Checks if the user is an M&E Manager of this organisation.

:param org; an Organisation instance

me_manager_projects()[source]

Return all projects of orgs where user is m&e manager.

my_projects(group_names=None, show_restricted=False)[source]
notes

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

objects = <akvo.rsr.models.user.CustomUserManager object>
organisations

Accessor to the related objects manager on the forward and reverse sides of a many-to-many relation.

In the example:

class Pizza(Model):
    toppings = ManyToManyField(Topping, related_name='pizzas')

Pizza.toppings and Topping.pizzas are ManyToManyDescriptor instances.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

static parse_permission_expression(permission_expression, permissions, operators, ignored=None)[source]

Convert permission expression to a queryset filter using permissions mapping

NOTE: This function does no error checking and assumes that all the expressions are valid, and all the operations in the expression are binary and correctly parenthesized. The expressions from the rules library satisfy these assumptions and can be safely used as inputs to this function.

password

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

passwordhistory_set

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

phonedevice_set

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

project_editor_me_manager_projects()[source]

Return all projects of orgs where user is project editor or m&e manager.

project_editor_of(org)[source]

Checks if the user is a Project editor of this organisation.

:param org; an Organisation instance

projectrole_set

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

projectupdate_set

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

request_tokens

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

requesttokenlog_set

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

seen_announcements

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

staticdevice_set

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

totpdevice_set

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

updates()[source]

return all updates created by the user or by organisation users if requesting user is admin

property user

Support for self as profile. Use of this is deprecated

user_management_organisations()[source]
user_manager_projects()[source]

Return all projects where user is a user manager.

user_name()[source]
user_permissions

Accessor to the related objects manager on the forward and reverse sides of a many-to-many relation.

In the example:

class Pizza(Model):
    toppings = ManyToManyField(Topping, related_name='pizzas')

Pizza.toppings and Topping.pizzas are ManyToManyDescriptor instances.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

username

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

viewable_indicator_updates(project_id)[source]
akvo.rsr.models.user.image_path(instance, file_name)[source]