diff --git a/loko/authorizations/forms.py b/loko/authorizations/forms.py index dd1d041..21c2328 100644 --- a/loko/authorizations/forms.py +++ b/loko/authorizations/forms.py @@ -134,8 +134,38 @@ class AuthorizationFilterForm(forms.Form): widget=forms.CheckboxSelectMultiple(attrs={'class': 'form-check-input'}), required=False, ) + agent = forms.MultipleChoiceField( + label=_("Agent traitant"), + widget=forms.CheckboxSelectMultiple(attrs={'class': 'form-check-input'}), + required=False, + ) search_text = forms.CharField( max_length=250, required=False, widget=forms.TextInput(attrs={'class': 'form-control', 'placeholder': _('Recherche…')}), ) + + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + from django.contrib.auth import get_user_model + from django.db.models import Q + from common.utils import get_short_name + User = get_user_model() + + agent_ids = RoadAuthorization.objects.exclude(agent__isnull=True).values_list('agent_id', flat=True) + agent_qs = User.objects.filter( + Q(id__in=agent_ids) | + Q(config__accessible_views__code='authorizations') | + Q(is_superuser=True) + ).distinct() + + agent_choices = [ + ('unassigned', _("Non assigné")), + ] + user_list = [ + (str(u.pk), get_short_name(u)) for u in agent_qs + ] + user_list.sort(key=lambda x: x[1].lower()) + agent_choices.extend(user_list) + self.fields['agent'].choices = agent_choices + diff --git a/loko/authorizations/templates/authorizations/authorization_list.html b/loko/authorizations/templates/authorizations/authorization_list.html index ab6abc8..1fdb81e 100644 --- a/loko/authorizations/templates/authorizations/authorization_list.html +++ b/loko/authorizations/templates/authorizations/authorization_list.html @@ -1,5 +1,5 @@ {% extends "base.html" %} -{% load i18n static %} +{% load i18n static short_name %} {% block head %} @@ -63,13 +63,13 @@
-
+
{{ filter_form.search_text }}
-
+
-
+
+ + +
+
{{ filter_form.include_archives }}
-
+
@@ -139,6 +178,7 @@ {% translate "Type" %} {% translate "Statut" %} {% translate "Demandeur" %} + {% translate "Agent" %} {% translate "Localisation" %} {% translate "Date de création" %} @@ -163,6 +203,7 @@ {% endif %} {{ auth.applicant_name }} + {{ auth.agent|short_name|default:"—" }} {{ auth.location }} {{ auth.creation_date|date:"d/m/Y" }} @@ -173,7 +214,7 @@ {% empty %} - + {% translate "Aucune demande trouvée." %} @@ -192,6 +233,7 @@ {% block script %}