Added bds/members to export members list as CSV

This commit is contained in:
Dorian Lesbre 2021-01-21 20:32:36 +01:00
parent 33319cfe76
commit 830aba984e
2 changed files with 23 additions and 0 deletions

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