summaryrefslogtreecommitdiff
path: root/website/admin.py
diff options
context:
space:
mode:
authorAkshen2018-10-22 17:09:41 +0530
committerAkshen2018-10-22 17:09:41 +0530
commitb4f391712577268f9183983461bc183801a150c5 (patch)
treeb4ed5c26795aa3c2c688fc3664fdd589123ccdb4 /website/admin.py
parent0c8f9e7f672755127a0c396448118dff22aac7e5 (diff)
downloadnccps-2018-b4f391712577268f9183983461bc183801a150c5.tar.gz
nccps-2018-b4f391712577268f9183983461bc183801a150c5.tar.bz2
nccps-2018-b4f391712577268f9183983461bc183801a150c5.zip
Download AnswerPaper data via Admin Panel
Diffstat (limited to 'website/admin.py')
-rw-r--r--website/admin.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/website/admin.py b/website/admin.py
index e244083..c6a7d78 100644
--- a/website/admin.py
+++ b/website/admin.py
@@ -1,9 +1,16 @@
from django.contrib import admin
+import csv
+from django.http import HttpResponse
from .models import( Profile,
AnswerPaper,
Question
)
+try:
+ from StringIO import StringIO as string_io
+except ImportError:
+ from io import BytesIO as string_io
+
class ProfileAdmin(admin.ModelAdmin):
list_display = ['title','user', 'institute',
@@ -14,8 +21,28 @@ class QuestionAdmin(admin.ModelAdmin):
list_display = ['question', 'correct_answer', 'question_day']
+
class AnswerPaperAdmin(admin.ModelAdmin):
list_display = ['participant', 'answered_q', 'date']
+ actions = ['download_csv']
+
+ def download_csv(self, request, queryset):
+ openfile = string_io()
+ response = HttpResponse(content_type='text/csv')
+ response['Content-Disposition'] = 'attachment;\
+ filename=AnswerPaper_data.csv'
+
+ writer = csv.writer(response)
+ writer.writerow(['Participant', 'Answer date/time'])
+ for q in queryset:
+ writer.writerow([q.participant.user.get_full_name(), q.date])
+
+ openfile.seek(0)
+ response.write(openfile.read())
+ return response
+
+ download_csv.short_description = "Download CSV file for selected stats."
+
# Register your models here.