diff options
-rw-r--r-- | nccps2018/settings.py | 10 | ||||
-rw-r--r-- | website/admin.py | 27 |
2 files changed, 32 insertions, 5 deletions
diff --git a/nccps2018/settings.py b/nccps2018/settings.py index db36bd8..d2731b4 100644 --- a/nccps2018/settings.py +++ b/nccps2018/settings.py @@ -81,10 +81,10 @@ WSGI_APPLICATION = 'nccps2018.wsgi.application' DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', - 'NAME': DB_NAME_DEFAULT, # Or path to database file if using sqlite3. - 'USER': DB_USER_DEFAULT, - 'PASSWORD': DB_PASS_DEFAULT, - 'HOST': DB_HOST_DEFAULT, +- 'NAME': DB_NAME_DEFAULT, # Or path to database file if using sqlite3. +- 'USER': DB_USER_DEFAULT, +- 'PASSWORD': DB_PASS_DEFAULT, +- 'HOST': DB_HOST_DEFAULT, } } @@ -113,7 +113,7 @@ AUTH_PASSWORD_VALIDATORS = [ LANGUAGE_CODE = 'en-us' -TIME_ZONE = 'UTC' +TIME_ZONE = 'Asia/Kolkata' USE_I18N = True 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. |