Skip to content

Commit

Permalink
Added csv option
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamín Mravec committed Nov 10, 2023
1 parent 1f13567 commit 2f4e40d
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions competition/views.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import os
import zipfile
import csv
from io import BytesIO
from operator import itemgetter

from django.core.files import File
from django.core.mail import send_mail
from django.http import FileResponse, HttpResponse
from django.template.loader import render_to_string
from django.views.generic import View
from rest_framework import exceptions, mixins, status, viewsets
from rest_framework.decorators import action
from rest_framework.exceptions import ValidationError
Expand Down Expand Up @@ -688,6 +690,21 @@ def participants(self, request, pk=None):

profiles = Profile.objects.only("user").filter(pk__in=participants_id)
serializer = ProfileExportSerializer(profiles, many=True)

#if request == 'csv':

response = HttpResponse(content_type='text/csv')
response['Content-Disposition'] = 'attachment; filename="export.csv"'

header = ProfileExportSerializer.Meta.fields

writer = csv.DictWriter(response, fieldnames=header)
writer.writeheader()
for row in serializer.data:
writer.writerow(row)

return response

return Response(serializer.data)

def post(self, request, format_post):
Expand Down

0 comments on commit 2f4e40d

Please sign in to comment.