Merge branch 'dodo/bds_export_csv' into 'master'

Dodo/bds export csv

Closes #285

See merge request klub-dev-ens/gestioCOF!481
This commit is contained in:
Martin Pepin 2021-01-29 19:38:55 +01:00
commit ba9aa06b4f
4 changed files with 34 additions and 2 deletions

View file

@ -29,6 +29,10 @@ adhérents ni des cotisations.
ses places pour pouvoir revendre.
- On s'assure que les emails dans les demandes de petits cours sont valides.
### BDS
- Le buro peut exporter la liste de membres avec email au format CSV depuis la page d'acceuil.
### K-Fêt
- On affiche les articles actuellement en vente en premier lors des inventaires

View file

@ -7,7 +7,7 @@
<section class="section">
<div class="box">
<div class="content has-text-centered">
<h1>{{ member_count }}</h1>
<h1>{{ member_count }}</h1>
adhérent·e·s
</div>
</div>
@ -34,6 +34,11 @@
<br>
<br>
<a class=button href="{% url 'export.members' %}">Télécharger la liste des membres (CSV)</a>
<br>
<br>
Le site est encore en développement.
<br>
Suivez notre avancement sur
@ -52,4 +57,4 @@
{% endblock layout %}

View file

@ -14,4 +14,5 @@ urlpatterns = [
name="user.create.fromclipper",
),
path("user/delete/<int:pk>", views.UserDeleteView.as_view(), name="user.delete"),
path("members", views.export_members, name="export.members"),
]

View file

@ -1,5 +1,9 @@
import csv
from django.contrib import messages
from django.contrib.auth import get_user_model
from django.contrib.auth.decorators import permission_required
from django.http import HttpResponse
from django.shortcuts import get_object_or_404
from django.urls import reverse, reverse_lazy
from django.utils.translation import gettext_lazy as _
@ -128,3 +132,21 @@ class UserDeleteView(StaffRequiredMixin, DeleteView):
messages.success(request, self.success_message)
return super().delete(request, *args, **kwargs)
@permission_required("bds.is_team")
def export_members(request):
response = HttpResponse(content_type="text/csv")
response["Content-Disposition"] = "attachment; filename=membres_bds.csv"
writer = csv.writer(response)
for profile in BDSProfile.objects.filter(is_member=True).all():
user = profile.user
bits = [
user.username,
user.get_full_name(),
user.email,
]
writer.writerow([str(bit) for bit in bits])
return response