2020-08-03 19:04:36 +02:00
|
|
|
from django.contrib.auth.models import Group, Permission
|
2017-09-13 01:57:31 +02:00
|
|
|
from django.db import models
|
2017-09-25 17:16:19 +02:00
|
|
|
from django.utils.crypto import get_random_string
|
2020-08-03 19:04:36 +02:00
|
|
|
from django.utils.translation import ugettext_lazy as _
|
2017-09-25 17:16:19 +02:00
|
|
|
|
|
|
|
|
|
|
|
class GenericTeamTokenManager(models.Manager):
|
|
|
|
def create_token(self):
|
|
|
|
token = get_random_string(50)
|
|
|
|
while self.filter(token=token).exists():
|
|
|
|
token = get_random_string(50)
|
|
|
|
return self.create(token=token)
|
2017-09-13 01:57:31 +02:00
|
|
|
|
|
|
|
|
|
|
|
class GenericTeamToken(models.Model):
|
|
|
|
token = models.CharField(max_length=50, unique=True)
|
2017-09-25 17:16:19 +02:00
|
|
|
|
|
|
|
objects = GenericTeamTokenManager()
|
2020-08-03 19:04:36 +02:00
|
|
|
|
|
|
|
|
|
|
|
class KFetGroup(Group):
|
|
|
|
# Même si on n'ajoute que des méthodes, on fait un héritage complet pour
|
|
|
|
# mieux distinguer les groupes K-Fêt via l'ORM (i.e. faire `KFetGroup.objects.all`)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
verbose_name = _("Groupe K-Fêt")
|
|
|
|
verbose_name_plural = _("Groupes K-Fêt")
|
|
|
|
|
|
|
|
|
|
|
|
class KFetPermissionManager(models.Manager):
|
|
|
|
def get_queryset(self):
|
|
|
|
return (
|
|
|
|
super()
|
|
|
|
.get_queryset()
|
|
|
|
.filter(content_type__app_label__in=["kfet", "kfetauth"])
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
class KFetPermission(Permission):
|
|
|
|
kfet = KFetPermissionManager()
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
proxy = True
|
|
|
|
verbose_name = _("Permission K-Fêt")
|
|
|
|
verbose_name_plural = _("Permissions K-Fêt")
|