42 lines
1.5 KiB
Python
42 lines
1.5 KiB
Python
from django import forms
|
|
from django.contrib.auth import get_user_model
|
|
|
|
User = get_user_model()
|
|
|
|
class UserConfigDuplicateForm(forms.Form):
|
|
user = forms.ModelChoiceField(
|
|
queryset=User.objects.order_by('username'),
|
|
label="Nouvel utilisateur",
|
|
widget=forms.Select(attrs={"class": "vTextField admin-autocomplete"})
|
|
)
|
|
|
|
|
|
class UserConfigAssignCompanyForm(forms.Form):
|
|
company = forms.ModelChoiceField(
|
|
queryset=None, # set in __init__
|
|
label="Société à assigner",
|
|
required=False,
|
|
empty_label="— Aucune (retirer la société) —",
|
|
help_text="La société sélectionnée sera appliquée à tous les utilisateurs choisis.",
|
|
)
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
super().__init__(*args, **kwargs)
|
|
from contracts.models import Company
|
|
self.fields['company'].queryset = Company.objects.order_by('name')
|
|
|
|
|
|
class UserConfigCopyFromForm(forms.Form):
|
|
source = forms.ModelChoiceField(
|
|
queryset=None, # set in __init__
|
|
label="Copier la configuration depuis",
|
|
help_text="Toute la configuration de cet utilisateur sera recopiée sur les utilisateurs sélectionnés.",
|
|
)
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
super().__init__(*args, **kwargs)
|
|
# Import here to avoid circular imports at module level
|
|
from common.models import UserConfig
|
|
self.fields['source'].queryset = (
|
|
UserConfig.objects.select_related('user').order_by('user__username')
|
|
)
|