Fix dev data

This commit is contained in:
Ludovic Stephan 2020-08-03 20:35:56 +02:00
parent d6fa738a25
commit 2d36c85085
3 changed files with 30 additions and 31 deletions

View file

@ -7,7 +7,7 @@ from .models import KFetPermission
class KFetPermissionsField(forms.ModelMultipleChoiceField):
def __init__(self, *args, **kwargs):
kwargs.setdefault("queryset", KFetPermission.kfet.all())
kwargs.setdefault("queryset", KFetPermission.objects.all())
kwargs.setdefault("widget", widgets.CheckboxSelectMultiple)
super().__init__(*args, **kwargs)

View file

@ -3,6 +3,8 @@ from django.db import models
from django.utils.crypto import get_random_string
from django.utils.translation import ugettext_lazy as _
KFET_APP_LABELS = ["kfet", "kfetauth"]
class GenericTeamTokenManager(models.Manager):
def create_token(self):
@ -18,28 +20,36 @@ class GenericTeamToken(models.Model):
objects = GenericTeamTokenManager()
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"])
super().get_queryset().filter(content_type__app_label__in=KFET_APP_LABELS)
)
class KFetPermission(Permission):
kfet = KFetPermissionManager()
objects = KFetPermissionManager()
class Meta:
proxy = True
verbose_name = _("Permission K-Fêt")
verbose_name_plural = _("Permissions K-Fêt")
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`)
def give_admin_access(self):
perms = KFetPermission.objects.all()
self.permissions.add(*perms)
def give_staff_access(self):
perms = KFetPermission.objects.filter(
codename__in=["is_team", "perform_deposit", "add_account", "add_transfer"]
)
self.permissions.add(*perms)
class Meta:
verbose_name = _("Groupe K-Fêt")
verbose_name_plural = _("Groupes K-Fêt")

View file

@ -6,12 +6,13 @@ import os
import random
from datetime import timedelta
from django.contrib.auth.models import Group, Permission, User
from django.contrib.auth.models import User
from django.core.management import call_command
from django.utils import timezone
from gestioncof.management.base import MyBaseCommand
from gestioncof.models import CofProfile
from kfet.auth.models import KFetGroup
from kfet.models import (
Account,
Article,
@ -33,23 +34,11 @@ class Command(MyBaseCommand):
# Groupes
# ---
Group.objects.filter(name__icontains="K-Fêt").delete()
group_chef, _ = KFetGroup.objects.get_or_create(name="K-Fêt César")
group_boy, _ = KFetGroup.objects.get_or_create(name="K-Fêt Légionnaire")
group_chef = Group(name="K-Fêt César")
group_boy = Group(name="K-Fêt Légionnaire")
group_chef.save()
group_boy.save()
permissions_chef = Permission.objects.filter(
content_type__app_label="kfet",
)
permissions_boy = Permission.objects.filter(
content_type__app_label="kfet", codename__in=["is_team", "perform_deposit"]
)
group_chef.permissions.add(*permissions_chef)
group_boy.permissions.add(*permissions_boy)
group_chef.give_admin_access()
group_chef.give_staff_access()
# ---
# Comptes