Events: simple csv participants export
This commit is contained in:
parent
41a3c4c161
commit
33bc3c5882
3 changed files with 41 additions and 0 deletions
|
@ -123,6 +123,12 @@ urlpatterns = [
|
||||||
path("config", gestioncof_views.ConfigUpdate.as_view(), name="config.edit"),
|
path("config", gestioncof_views.ConfigUpdate.as_view(), name="config.edit"),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
if "events" in settings.INSTALLED_APPS:
|
||||||
|
# The new event application is still in development
|
||||||
|
# → for now it is namespaced below events_v2
|
||||||
|
# → when the old events system is out, move this above in the others apps
|
||||||
|
urlpatterns += [path("event_v2/", include("events.urls"))]
|
||||||
|
|
||||||
if "debug_toolbar" in settings.INSTALLED_APPS:
|
if "debug_toolbar" in settings.INSTALLED_APPS:
|
||||||
import debug_toolbar
|
import debug_toolbar
|
||||||
|
|
||||||
|
|
11
events/urls.py
Normal file
11
events/urls.py
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
from django.urls import path
|
||||||
|
from events import views
|
||||||
|
|
||||||
|
app_name = "events"
|
||||||
|
urlpatterns = [
|
||||||
|
path(
|
||||||
|
"csv/participants/<int:event_id>",
|
||||||
|
views.participants_csv,
|
||||||
|
name="csv-participants",
|
||||||
|
)
|
||||||
|
]
|
|
@ -0,0 +1,24 @@
|
||||||
|
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
|
||||||
|
from events.models import Event
|
||||||
|
|
||||||
|
|
||||||
|
@login_required
|
||||||
|
@permission_required("events.view_event")
|
||||||
|
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
|
Loading…
Reference in a new issue