Models
Club
¶
Bases: Model
The Club class, made as a tree to allow nice tidy organization.
president()
¶
Fetch the membership of the current president of this club.
check_loop()
¶
Raise a validation error when a loop is found within the parent list.
Source code in club/models.py
is_owned_by(user)
¶
Method to see if that object can be super edited by the given user.
can_be_edited_by(user)
¶
can_be_viewed_by(user)
¶
get_membership_for(user)
¶
Return the current membership the given user.
Note
The result is cached.
Source code in club/models.py
Group
¶
Bases: Group
Wrapper around django.auth.Group
BanGroup
¶
Bases: Group
An anti-group, that removes permissions instead of giving them.
Users are linked to BanGroups through UserBan objects.
Example
UserQuerySet
¶
Bases: QuerySet
CustomUserManager
¶
Bases: from_queryset(UserQuerySet)
User
¶
Bases: AbstractUser
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
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_short_name()
¶
get_display_name()
¶
Returns the display name of the user.
A nickname if possible, otherwise, the full name.
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
AnonymousUser()
¶
Bases: AnonymousUser
is_in_group(*, pk=None, name=None)
¶
The anonymous user is only in the public group.
Source code in core/models.py
UserBan
¶
Bases: Model
A ban of a user.
A user can be banned for a specific reason, for a specific duration. The expiration date is indicative, and the ban should be removed manually.
Preferences
¶
Bases: Model
SithFile
¶
Bases: Model
clean()
¶
Cleans up the file.
Source code in core/models.py
apply_rights_recursively(*, only_folders=False)
¶
Apply the rights of this file to all children recursively.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
only_folders
|
bool
|
If True, only apply the rights to SithFiles that are folders. |
False
|
Source code in core/models.py
copy_rights()
¶
Copy, if possible, the rights of the parent folder.
move_to(parent)
¶
Move a file to a new parent.
parent
must be a SithFile with the is_folder=True
property. Otherwise, this function doesn't change
anything.
This is done only at the DB level, so that it's very fast for the user. Indeed, this function doesn't modify
SithFiles recursively, so it stays efficient even with top-level folders.
Source code in core/models.py
LockError
¶
Bases: Exception
There was a lock error on the object.
Page
¶
Bases: Model
The page class to build a Wiki
Each page may have a parent and it's URL is of the form my.site/page/
Be careful with the _full_name attribute: this field may not be valid until you call save(). It's made for fast query, but don't rely on it when playing with a Page object, use get_full_name() instead!
save(*args, **kwargs)
¶
Performs some needed actions before and after saving a page in database.
Source code in core/models.py
get_page_by_full_name(name)
staticmethod
¶
Quicker to get a page with that method rather than building the request every time.
clean()
¶
Cleans up only the name for the moment, but this can be used to make any treatment before saving the object.
Source code in core/models.py
is_locked()
¶
Is True if the page is locked, False otherwise.
This is where the timeout is handled, so a locked page for which the timeout is reach will be unlocked and this function will return False.
Source code in core/models.py
set_lock(user)
¶
Sets a lock on the current page or raise an AlreadyLocked exception.
Source code in core/models.py
set_lock_recursive(user)
¶
unset_lock_recursive()
¶
unset_lock()
¶
get_lock()
¶
Returns the page's mutex containing the time and the user in a dict.
get_full_name()
¶
Computes the real full_name of the page based on its name and its parent's name You can and must rely on this function when working on a page object that is not freshly fetched from the DB (For example when treating a Page object coming from a form).
Source code in core/models.py
PageRev
¶
Bases: Model
True content of the page.
Each page object has a revisions field that is a list of PageRev, ordered by date. my_page.revisions.last() gives the PageRev object that is the most up-to-date, and thus, is the real content of the page. The content is in PageRev.title and PageRev.content .
Notification
¶
Bases: Model
Gift
¶
Bases: Model
OperationLog
¶
Bases: Model
General purpose log object to register operations.
validate_promo(value)
¶
Source code in core/models.py
get_group(*, pk=None, name=None)
¶
Search for a group by its primary key or its name. Either one of the two must be set.
The result is cached for the default duration (should be 5 minutes).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pk
|
int | None
|
The primary key of the group |
None
|
name
|
str | None
|
The name of the group |
None
|
Returns:
Type | Description |
---|---|
Group | None
|
The group if it exists, else None |
Raises:
Type | Description |
---|---|
ValueError
|
If no group matches the criteria |