diff --git a/borgia/forms.py b/borgia/forms.py index 1f3a7289..c56704ee 100644 --- a/borgia/forms.py +++ b/borgia/forms.py @@ -37,9 +37,12 @@ def clean(self): # User credential check try: - User.objects.get(username=cleaned_data['username']) + u = User.objects.get(username=cleaned_data['username']) except ObjectDoesNotExist: raise forms.ValidationError("L'utilisateur n'existe pas") + if not u.is_active: + raise forms.ValidationError("L'utilisateur a été desactivé") + user = authenticate( username=cleaned_data['username'], password=cleaned_data['password'] diff --git a/finances/forms.py b/finances/forms.py index ee8d39ea..f027bd90 100644 --- a/finances/forms.py +++ b/finances/forms.py @@ -56,6 +56,8 @@ def clean_recipient(self): except ObjectDoesNotExist: raise forms.ValidationError("L'utilisateur n'existe pas !") + if not recipient.is_active: + raise forms.ValidationError("L'utilisateur a été desactivé !") if self.sender == recipient: # Send to self : Impossible raise forms.ValidationError("Vous ne pouvez pas transferez à vous même !") @@ -344,7 +346,10 @@ def clean_user(self): try: user = User.objects.get(username=username) except ObjectDoesNotExist: - raise forms.ValidationError("L'utilisateur n'existe pas !") + raise forms.ValidationError("L'utilisateur n'existe pas !") + + if not user.is_active : + raise forms.ValidationError("L'utilisateur a été desactivé !") return user @@ -353,6 +358,7 @@ class SharedEventDownloadXlsxForm(forms.Form): state = forms.ChoiceField(label='Selection', choices=(('year', 'Listes de promotions'), ('registrants', 'Préinscrit'), ('participants', 'Participants'))) + years = forms.MultipleChoiceField(label='Année(s) à inclure', required=False) def __init__(self, **kwargs): super(SharedEventDownloadXlsxForm, self).__init__(**kwargs) @@ -361,11 +367,7 @@ def __init__(self, **kwargs): YEAR_CHOICES.append( (year, year) ) - self.fields['years'] = forms.MultipleChoiceField( - label='Année à inclure ', - choices=YEAR_CHOICES, - required=False - ) + self.fields['years'].choices = YEAR_CHOICES class SharedEventUploadXlsxForm(forms.Form): diff --git a/finances/views.py b/finances/views.py index 0a076180..2b630695 100644 --- a/finances/views.py +++ b/finances/views.py @@ -1742,7 +1742,7 @@ def form_valid(self, form): if form.cleaned_data['years']: list_year_result = form.cleaned_data['years'] # Contains the years selected - users = User.objects.filter(year__in=list_year_result).exclude(groups=Group.objects.get(pk=1)).order_by('username') + users = User.objects.filter(year__in=list_year_result, is_active=True).exclude(groups=Group.objects.get(pk=1)).order_by('username') for u in users: ws.append([u.username, '', '',u.last_name + ' ' + u.first_name, u.surname]) diff --git a/modules/forms.py b/modules/forms.py index 2081c9da..ce6bbc67 100644 --- a/modules/forms.py +++ b/modules/forms.py @@ -47,9 +47,11 @@ def clean(self): self.client = User.objects.get( username= self.cleaned_data['client']) except ObjectDoesNotExist: - raise forms.ValidationError('Utilisateur inconnu') + raise forms.ValidationError("L'utilisateur n'existe pas") except KeyError: raise forms.ValidationError('Utilisateur non sélectionné') + if not self.client.is_active: + raise forms.ValidationError("L'utilisateur a été desactivé") total_price = 0 for field in self.cleaned_data: if field != 'client': diff --git a/users/forms.py b/users/forms.py index 461f28a3..48affa7f 100644 --- a/users/forms.py +++ b/users/forms.py @@ -141,9 +141,10 @@ class UserSearchForm(forms.Form): 'autofocus': 'true', 'placeholder': "Nom / Prénom / Surnom"})) year = forms.ChoiceField(label='Année', required=False) - state = forms.ChoiceField(label='Etat', choices=(('all', 'Tous les utilisateurs'), - ('True', 'Uniquement les activés'), - ('False', 'Uniquement les desactivés')), + state = forms.ChoiceField(label='Etat', choices=(('all', 'Tous les actifs'), + ('negative_balance', 'Uniquement ceux à solde négative'), + ('threshold', 'Uniquement ceux en-dessous du seuil de commande'), + ('unactive', 'Uniquement ceux désactivés')), required=False) def __init__(self, **kwargs): diff --git a/users/models.py b/users/models.py index af11f727..7f6cab71 100644 --- a/users/models.py +++ b/users/models.py @@ -310,7 +310,7 @@ def list_year(): :returns: list of integer years used by users, sorted the decreasing dates. """ list_year = [] - for u in User.objects.all().exclude(groups=6).exclude(pk=1): # Parmis tout les users moins les gadz d'honn'ss et l'admin + for u in User.objects.filter(is_active=True).exclude(groups=6).exclude(pk=1): # Parmis tout les users moins les gadz d'honn'ss et l'admin if u.year not in list_year: if u.year is not None: # year is not mandatory list_year.append(u.year) diff --git a/users/templates/users/user_list.html b/users/templates/users/user_list.html index 93959381..96186a84 100644 --- a/users/templates/users/user_list.html +++ b/users/templates/users/user_list.html @@ -44,7 +44,6 @@ {% endif %} {% endfor %} -