From e5276693d30c57092a6e3ac1e82bbc936cbed025 Mon Sep 17 00:00:00 2001 From: nanoy Date: Sun, 6 Jan 2019 06:02:16 +0100 Subject: [PATCH] Export_group_list --- users/forms.py | 3 ++- users/templates/users/index.html | 1 + users/views.py | 15 ++++++++++----- 3 files changed, 13 insertions(+), 6 deletions(-) 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 @@
{% csrf_token %} {{export_form}} +
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)