gestioCOF/kfet/auth/fields.py

26 lines
759 B
Python
Raw Normal View History

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