manager: hide internal roles in agenda settings (#77155)
gitea/chrono/pipeline/head This commit looks good
Details
gitea/chrono/pipeline/head This commit looks good
Details
This commit is contained in:
parent
6f85279226
commit
f0041d5ad8
|
@ -26,7 +26,6 @@ import django_filters
|
||||||
from dateutil.relativedelta import relativedelta
|
from dateutil.relativedelta import relativedelta
|
||||||
from django import forms
|
from django import forms
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.contrib.auth.models import Group
|
|
||||||
from django.contrib.humanize.templatetags.humanize import ordinal
|
from django.contrib.humanize.templatetags.humanize import ordinal
|
||||||
from django.core.exceptions import FieldDoesNotExist
|
from django.core.exceptions import FieldDoesNotExist
|
||||||
from django.core.validators import URLValidator
|
from django.core.validators import URLValidator
|
||||||
|
@ -70,16 +69,13 @@ from chrono.utils.lingo import get_agenda_check_types
|
||||||
from chrono.utils.timezone import localtime, make_aware, now
|
from chrono.utils.timezone import localtime, make_aware, now
|
||||||
|
|
||||||
from . import widgets
|
from . import widgets
|
||||||
|
from .utils import get_role_queryset
|
||||||
from .widgets import SplitDateTimeField, WeekdaysWidget
|
from .widgets import SplitDateTimeField, WeekdaysWidget
|
||||||
|
|
||||||
|
|
||||||
class AgendaAddForm(forms.ModelForm):
|
class AgendaAddForm(forms.ModelForm):
|
||||||
edit_role = forms.ModelChoiceField(
|
edit_role = forms.ModelChoiceField(label=_('Edit Role'), required=False, queryset=get_role_queryset())
|
||||||
label=_('Edit Role'), required=False, queryset=Group.objects.all().order_by('name')
|
view_role = forms.ModelChoiceField(label=_('View Role'), required=False, queryset=get_role_queryset())
|
||||||
)
|
|
||||||
view_role = forms.ModelChoiceField(
|
|
||||||
label=_('View Role'), required=False, queryset=Group.objects.all().order_by('name')
|
|
||||||
)
|
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Agenda
|
model = Agenda
|
||||||
|
@ -155,12 +151,8 @@ class UnavailabilityCalendarAddForm(forms.ModelForm):
|
||||||
model = UnavailabilityCalendar
|
model = UnavailabilityCalendar
|
||||||
fields = ['label', 'edit_role', 'view_role']
|
fields = ['label', 'edit_role', 'view_role']
|
||||||
|
|
||||||
edit_role = forms.ModelChoiceField(
|
edit_role = forms.ModelChoiceField(label=_('Edit Role'), required=False, queryset=get_role_queryset())
|
||||||
label=_('Edit Role'), required=False, queryset=Group.objects.all().order_by('name')
|
view_role = forms.ModelChoiceField(label=_('View Role'), required=False, queryset=get_role_queryset())
|
||||||
)
|
|
||||||
view_role = forms.ModelChoiceField(
|
|
||||||
label=_('View Role'), required=False, queryset=Group.objects.all().order_by('name')
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class UnavailabilityCalendarEditForm(UnavailabilityCalendarAddForm):
|
class UnavailabilityCalendarEditForm(UnavailabilityCalendarAddForm):
|
||||||
|
@ -1639,7 +1631,7 @@ class SharedCustodyPeriodForm(forms.ModelForm):
|
||||||
|
|
||||||
class SharedCustodySettingsForm(forms.ModelForm):
|
class SharedCustodySettingsForm(forms.ModelForm):
|
||||||
management_role = forms.ModelChoiceField(
|
management_role = forms.ModelChoiceField(
|
||||||
label=_('Management role'), required=False, queryset=Group.objects.all().order_by('name')
|
label=_('Management role'), required=False, queryset=get_role_queryset()
|
||||||
)
|
)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
|
|
|
@ -18,6 +18,7 @@ import collections
|
||||||
import itertools
|
import itertools
|
||||||
|
|
||||||
from django.contrib.auth.models import Group
|
from django.contrib.auth.models import Group
|
||||||
|
from django.core.exceptions import FieldDoesNotExist
|
||||||
from django.db import transaction
|
from django.db import transaction
|
||||||
from django.db.models import Q
|
from django.db.models import Q
|
||||||
|
|
||||||
|
@ -124,3 +125,14 @@ def import_site(data, if_empty=False, clean=False, overwrite=False):
|
||||||
results[key]['updated'].append(obj)
|
results[key]['updated'].append(obj)
|
||||||
SharedCustodySettings.import_json(data.get('shared_custody_settings', {}))
|
SharedCustodySettings.import_json(data.get('shared_custody_settings', {}))
|
||||||
return results
|
return results
|
||||||
|
|
||||||
|
|
||||||
|
def get_role_queryset():
|
||||||
|
qs = Group.objects.all().order_by('name')
|
||||||
|
|
||||||
|
try:
|
||||||
|
Group._meta.get_field('role')
|
||||||
|
except FieldDoesNotExist:
|
||||||
|
return qs
|
||||||
|
|
||||||
|
return qs.exclude(role__slug__startswith='_')
|
||||||
|
|
Loading…
Reference in New Issue