Views
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
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
CanEditMixin
¶
Bases: GenericContentPermissionMixinBuilder
Ensure the user has permission to edit this view's object.
Raises:
Type | Description |
---|---|
PermissionDenied
|
if the user cannot edit this view's object. |
CanViewMixin
¶
Bases: GenericContentPermissionMixinBuilder
Ensure the user has permission to view this view's object.
Raises:
Type | Description |
---|---|
PermissionDenied
|
if the user cannot edit this view's object. |
FileView
¶
Bases: CanViewMixin
, DetailView
, FormMixin
Handle the upload of new files into a folder.
handle_clipboard(request, obj)
staticmethod
¶
Handle the clipboard in the view.
This method can fail, since it does not catch the exceptions coming from below, allowing proper handling in the calling view. Use this method like this:
FileView.handle_clipboard(request, self.object)
request
is usually the self.request obj in your view
obj
is the SithFile object you want to put in the clipboard, or
where you want to paste the clipboard
Source code in core/views/files.py
AlbumEditForm
¶
Bases: ModelForm
PictureEditForm
¶
Bases: ModelForm
PictureModerationRequestForm(*args, user, picture, **kwargs)
¶
Bases: ModelForm
Form to create a PictureModerationRequest.
The form only manages the reason field, because the author and the picture are set in the view.
Source code in sas/forms.py
SASForm
¶
Bases: Form
Album
¶
Bases: SasFile
NAME_MAX_LENGTH: int = 50
class-attribute
¶
Maximum length of an album's name.
SithFile have a maximum length of 256 characters. However, this limit is too high for albums. Names longer than 50 characters are harder to read and harder to display on the SAS page.
It is to be noted, though, that this does not add or modify any db behaviour. It's just a constant to be used in views and forms.
Picture
¶
Bases: SasFile
SASMainView
¶
Bases: FormView
PictureView
¶
Bases: CanViewMixin
, DetailView
AlbumUploadView
¶
Bases: CanViewMixin
, DetailView
, FormMixin
AlbumView
¶
Bases: CanViewMixin
, DetailView
, FormMixin
ModerationView
¶
Bases: TemplateView
PictureEditView
¶
Bases: CanEditMixin
, UpdateView
PictureAskRemovalView
¶
Bases: CanViewMixin
, DetailView
, FormView
View to allow users to ask pictures to be removed.
get_form_kwargs()
¶
Add the user and picture to the form kwargs.
Those are required to create the PictureModerationRequest, and aren't part of the form itself (picture is a path parameter, and user is the request user).
Source code in sas/views.py
get_success_url()
¶
Return the URL to the album containing the picture.
AlbumEditView
¶
Bases: CanEditMixin
, UpdateView
send_file(request, file_id, file_class=SithFile, file_attr='file')
¶
Send a protected file, if the user can see it.
In prod, the server won't handle the download itself, but set the appropriate headers in the response to make the reverse-proxy deal with it. In debug mode, the server will directly send the file.