Aller au contenu

Views

Notification

Bases: Model

RealGroup

Bases: Group

RealGroups are created by the developer.

Most of the time they match a number in settings to be easily used for permissions.

CanCreateMixin

Bases: View

Protect any child view that would create an object.

Raises:

Type Description
PermissionDenied

If the user has not the necessary permission to create the object of the view.

CanEditPropMixin

Bases: GenericContentPermissionMixinBuilder

Ensure the user has owner permissions on the child view object.

In other word, you can make a view with this view as parent, and it will be retricted to the users that are in the object's owner_group or that pass the obj.can_be_viewed_by test.

Raises:

Type Description
PermissionDenied

If the user cannot see the 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.

DetailFormView

Bases: SingleObjectMixin, FormView

Class that allow both a detail view and a form view.

get_object()

Get current group from id in url.

Source code in core/views/__init__.py
def get_object(self):
    """Get current group from id in url."""
    return self.cached_object

cached_object()

Optimisation on group retrieval.

Source code in core/views/__init__.py
@cached_property
def cached_object(self):
    """Optimisation on group retrieval."""
    return super().get_object()

FormerSubscriberMixin

Bases: AccessMixin

Check if the user was at least an old subscriber.

Raises:

Type Description
PermissionDenied

if the user never subscribed.

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
def __init__(self, author_id, uv_id, is_creation, *args, **kwargs):
    super().__init__(*args, **kwargs)
    self.fields["author"].queryset = User.objects.filter(id=author_id).all()
    self.fields["author"].initial = author_id
    self.fields["uv"].queryset = UV.objects.filter(id=uv_id).all()
    self.fields["uv"].initial = uv_id
    self.is_creation = is_creation

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
def __init__(self, reporter_id, comment_id, *args, **kwargs):
    super().__init__(*args, **kwargs)
    self.fields["reporter"].queryset = User.objects.filter(id=reporter_id).all()
    self.fields["reporter"].initial = reporter_id
    self.fields["comment"].queryset = UVComment.objects.filter(id=comment_id).all()
    self.fields["comment"].initial = comment_id

UVForm(author_id, *args, **kwargs)

Bases: ModelForm

Form handeling creation and edit of an UV.

Source code in pedagogy/forms.py
def __init__(self, author_id, *args, **kwargs):
    super().__init__(*args, **kwargs)
    self.fields["author"].queryset = User.objects.filter(id=author_id).all()
    self.fields["author"].initial = author_id

UV

Bases: Model

Contains infos about an UV (course).

is_owned_by(user)

Can be created by superuser, root or pedagogy admin user.

Source code in pedagogy/models.py
def is_owned_by(self, user):
    """Can be created by superuser, root or pedagogy admin user."""
    return user.is_in_group(pk=settings.SITH_GROUP_PEDAGOGY_ADMIN_ID)

can_be_viewed_by(user)

Only visible by subscribers.

Source code in pedagogy/models.py
def can_be_viewed_by(self, user):
    """Only visible by subscribers."""
    return user.is_subscribed

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
def has_user_already_commented(self, user: User) -> bool:
    """Help prevent multiples comments from the same user.

    This function checks that no other comment has been posted by a specified user.

    Returns:
        True if the user has already posted a comment on this UV, else False.
    """
    return self.comments.filter(author=user).exists()

UVComment

Bases: Model

A comment about an UV.

is_owned_by(user)

Is owned by a pedagogy admin, a superuser or the author himself.

Source code in pedagogy/models.py
def is_owned_by(self, user):
    """Is owned by a pedagogy admin, a superuser or the author himself."""
    return self.author == user or user.is_owner(self.uv)

is_reported()

Return True if someone reported this UV.

Source code in pedagogy/models.py
@cached_property
def is_reported(self):
    """Return True if someone reported this UV."""
    return self.reports.exists()

UVCommentReport

Bases: Model

Report an inapropriate comment.

is_owned_by(user)

Can be created by a pedagogy admin, a superuser or a subscriber.

Source code in pedagogy/models.py
def is_owned_by(self, user):
    """Can be created by a pedagogy admin, a superuser or a subscriber."""
    return user.is_subscribed or user.is_owner(self.comment.uv)

UVDetailFormView

Bases: CanViewMixin, DetailFormView

Display every comment of an UV and detailed infos about it.

Allow to comment the UV.

UVCommentUpdateView

Bases: CanEditPropMixin, UpdateView

Allow edit of a given comment.

UVCommentDeleteView

Bases: CanEditPropMixin, DeleteView

Allow delete of a given comment.

UVGuideView

Bases: LoginRequiredMixin, FormerSubscriberMixin, TemplateView

UV guide main page.

UVCommentReportCreateView

Bases: CanCreateMixin, CreateView

Create a new report for an inapropriate comment.

UVModerationFormView

Bases: FormView

Moderation interface (Privileged).

UVCreateView

Bases: CanCreateMixin, CreateView

Add a new UV (Privileged).

UVDeleteView

Bases: CanEditPropMixin, DeleteView

Allow to delete an UV (Privileged).

UVUpdateView

Bases: CanEditPropMixin, UpdateView

Allow to edit an UV (Privilegied).