Aller au contenu

# Views

## `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`

    159
    160
    161
    162
    163
    164
    165
    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`

    189
    190
    191
    192
    193
    194
    195
    196
    197
    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: `UserPassesTestMixin`, `CreateView`

## `ForumEditForm`

Bases: `ForumForm`

## `ForumEditView`

Bases: `CanEditPropMixin`, `UpdateView`

## `ForumDeleteView`

Bases: `CanEditPropMixin`, `DeleteView`

## `ForumDetailView`

Bases: `CanViewMixin`, `DetailView`

## `TopicForm`

Bases: `ModelForm`

## `ForumTopicCreateView`

Bases: `LoginRequiredMixin`, `UserPassesTestMixin`, `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: `LoginRequiredMixin`, `UserPassesTestMixin`, `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

Example

    if not can_view(self.object ,request.user):
        raise PermissionDenied

Source code in `core/auth/mixins.py`

     85
     86
     87
     88
     89
     90
     91
     92
     93
     94
     95
     96
     97
     98
     99
    100
    101
    102
    103
    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

        Example:
            ```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)