gestioCOF/events/views.py

26 lines
877 B
Python
Raw Normal View History

2019-10-05 15:58:11 +02:00
import csv
from django.contrib.auth.decorators import login_required, permission_required
from django.http import HttpResponse
from django.shortcuts import get_object_or_404
from django.utils.text import slugify
2019-10-08 23:33:46 +02:00
2019-10-05 15:58:11 +02:00
from events.models import Event
@login_required
2019-10-05 16:55:05 +02:00
@permission_required("events.view_event", raise_exception=True)
2019-10-05 15:58:11 +02:00
def participants_csv(request, event_id):
event = get_object_or_404(Event, id=event_id)
filename = "{}-participants.csv".format(slugify(event.title))
response = HttpResponse(content_type="text/csv")
response["Content-Disposition"] = 'attachment; filename="{}"'.format(filename)
writer = csv.writer(response)
writer.writerow(["username", "email", "prénom", "nom de famille"])
for user in event.subscribers.all():
writer.writerow([user.username, user.email, user.first_name, user.last_name])
return response