3
0
Fork 0
mirror of https://github.com/nanoy42/coope synced 2024-12-25 16:33:47 +00:00

Merge branch 'export_group_list' into dev

Close #28
This commit is contained in:
Yoann Pétri 2019-01-06 06:02:45 +01:00
commit f10309a1ce
3 changed files with 13 additions and 6 deletions

View file

@ -129,3 +129,4 @@ class ExportForm(forms.Form):
) )
query_type = forms.ChoiceField(choices=QUERY_TYPE_CHOICES, label="Ensemble de la demande") query_type = forms.ChoiceField(choices=QUERY_TYPE_CHOICES, label="Ensemble de la demande")
fields = forms.MultipleChoiceField(widget=forms.CheckboxSelectMultiple, choices=FIELDS_CHOICES, label="Champs") 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")

View file

@ -106,6 +106,7 @@
<form action="{% url 'users:exportCSV' %}" method="POST"> <form action="{% url 'users:exportCSV' %}" method="POST">
{% csrf_token %} {% csrf_token %}
{{export_form}} {{export_form}}
<br>
<button class="button" target="_blank">Exporter au format csv</button> <button class="button" target="_blank">Exporter au format csv</button>
</form> </form>
</section> </section>

View file

@ -83,8 +83,9 @@ def export_csv(request):
users = User.objects users = User.objects
qt = export_form.cleaned_data['query_type'] qt = export_form.cleaned_data['query_type']
if qt == 'all': 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': elif qt == 'all_active':
users = users.filter(is_active=True) users = users.filter(is_active=True)
filename = "Utilisateurs-actifs-coope" filename = "Utilisateurs-actifs-coope"
@ -96,6 +97,10 @@ def export_csv(request):
pks = [x.pk for x in User.objects.filter(is_active=True) if x.profile.is_adherent] pks = [x.pk for x in User.objects.filter(is_active=True) if x.profile.is_adherent]
users = users.filter(pk__in=pks) 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 = HttpResponse(content_type='text/csv')
response['Content-Disposition'] = 'attachment; filename="'+ filename + '.csv"' response['Content-Disposition'] = 'attachment; filename="'+ filename + '.csv"'
writer = csv.writer(response) writer = csv.writer(response)