3
0
Fork 0
mirror of https://github.com/nanoy42/coope synced 2024-11-05 01:16:28 +00:00

Export_group_list

This commit is contained in:
Yoann Pétri 2019-01-06 06:02:16 +01:00
parent 4068c5212a
commit e5276693d3
3 changed files with 13 additions and 6 deletions

View file

@ -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")
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">
{% csrf_token %}
{{export_form}}
<br>
<button class="button" target="_blank">Exporter au format csv</button>
</form>
</section>

View file

@ -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)