Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 29 additions & 3 deletions lego/apps/events/views.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import csv

from django.db import transaction
from django.db.models import Count, Prefetch, Q
from django.http import Http404
from django.http import Http404, HttpResponse
from django.shortcuts import get_object_or_404
from django.utils import timezone
from django_filters.rest_framework import DjangoFilterBackend
Expand Down Expand Up @@ -203,6 +205,30 @@ def perform_update(self, serializer):
"""
serializer.save(is_ready=False)

@decorators.action(detail=True, methods=["GET"])
def csv(self, *args, **kwargs):
event = Event.objects.get(pk=kwargs["pk"])
response = HttpResponse(content_type="text/csv")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe use Response instead like other places in our codebase for consistency?

response["Content-Disposition"] = (
f'attachment; filename="{event.title.replace(" ", "_") + "_attendees"}.csv"'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you change this to filename="{event.title.replace(" ", "_") }_attendees.csv"

)

writer = csv.writer(response)
writer.writerow(["full_name", "username", "email", "phone", "grade"])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not phone_number here?

for pool in event.pools.all():
for participant in pool.registrations.all():
writer.writerow(
[
participant.user.get_full_name(),
participant.user.username,
participant.user.email,
participant.user.phone_number,
participant.user.grade,
]
)

return response

@decorators.action(detail=True, methods=["GET"])
def administrate(self, request, *args, **kwargs):
event_id = self.kwargs.get("pk", None)
Expand Down Expand Up @@ -334,8 +360,8 @@ def cover_image_gallery(self, request):
)
serializer = self.get_serializer(queryset, many=True)
return Response(serializer.data)


Comment on lines +363 to +364
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you remove these two

class PoolViewSet(
mixins.CreateModelMixin,
mixins.UpdateModelMixin,
Expand Down