kpsul/kfet/auth/fields.py
2017-10-12 13:42:06 +02:00

25 lines
759 B
Python

from django import forms
from .models import Group, Permission
class GroupsField(forms.ModelMultipleChoiceField):
def __init__(self, **kwargs):
kwargs.setdefault('queryset', Group.objects.all())
kwargs.setdefault('widget', forms.CheckboxSelectMultiple)
super().__init__(**kwargs)
class BasePermissionsField(forms.ModelMultipleChoiceField):
def __init__(self, **kwargs):
kwargs.setdefault('widget', forms.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)