-
Notifications
You must be signed in to change notification settings - Fork 25
Add downlad attendee-csv-file EventViewSet #3811
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 | ||
|
|
@@ -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") | ||
| response["Content-Disposition"] = ( | ||
| f'attachment; filename="{event.title.replace(" ", "_") + "_attendees"}.csv"' | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you change this to |
||
| ) | ||
|
|
||
| writer = csv.writer(response) | ||
| writer.writerow(["full_name", "username", "email", "phone", "grade"]) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
|
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you remove these two |
||
| class PoolViewSet( | ||
| mixins.CreateModelMixin, | ||
| mixins.UpdateModelMixin, | ||
|
|
||
There was a problem hiding this comment.
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?