Aller au contenu

Views

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.

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.

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.

Forum

Bases: Model

The Forum class, made as a tree to allow nice tidy organization.

owner_club allows club members to moderate there own topics edit_groups allows to put any group as a forum admin view_groups allows some groups to view a forum

copy_rights()

Copy, if possible, the rights of the parent folder.

Source code in forum/models.py
def copy_rights(self):
    """Copy, if possible, the rights of the parent folder."""
    if self.parent is not None:
        self.owner_club = self.parent.owner_club
        self.edit_groups.set(self.parent.edit_groups.all())
        self.view_groups.set(self.parent.view_groups.all())
        self.save()

check_loop()

Raise a validation error when a loop is found within the parent list.

Source code in forum/models.py
def check_loop(self):
    """Raise a validation error when a loop is found within the parent list."""
    objs = []
    cur = self
    while cur.parent is not None:
        if cur in objs:
            raise ValidationError(_("You can not make loops in forums"))
        objs.append(cur)
        cur = cur.parent

ForumMessage

Bases: Model

A message in the forum (thx Cpt. Obvious.).

ForumMessageMeta

Bases: Model

ForumTopic

Bases: Model

ForumSearchView

Bases: ListView

ForumMainView

Bases: ListView

ForumMarkAllAsRead

Bases: RedirectView

ForumFavoriteTopics

Bases: ListView

ForumLastUnread

Bases: ListView

ForumNameField

Bases: ModelChoiceField

ForumForm

Bases: ModelForm

ForumCreateView

Bases: CanCreateMixin, CreateView

ForumEditForm

Bases: ForumForm

ForumEditView

Bases: CanEditPropMixin, UpdateView

ForumDeleteView

Bases: CanEditPropMixin, DeleteView

ForumDetailView

Bases: CanViewMixin, DetailView

TopicForm

Bases: ModelForm

ForumTopicCreateView

Bases: CanCreateMixin, CreateView

ForumTopicEditView

Bases: CanEditMixin, UpdateView

ForumTopicSubscribeView

Bases: LoginRequiredMixin, CanViewMixin, SingleObjectMixin, RedirectView

ForumTopicDetailView

Bases: CanViewMixin, DetailView

ForumMessageView

Bases: SingleObjectMixin, RedirectView

ForumMessageEditView

Bases: CanEditMixin, UpdateView

ForumMessageDeleteView

Bases: SingleObjectMixin, RedirectView

ForumMessageUndeleteView

Bases: SingleObjectMixin, RedirectView

ForumMessageCreateView

Bases: CanCreateMixin, CreateView

can_view(obj, user)

Can the user see the object.

Parameters:

Name Type Description Default
obj Any

Object to test for permission

required
user User

core.models.User to test permissions against

required

Returns:

Type Description
bool

True if user is authorized to see object else False

Examples:

if not can_view(self.object ,request.user):
    raise PermissionDenied
Source code in core/views/__init__.py
def can_view(obj: Any, user: User) -> bool:
    """Can the user see the object.

    Args:
        obj: Object to test for permission
        user: core.models.User to test permissions against

    Returns:
        True if user is authorized to see object else False

    Examples:
        ```python
        if not can_view(self.object ,request.user):
            raise PermissionDenied
        ```
    """
    if obj is None or user.can_view(obj):
        return True
    return can_edit(obj, user)