diff --git a/users/forms.py b/users/forms.py index 5afd808..e564ecd 100644 --- a/users/forms.py +++ b/users/forms.py @@ -128,4 +128,5 @@ class ExportForm(forms.Form): ('debit', 'Débit') ) query_type = forms.ChoiceField(choices=QUERY_TYPE_CHOICES, label="Ensemble de la demande") - fields = forms.MultipleChoiceField(widget=forms.CheckboxSelectMultiple, choices=FIELDS_CHOICES, label="Champs") \ No newline at end of file + fields = forms.MultipleChoiceField(widget=forms.CheckboxSelectMultiple, choices=FIELDS_CHOICES, label="Champs") + group = forms.ModelChoiceField(queryset=Group.objects.all(), empty_label="Tous les groupes", required=False, label="Groupe") \ No newline at end of file diff --git a/users/templates/users/index.html b/users/templates/users/index.html index cf16059..451c552 100644 --- a/users/templates/users/index.html +++ b/users/templates/users/index.html @@ -106,6 +106,7 @@
diff --git a/users/views.py b/users/views.py index bb183c8..03c1fc9 100644 --- a/users/views.py +++ b/users/views.py @@ -83,19 +83,24 @@ def export_csv(request): users = User.objects qt = export_form.cleaned_data['query_type'] if qt == 'all': - users = users.all() - filename="Utilisateurs-coope" + filename = "Utilisateurs-coope" + if not export_form.cleaned_data['group']: + users = users.all() elif qt == 'all_active': users = users.filter(is_active=True) - filename="Utilisateurs-actifs-coope" + filename = "Utilisateurs-actifs-coope" elif qt == 'adherent': pks = [x.pk for x in User.objects.all() if x.profile.is_adherent] users = users.filter(pk__in=pks) - filename="Adherents-coope" + filename = "Adherents-coope" elif qt == 'adherent_active': pks = [x.pk for x in User.objects.filter(is_active=True) if x.profile.is_adherent] users = users.filter(pk__in=pks) - filename="Adherents-actifs-coope" + filename = "Adherents-actifs-coope" + if export_form.cleaned_data['group']: + group = export_form.cleaned_data['group'] + users = users.filter(groups=group) + filename += "(" + group.name + ")" response = HttpResponse(content_type='text/csv') response['Content-Disposition'] = 'attachment; filename="'+ filename + '.csv"' writer = csv.writer(response)