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):
|
|
|
|
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)
|
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)
|