summaryrefslogtreecommitdiff
path: root/website
diff options
context:
space:
mode:
Diffstat (limited to 'website')
-rw-r--r--website/admin.py10
-rwxr-xr-xwebsite/forms.py5
-rw-r--r--website/migrations/0005_uploadmodel.py22
-rw-r--r--website/models.py14
-rw-r--r--website/urls.py1
-rw-r--r--website/views.py98
6 files changed, 126 insertions, 24 deletions
diff --git a/website/admin.py b/website/admin.py
index c6a7d78..7a6ba2e 100644
--- a/website/admin.py
+++ b/website/admin.py
@@ -3,7 +3,8 @@ import csv
from django.http import HttpResponse
from .models import( Profile,
AnswerPaper,
- Question
+ Question,
+ UploadModel
)
try:
@@ -45,7 +46,12 @@ class AnswerPaperAdmin(admin.ModelAdmin):
+class UploadModelAdmin(admin.ModelAdmin):
+ list_display = ['question']
+
+
# Register your models here.
admin.site.register(Profile, ProfileAdmin)
admin.site.register(AnswerPaper, AnswerPaperAdmin)
-admin.site.register(Question, QuestionAdmin) \ No newline at end of file
+admin.site.register(Question, QuestionAdmin)
+admin.site.register(UploadModel, UploadModelAdmin) \ No newline at end of file
diff --git a/website/forms.py b/website/forms.py
index 5b094e7..9df1fcb 100755
--- a/website/forms.py
+++ b/website/forms.py
@@ -1,7 +1,7 @@
from django import forms
from django.forms import ModelForm, widgets
-
+import datetime
from django.contrib.auth.forms import UserCreationForm
from django.contrib.auth.models import User
from django.core.validators import MinLengthValidator, MinValueValidator, \
@@ -396,4 +396,5 @@ class QuestionUploadForm(forms.ModelForm):
widgets = {
'question_day': DateInput(),
- } \ No newline at end of file
+ }
+
diff --git a/website/migrations/0005_uploadmodel.py b/website/migrations/0005_uploadmodel.py
new file mode 100644
index 0000000..a357f95
--- /dev/null
+++ b/website/migrations/0005_uploadmodel.py
@@ -0,0 +1,22 @@
+# Generated by Django 2.1 on 2018-10-31 05:40
+
+from django.db import migrations, models
+import django.db.models.deletion
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('website', '0004_auto_20181012_0951'),
+ ]
+
+ operations = [
+ migrations.CreateModel(
+ name='UploadModel',
+ fields=[
+ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+ ('model_file', models.FileField(upload_to='uploads/')),
+ ('question', models.ForeignKey(blank=True, on_delete=django.db.models.deletion.CASCADE, to='website.Question')),
+ ],
+ ),
+ ]
diff --git a/website/models.py b/website/models.py
index 2481177..ad6b3e4 100644
--- a/website/models.py
+++ b/website/models.py
@@ -34,7 +34,7 @@ def get_document_dir(instance, filename):
fname, fext = os.path.splitext(filename)
# print "----------------->",instance.user
return '%s/attachment/%s/%s.%s' % (instance.user, instance.proposal_type, fname+'_'+str(instance.user), fext)
-
+
class Proposal(models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE,)
@@ -117,10 +117,20 @@ class Question(models.Model):
# The date for the question.
question_day = models.DateField()
+ def __str__(self):
+ return u"{0} || {1}".format(self.correct_answer, self.question_day)
+
class AnswerPaper(models.Model):
participant = models.ForeignKey(Profile, on_delete=models.CASCADE)
answered_q = models.ForeignKey(Question, on_delete=models.CASCADE)
validate_ans = models.BooleanField()
- date = models.DateTimeField(auto_now=True) \ No newline at end of file
+ date = models.DateTimeField(auto_now=True)
+
+
+#To upload model for each question
+
+class UploadModel(models.Model):
+ question = models.ForeignKey(Question, on_delete=models.CASCADE, blank=True)
+ model_file = models.FileField(upload_to='uploads/')
diff --git a/website/urls.py b/website/urls.py
index a6aabe3..841f338 100644
--- a/website/urls.py
+++ b/website/urls.py
@@ -21,6 +21,7 @@ urlpatterns = [
re_path(r'^cfp/$', views.cfp, name='cfp'),
#re_path(r'^quiz/$', views.quiz_view, name='quiz_view'),
re_path(r'^question_list/$', views.question_list, name='question_list'),
+ re_path(r'^view_solutions/$', views.view_solutions, name='view_solutions'),
re_path(r'^add_questions/$', views.add_questions, name='add_questions'),
re_path(r'^edit_question/(?P<qid>\d+)$', views.edit_question, name='edit_question'),
re_path(r'^take_quiz/$', views.take_quiz, name='take_quiz'),
diff --git a/website/views.py b/website/views.py
index 4a52495..5aee28e 100644
--- a/website/views.py
+++ b/website/views.py
@@ -1,6 +1,6 @@
# Create your views here.
-from django.http import HttpResponse
+from django.http import HttpResponse, JsonResponse
from django.shortcuts import render
from django.shortcuts import render_to_response, render, redirect
from django.template import loader
@@ -13,21 +13,27 @@ from django.views.decorators.csrf import (csrf_exempt, csrf_protect,
from django.contrib.auth.decorators import login_required
from django.contrib.auth.models import User
from website.models import (Proposal, Comments, Ratings, Question,
- AnswerPaper, Profile)
+ AnswerPaper, Profile, UploadModel)
from website.forms import (ProposalForm, UserRegisterForm, UserRegistrationForm,
- UserLoginForm, WorkshopForm,QuestionUploadForm) # ,ContactForm
+ UserLoginForm, WorkshopForm,QuestionUploadForm
+ )# ,ContactForm
from website.models import Proposal, Comments, Ratings
from social.apps.django_app.default.models import UserSocialAuth
from django.contrib.auth import authenticate, login, logout
-from datetime import datetime
+from datetime import datetime, date
from django import template
from django.core.mail import EmailMultiAlternatives
-import os
+import os, re
from nccps2018.config import *
from website.send_mails import send_email
from django.contrib.auth.models import Group
from django.contrib import messages
+from zipfile import ZipFile
+try:
+ from StringIO import StringIO as string_io
+except ImportError:
+ from io import BytesIO as string_io
@@ -1094,6 +1100,30 @@ def edit_question(request, qid=None):
def quiz_intro(request):
return render(request, 'quiz_intro.html')
+
+def calculate_leader():
+ profiles = Profile.objects.all()
+ leaderboard = {p:0 for p in profiles}
+ marks = {
+ '5': [date(2018, 10, 29), date(2018, 11, 4)],
+ '10': [date(2018, 11, 5), date(2018, 11, 12)]
+ }
+ answers = AnswerPaper.objects.all()
+
+ for i in leaderboard:
+ profiles = AnswerPaper.objects.filter(participant=i)
+ for p in profiles:
+ if p.validate_ans==1:
+ if marks['5'][0] <= p.answered_q.question_day <= marks['5'][1]:
+ leaderboard[i] +=5
+ else:
+ leaderboard[i] +=1
+
+
+ sorted_leaderboard = sorted(leaderboard.items(), key=lambda kv: kv[1])
+ return sorted_leaderboard
+
+
@login_required
def take_quiz(request):
user = request.user
@@ -1162,24 +1192,56 @@ def take_quiz(request):
except:
pass
+ today = datetime.today().date()
+ if today > date(2018, 11, 4):
+ set_visible = 0
+ else:
+ set_visible = 1
+ sorted_leaderboard = calculate_leader()
+
return render(request, 'take_quiz.html', {
- 'question_list' : questions
+ 'question_list' : questions,
+ 'set_visible': set_visible,
+ "leaderboard": sorted_leaderboard[::-1]
})
-def leaderboard(request):
- profiles = Profile.objects.all()
- leaderboard = {p:0 for p in profiles}
+def leaderboard(request):
+ sorted_leaderboard = calculate_leader()
+ return render(request, "leaderboard.html", {'leaderboard': sorted_leaderboard[::-1]})
- answers = AnswerPaper.objects.all()
- for i in leaderboard:
- profile_data = AnswerPaper.objects.filter(participant=i)
- for pro in profile_data:
- if pro.validate_ans==1:
- leaderboard[i] +=1
-
- sorted_leaderboard = sorted(leaderboard.items(), key=lambda kv: kv[1])
- return render(request, "leaderboard.html", {'leaderboard': sorted_leaderboard[::-1]})
+@login_required
+def view_solutions(request,id=None):
+ ''''Show solutions to participants after a specific date'''
+ question_ans_list = Question.objects.all()
+ today = datetime.today().date()
+ if today < date(2018, 11, 15):
+ set_visible = 0
+ else:
+ set_visible = 1
+ if request.method == 'POST':
+ filename = UploadModel.objects.all()
+ attachment_path = os.path.dirname(filename[0].model_file.path)
+ zipfile_name = string_io()
+ zipfile = ZipFile(zipfile_name, "w")
+ attachments = os.listdir(attachment_path)
+ for file in attachments:
+ file_path = os.sep.join((attachment_path, file))
+ zipfile.write(file_path, os.path.basename(file_path))
+ zipfile.close()
+ zipfile_name.seek(0)
+ response = HttpResponse(content_type='application/zip')
+ response['Content-Disposition'] = 'attachment; filename={0}.zip'.format(
+ "Solutions"
+ )
+ response.write(zipfile_name.read())
+ return response
+
+
+ return render(request, 'view_solutions.html', {"question_ans_list": question_ans_list,
+ "set_visible": set_visible
+ })
+ \ No newline at end of file