2017-09-13 01:57:31 +02:00
|
|
|
from django import forms
|
2020-08-03 19:06:48 +02:00
|
|
|
from django.contrib.auth.models import Group
|
2017-09-13 01:57:31 +02:00
|
|
|
from django.forms import widgets
|
|
|
|
|
2020-08-03 19:06:48 +02:00
|
|
|
from .models import KFetPermission
|
|
|
|
|
2017-09-13 01:57:31 +02:00
|
|
|
|
|
|
|
class KFetPermissionsField(forms.ModelMultipleChoiceField):
|
|
|
|
def __init__(self, *args, **kwargs):
|
2020-08-03 19:06:48 +02:00
|
|
|
kwargs.setdefault("queryset", KFetPermission.kfet.all())
|
|
|
|
kwargs.setdefault("widget", widgets.CheckboxSelectMultiple)
|
|
|
|
super().__init__(*args, **kwargs)
|
|
|
|
|
|
|
|
def label_from_instance(self, obj):
|
|
|
|
return obj.name
|
|
|
|
|
|
|
|
|
|
|
|
class KFetGroupsField(forms.ModelMultipleChoiceField):
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
kwargs.setdefault("queryset", Group.objects.filter(kfetgroup__isnull=False))
|
|
|
|
kwargs.setdefault("widget", widgets.SelectMultiple)
|
|
|
|
super().__init__(*args, **kwargs)
|
2017-09-13 01:57:31 +02:00
|
|
|
|
|
|
|
def label_from_instance(self, obj):
|
|
|
|
return obj.name
|