diff options
author | Akshen | 2018-10-31 11:13:21 +0530 |
---|---|---|
committer | Akshen | 2018-10-31 11:13:21 +0530 |
commit | 529c9b63bfe2ee7d6fe1667bf5c09a0b23ac374f (patch) | |
tree | 87f5099735d814f89831d91b606f038e02468471 | |
parent | 7d171e9b3dfdf6119f719ae7283add795bd1ec6c (diff) | |
download | nccps-2018-529c9b63bfe2ee7d6fe1667bf5c09a0b23ac374f.tar.gz nccps-2018-529c9b63bfe2ee7d6fe1667bf5c09a0b23ac374f.tar.bz2 nccps-2018-529c9b63bfe2ee7d6fe1667bf5c09a0b23ac374f.zip |
Allow participants to view and download solutions
- view correct answers
- download all dwsim files
- remove 10 marks week
-rwxr-xr-x | .gitignore | 3 | ||||
-rw-r--r-- | nccps2018/settings.py | 10 | ||||
-rw-r--r-- | static/website/templates/navbar.html | 1 | ||||
-rw-r--r-- | static/website/templates/question_list.html | 1 | ||||
-rw-r--r-- | static/website/templates/view_solutions.html | 40 | ||||
-rw-r--r-- | website/admin.py | 10 | ||||
-rwxr-xr-x | website/forms.py | 8 | ||||
-rw-r--r-- | website/migrations/0005_uploadmodel.py | 22 | ||||
-rw-r--r-- | website/models.py | 14 | ||||
-rw-r--r-- | website/urls.py | 2 | ||||
-rw-r--r-- | website/views.py | 70 |
11 files changed, 123 insertions, 58 deletions
@@ -24,3 +24,6 @@ db.sqlite3 #VScode .vscode/ + +# +uploads/ diff --git a/nccps2018/settings.py b/nccps2018/settings.py index 9ce4c32..a17836f 100644 --- a/nccps2018/settings.py +++ b/nccps2018/settings.py @@ -80,11 +80,11 @@ 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, + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), + 'TEST': { + 'NAME': 'mytestdatebase', + }, } } diff --git a/static/website/templates/navbar.html b/static/website/templates/navbar.html index d820d5d..a196b05 100644 --- a/static/website/templates/navbar.html +++ b/static/website/templates/navbar.html @@ -54,6 +54,7 @@ {% else %} <!--<li><a href="{% url 'website:proposal' %}">Submit your Paper</a></li> --> <li><a href="{% url 'website:quiz_intro' %}">Take Quiz</a></li> + <li><a href="{% url 'website:view_solutions' %}">View Solutions</a></li> {% endif %} <!-- <li><a href="{{SITE_URL}}/#registration">Book your Ticket</a></li> --> <li><a href="{% url 'auth:logout' %}?next=/nccps-2018"><i class="fa fa-sign-out"></i> Logout</a></li> diff --git a/static/website/templates/question_list.html b/static/website/templates/question_list.html index cc11098..65b571a 100644 --- a/static/website/templates/question_list.html +++ b/static/website/templates/question_list.html @@ -13,7 +13,6 @@ <br> <a href="{% url 'website:add_questions' %}" ><button class="btn-default btn-warning"> Add Question </button></a> <a href="{% url 'website:leaderboard' %}" ><button class="btn-default btn-info"> LeaderBoard </button></a> - <br><br> </div> diff --git a/static/website/templates/view_solutions.html b/static/website/templates/view_solutions.html new file mode 100644 index 0000000..2074dcb --- /dev/null +++ b/static/website/templates/view_solutions.html @@ -0,0 +1,40 @@ +{% extends "base.html" %} + +{% load static %} + {% block content %} + <br><br> + <br><br> + + <div class="container"> + {% if set_visible %} + <form method="POST"> + {% csrf_token %} + <button class="btn-default btn-info btn-lg" name="Download">Download Model Files</button> + </form> + <br><br> + + <table style="width:100%" class="table table-hover"> + <thead> + <tr> + <th>Question</th> + <th>Answer</th> + </tr> + </thead> + {% for q in question_ans_list %} + <tbody> + <tr> + <td>{{ q.question }} </td> + <td>{{ q.correct_answer }} </td> + </tr> + </tbody> + {% endfor %} + </table> + + {% else %} + <div class="jumbotron"> + <p>This page will be visible from <strong>15-11-2018</strong></p> + </div> + {% endif %} +</div> + +{% endblock %}
\ No newline at end of file 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 bee9ba9..9df1fcb 100755 --- a/website/forms.py +++ b/website/forms.py @@ -398,11 +398,3 @@ class QuestionUploadForm(forms.ModelForm): 'question_day': DateInput(), } - -#To upload model for each question -''' -class UploadModelForm(forms.ModelForm): - class Meta: - model = UploadModel - fields = ['model_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 e482453..ad6b3e4 100644 --- a/website/models.py +++ b/website/models.py @@ -36,10 +36,6 @@ def get_document_dir(instance, filename): return '%s/attachment/%s/%s.%s' % (instance.user, instance.proposal_type, fname+'_'+str(instance.user), fext) -def attachments(instance, filename): - return os.sep.join((instance.workshoptype_name.replace(" ", '_'), filename)) - - class Proposal(models.Model): user = models.ForeignKey(User, on_delete=models.CASCADE,) name_of_authors = models.CharField(max_length=200, default='None') @@ -121,6 +117,9 @@ 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): @@ -131,8 +130,7 @@ class AnswerPaper(models.Model): #To upload model for each question -''' + class UploadModel(models.Model): - question = models.ForeignKey(Question, on_delete=models.CASCADE, blank=True, null=True) - model_file = models.FileField(upload_to=attachments) -'''
\ No newline at end of file + 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 f0dbe60..3190ec0 100644 --- a/website/urls.py +++ b/website/urls.py @@ -20,7 +20,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'^uploadmodel/$', views.uploadmodel, name='uploadmodel'), + 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 a330387..3c4f737 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,7 +13,7 @@ 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 @@ -24,11 +24,16 @@ from django.contrib.auth import authenticate, login, logout 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 @@ -1177,8 +1182,6 @@ def leaderboard(request): if p.validate_ans==1: if marks['5'][0] <= p.answered_q.question_day <= marks['5'][1]: leaderboard[i] +=5 - elif marks['10'][0] <= p.answered_q.question_day <= marks['10'][1]: - leaderboard[i] +=10 else: leaderboard[i] +=1 @@ -1187,37 +1190,38 @@ def leaderboard(request): return render(request, "leaderboard.html", {'leaderboard': sorted_leaderboard[::-1]}) -''' @login_required -def uploadmodel(request): +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': - data = request.body.decode("utf-8").split('&') - date = data[1].replace("qdate=", "") - date = datetime.strptime(date, "%Y-%m-%d").date() - question_list = Question.objects.all() - try: - question_obj = Question.objects.get(question_day=date) - print(question_obj) - messages.info(request, 'Uploaded Successfully!') - except: - messages.error(request, 'No question uploaded for mentioned date') + 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 - form = UploadModelForm(request.POST) - if form.is_valid(): - uploadForm = form.save(commit=False) - try: - question_obj = Question.objects.get(question_day=date) - uploadForm.question = question_obj - uploadForm.model_file - uploadForm.save() - messages.info(request, 'Uploaded Successfully!') - except: - messages.error(request, 'No question uploaded for mentioned date') - print(question_obj) - else: - messages.error(request, 'Invalid Form') - - return render(request, "uploadmodel.html", {"question_list":question_list})''' + return render(request, 'view_solutions.html', {"question_ans_list": question_ans_list, + "set_visible": set_visible + })
\ No newline at end of file |