ded824bddd
KFetGroup model - Provides a distinction from non-kfet Groups. - Convert code appropriately. - Initially filled from Groups containing K-Fêt (this was the previous distinction) in the kfetauth.0002 migration. Permission proxy model (kfetauth app) - Proxy of the django.contrib.auth Permission model. - Adds the 'kfet' manager which returns only kfet-related permissions. KeepUnselectableModelFormMixin - Helps to keep the unselectable items of many-to-many field for ModelForm. - 'kfetauth' forms (related to KFetGroup) use this mixin. Using KFetGroup allows to simplify the 'kfet/account_group_form.html' template. A bug is also fixed in 'kfet/form_field_snippet.html', which could lead to prevent field displays if they used CheckboxSelectMultiple widget.
43 lines
1.1 KiB
Python
43 lines
1.1 KiB
Python
from django.contrib.auth.models import (
|
|
Group as DjangoGroup, Permission as DjangoPermission,
|
|
)
|
|
from django.db import models
|
|
from django.utils.translation import ugettext_lazy as _
|
|
|
|
|
|
class GenericTeamToken(models.Model):
|
|
token = models.CharField(max_length=50, unique=True)
|
|
|
|
|
|
class Group(DjangoGroup):
|
|
|
|
def give_admin_access(self):
|
|
perms = Permission.kfetcore.all()
|
|
self.permissions.add(*perms)
|
|
|
|
def give_staff_access(self):
|
|
perms = Permission.kfetcore.filter(
|
|
codename__in=['is_team', 'perform_deposit'])
|
|
self.permissions.add(*perms)
|
|
|
|
class Meta:
|
|
verbose_name = _("Groupe")
|
|
verbose_name_plural = _("Groupes")
|
|
|
|
|
|
KFET_CORE_APP_LABELS = ['kfet', 'kfetauth']
|
|
|
|
|
|
class CorePermissionManager(models.Manager):
|
|
def get_queryset(self):
|
|
return super().get_queryset().filter(
|
|
content_type__app_label__in=KFET_CORE_APP_LABELS)
|
|
|
|
|
|
class Permission(DjangoPermission):
|
|
kfetcore = CorePermissionManager()
|
|
|
|
class Meta:
|
|
proxy = True
|
|
verbose_name = _("Permission")
|
|
verbose_name_plural = _("Permissions")
|