mirror of
https://github.com/nanoy42/coope
synced 2024-12-25 08:23:46 +00:00
Export_group_list
This commit is contained in:
parent
4068c5212a
commit
e5276693d3
3 changed files with 13 additions and 6 deletions
|
@ -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")
|
|
@ -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>
|
||||||
|
|
|
@ -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)
|
||||||
|
|
Loading…
Reference in a new issue