Views
PermissionOrAuthorRequiredMixin
¶
Bases: PermissionRequiredMixin
Require that the user has the required perm or is the object author.
This mixin can be used in combination with DetailView
,
or another base class that implements the get_object
method.
Example
In the following code, a user will be able
to edit news if he has the com.change_news
permission
or if he tries to edit his own news :
class NewsEditView(PermissionOrAuthorRequiredMixin, DetailView):
model = News
author_field = "author"
permission_required = "com.change_news"
This is more or less equivalent to :
class NewsEditView(PermissionOrAuthorRequiredMixin, DetailView):
model = News
def dispatch(self, request, *args, **kwargs):
self.object = self.get_object()
if not (
user.has_perm("com.change_news")
or self.object.author == request.user
):
raise PermissionDenied
return super().dispatch(request, *args, **kwargs)
Notification
¶
Bases: Model
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
DetailFormView
¶
Bases: FormView
, BaseDetailView
Class that allow both a detail view and a form view.
UVCommentForm(author_id, uv_id, is_creation, *args, **kwargs)
¶
Bases: ModelForm
Form handeling creation and edit of an UVComment.
Source code in pedagogy/forms.py
UVCommentModerationForm
¶
Bases: Form
Form handeling bulk comment deletion.
UVCommentReportForm(reporter_id, comment_id, *args, **kwargs)
¶
Bases: ModelForm
Form handeling creation and edit of an UVReport.
Source code in pedagogy/forms.py
UVForm(author_id, *args, **kwargs)
¶
Bases: ModelForm
Form handeling creation and edit of an UV.
Source code in pedagogy/forms.py
UV
¶
Bases: Model
Contains infos about an UV (course).
has_user_already_commented(user)
¶
Help prevent multiples comments from the same user.
This function checks that no other comment has been posted by a specified user.
Returns:
Type | Description |
---|---|
bool
|
True if the user has already posted a comment on this UV, else False. |
Source code in pedagogy/models.py
UVComment
¶
Bases: Model
A comment about an UV.
UVCommentReport
¶
Bases: Model
Report an inapropriate comment.
UVDetailFormView
¶
Bases: PermissionRequiredMixin
, DetailFormView
Display every comment of an UV and detailed infos about it.
Allow to comment the UV.
UVCommentUpdateView
¶
UVCommentDeleteView
¶
UVGuideView
¶
Bases: PermissionRequiredMixin
, TemplateView
UV guide main page.
UVCommentReportCreateView
¶
Bases: PermissionRequiredMixin
, CreateView
Create a new report for an inapropriate comment.
UVModerationFormView
¶
Bases: PermissionRequiredMixin
, FormView
Moderation interface (Privileged).
UVCreateView
¶
Bases: PermissionRequiredMixin
, CreateView
Add a new UV (Privileged).
UVDeleteView
¶
Bases: PermissionRequiredMixin
, DeleteView
Allow to delete an UV (Privileged).
UVUpdateView
¶
Bases: PermissionRequiredMixin
, UpdateView
Allow to edit an UV (Privilegied).