Models
User
¶
Bases: AbstractBaseUser
Defines the base user class, useable in every app.
This is almost the same as the auth module AbstractUser since it inherits from it, but some fields are required, and the username is generated automatically with the name of the user (see generate_username()).
Added field: nick_name, date_of_birth Required fields: email, first_name, last_name, date_of_birth
cached_groups: list[Group]
property
¶
Get the list of groups this user is in.
The result is cached for the default duration (should be 5 minutes)
Returns: A list of all the groups this user is in.
is_in_group(*, pk=None, name=None)
¶
Check if this user is in the given group. Either a group id or a group name must be provided. If both are passed, only the id will be considered.
The group will be fetched using the given parameter. If no group is found, return False. If a group is found, check if this user is in the latter.
Returns:
Type | Description |
---|---|
bool
|
True if the user is the group, else False |
Source code in core/models.py
age()
¶
Return the age this user has the day the method is called. If the user has not filled his age, return 0.
Source code in core/models.py
get_full_name()
¶
get_short_name()
¶
get_display_name()
¶
Returns the display name of the user.
A nickname if possible, otherwise, the full name.
get_age()
¶
get_family(godfathers_depth=4, godchildren_depth=4)
¶
Get the family of the user, with the given depth.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
godfathers_depth
|
NonNegativeInt
|
The number of generations of godfathers to fetch |
4
|
godchildren_depth
|
NonNegativeInt
|
The number of generations of godchildren to fetch |
4
|
Returns:
Type | Description |
---|---|
set[through]
|
A list of family relationships in this user's family |
Source code in core/models.py
email_user(subject, message, from_email=None, **kwargs)
¶
Sends an email to this User.
generate_username()
¶
Generates a unique username based on the first and last names.
For example: Guy Carlier gives gcarlier, and gcarlier1 if the first one exists.
Returns:
Type | Description |
---|---|
str
|
The generated username. |
Source code in core/models.py
is_owner(obj)
¶
Determine if the object is owned by the user.
Source code in core/models.py
can_edit(obj)
¶
Determine if the object can be edited by the user.
Source code in core/models.py
can_view(obj)
¶
Determine if the object can be viewed by the user.
Source code in core/models.py
clubs_with_rights()
¶
The list of clubs where the user has rights
Subscription
¶
Bases: Model
compute_start(d=None, duration=1, user=None)
staticmethod
¶
Computes the start date of the subscription.
The computation is done with respect to the given date (default is today) and the start date given in settings.SITH_SEMESTER_START_AUTUMN. It takes the nearest past start date. Exemples: with SITH_SEMESTER_START_AUTUMN = (8, 15) Today -> Start date 2015-03-17 -> 2015-02-15 2015-01-11 -> 2014-08-15.
Source code in subscription/models.py
compute_end(duration, start=None, user=None)
staticmethod
¶
Compute the end date of the subscription.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
duration
|
int
|
the duration of the subscription, in semester (for example, 2 => 2 semesters => 1 year) |
required |
start
|
date | None
|
The start date of the subscription |
None
|
user
|
User | None
|
the user which is (or will be) subscribed |
None
|
Exemples
Start - Duration -> End date 2015-09-18 - 1 -> 2016-03-18 2015-09-18 - 2 -> 2016-09-18 2015-09-18 - 3 -> 2017-03-18 2015-09-18 - 4 -> 2017-09-18.
Source code in subscription/models.py
get_start_of_semester(today=None)
¶
Return the date of the start of the semester of the given date. If no date is given, return the start date of the current semester.
The current semester is computed as follows:
- If the date is between 15/08 and 31/12 => Autumn semester.
- If the date is between 01/01 and 15/02 => Autumn semester of the previous year.
- If the date is between 15/02 and 15/08 => Spring semester
Parameters:
Name | Type | Description | Default |
---|---|---|---|
today
|
Optional[date]
|
the date to use to compute the semester. If None, use today's date. |
None
|
Returns:
Type | Description |
---|---|
date
|
the date of the start of the semester |