gestioCOF/kfet/auth/fields.py
2019-01-14 22:41:38 +01:00

26 lines
796 B
Python

from django import forms
from django.forms import widgets
from .models import Group, Permission
class GroupsField(forms.ModelMultipleChoiceField):
def __init__(self, **kwargs):
kwargs.setdefault("queryset", Group.objects.all())
kwargs.setdefault("widget", widgets.CheckboxSelectMultiple)
super().__init__(**kwargs)
class BasePermissionsField(forms.ModelMultipleChoiceField):
def __init__(self, **kwargs):
kwargs.setdefault("widget", widgets.CheckboxSelectMultiple)
super().__init__(**kwargs)
def label_from_instance(self, obj):
return obj.name
class CorePermissionsField(BasePermissionsField):
def __init__(self, **kwargs):
kwargs.setdefault("queryset", Permission.kfetcore.all())
super().__init__(**kwargs)