UserProperties

Qualified name: intranet.apps.users.models.UserProperties

class intranet.apps.users.models.UserProperties(id, user, _address, self_show_pictures, parent_show_pictures, self_show_address, parent_show_address, self_show_telephone, parent_show_telephone, self_show_eighth, parent_show_eighth, self_show_schedule, parent_show_schedule)[source]

Bases: Model

Parameters:

Relationship fields:

Parameters:
  • user (OneToOneField to User) – User (related name: properties)

  • _address (OneToOneField to Address) – address (related name: userproperties)

  • _schedule (ManyToManyField to Section) –

    schedule (related name: _students)

    User preference permissions (privacy options) When setting permissions, use set_permission(permission, value , parent=False) The permission attribute should be the part after “self_” or “parent_

    e.g. show_pictures

    If you’re setting permission of the student, but the parent permission is false, the method will fail and return False.

    To define a new permission, just create two new BooleanFields in the same pattern as below.

Methods

attribute_is_public

Checks if attribute is visible to public (ignoring whether the user sending the HTTP request has permission to access it).

attribute_is_visible

Checks privacy options to see if an attribute is visible to the user sending the current HTTP request.

is_http_request_sender

Checks if a user the HTTP request sender (accessing own info)

set_permission

Sets permission for personal information.

Attributes

id

Type: AutoField

objects

parent_show_address

Type: BooleanField

parent_show_eighth

Type: BooleanField

parent_show_pictures

Type: BooleanField

parent_show_schedule

Type: BooleanField

parent_show_telephone

Type: BooleanField

self_show_address

Type: BooleanField

self_show_eighth

Type: BooleanField

self_show_pictures

Type: BooleanField

self_show_schedule

Type: BooleanField

self_show_telephone

Type: BooleanField

user

Type: OneToOneField to User

user_id

Internal field, use user instead.

_current_user_override() bool[source]

Return whether the currently logged in user is a teacher, and can view all of a student’s information regardless of their privacy settings.

Returns:

Whether the currently logged in user can view all of a student’s information regardless of their privacy settings.

_schedule

Type: ManyToManyField to Section

schedule (related name: _students)

User preference permissions (privacy options) When setting permissions, use set_permission(permission, value , parent=False) The permission attribute should be the part after “self_” or “parent_

e.g. show_pictures

If you’re setting permission of the student, but the parent permission is false, the method will fail and return False.

To define a new permission, just create two new BooleanFields in the same

attribute_is_public(permission: str) bool[source]

Checks if attribute is visible to public (ignoring whether the user sending the HTTP request has permission to access it).

Parameters:

permission – The name of the permission to check.

Returns:

Whether the given permission is public.

attribute_is_visible(permission: str) bool[source]

Checks privacy options to see if an attribute is visible to the user sending the current HTTP request.

Parameters:

permission – The name of the permission to check.

Returns:

Whether the user sending the current HTTP request has permission to view the given permission.

is_http_request_sender() bool[source]

Checks if a user the HTTP request sender (accessing own info)

Used primarily to load private personal information from the cache. (A student should see all info on his or her own profile regardless of how the permissions are set.)

Returns:

Whether the user is the sender of the current HTTP request.

set_permission(permission: str, value: bool, parent: bool = False, admin: bool = False) bool[source]

Sets permission for personal information.

Returns False silently if unable to set permission. Returns True if successful.

Parameters:
  • permission – The name of the permission to set.

  • value – The value to set the permission to.

  • parent – Whether to set the parent’s permission instead of the student’s permission. If parent is True and value is False, both the parent and the student’s permissions will be set to False.

  • admin – If set to True, this will allow changing the student’s permission even if the parent’s permission is set to False (normally, this causes an error).