2017-09-13 01:57:31 +02:00
|
|
|
from django import forms
|
|
|
|
|
2017-09-26 22:18:39 +02:00
|
|
|
from .models import Group, Permission
|
2017-09-13 01:57:31 +02:00
|
|
|
|
|
|
|
|
2017-09-26 22:18:39 +02:00
|
|
|
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)
|
2017-09-26 22:18:39 +02:00
|
|
|
super().__init__(**kwargs)
|
|
|
|
|
|
|
|
|
|
|
|
class BasePermissionsField(forms.ModelMultipleChoiceField):
|
|
|
|
def __init__(self, **kwargs):
|
2017-10-12 13:42:06 +02:00
|
|
|
kwargs.setdefault('widget', forms.CheckboxSelectMultiple)
|
2017-09-26 22:18:39 +02:00
|
|
|
super().__init__(**kwargs)
|
2017-09-13 01:57:31 +02:00
|
|
|
|
|
|
|
def label_from_instance(self, obj):
|
|
|
|
return obj.name
|
2017-09-26 22:18:39 +02:00
|
|
|
|
|
|
|
|
|
|
|
class CorePermissionsField(BasePermissionsField):
|
|
|
|
def __init__(self, **kwargs):
|
|
|
|
kwargs.setdefault('queryset', Permission.kfetcore.all())
|
|
|
|
super().__init__(**kwargs)
|