2017-09-13 01:57:31 +02:00
|
|
|
from django import forms
|
|
|
|
from django.forms import widgets
|
|
|
|
|
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):
|
2019-01-14 22:41:38 +01:00
|
|
|
kwargs.setdefault("queryset", Group.objects.all())
|
|
|
|
kwargs.setdefault("widget", widgets.CheckboxSelectMultiple)
|
2017-09-26 22:18:39 +02:00
|
|
|
super().__init__(**kwargs)
|
|
|
|
|
|
|
|
|
|
|
|
class BasePermissionsField(forms.ModelMultipleChoiceField):
|
|
|
|
def __init__(self, **kwargs):
|
2019-01-14 22:41:38 +01:00
|
|
|
kwargs.setdefault("widget", widgets.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):
|
2019-01-14 22:41:38 +01:00
|
|
|
kwargs.setdefault("queryset", Permission.kfetcore.all())
|
2017-09-26 22:18:39 +02:00
|
|
|
super().__init__(**kwargs)
|