diff options
Diffstat (limited to 'website/views.py')
-rw-r--r-- | website/views.py | 153 |
1 files changed, 86 insertions, 67 deletions
diff --git a/website/views.py b/website/views.py index a330387..e40661a 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 @@ -57,7 +62,12 @@ def dwsimquiz(request): context = {} template = loader.get_template('dwsim-quiz.html') return HttpResponse(template.render(context, request)) - + +def jobfair(request): + context = {} + template = loader.get_template('job-fair.html') + return HttpResponse(template.render(context, request)) + # def proposal(request): # context = {} # template = loader.get_template('proposal.html') @@ -739,17 +749,13 @@ def status_change(request): Pardon the unsolicited advice but it is important that you plan your presentations carefully. 15 minutes is a good amount of time to communicate your central idea. Most really good TED talks finish in 15 minutes. Keep your talk focussed and please do rehearse your talk and slides to make sure it flows well. If you need help with this, the program chairs can try to help you by giving you some early feedback on your slides. Just upload your slides before 26th on the same submission interface and we will go over it once. For anything submitted after 26th we may not have time to comment on but will try to give you feedback. Please also keep handy a PDF version of your talk in case your own laptops have a problem. Please confirm your participation. The schedule will be put up online by end of day. We look forward to hearing your talk. \n\nYou will be notified regarding instructions of your talk via email.\n\nThank You ! \n\nRegards,\nNCCPS 2018,\nFOSSEE - IIT Bombay""" - elif proposal.proposal_type == 'WORKSHOP': - subject = "NCCPS 2018 - Workshop Proposal Accepted" - message = """Dear """+proposal.user.first_name+""", - Thank you for your excellent submissions! We are pleased to accept your workshop. Due to the large number of submissions, we have decided to accept 8 workshops and give all the selected workshops 2 hours each. Please plan for 1 hour and 55 minutes in order to give the participants a 10 minute break between workshops for tea. - -The tentative schedule will be put up on the website shortly. Please confirm your participation and do provide detailed instructions for the participants (and the organizers if they need to do something for you) by replying to this email. These instructions will be made available on the conference website. Installation is often a problem, so please make sure your instructions are simple and easy to follow. If you wish, we could allow some time on the previous day for installation help. Let us know about this. Also, do not waste too much time on installation during your workshop. - -We strongly suggest that you try to plan your workshops carefully and focus on doing things hands-on and not do excessive amounts of theory. Try to give your participants a decent overview so they can pick up additional details on their own. It helps to pick one or two overarching problems you plan to solve and work your way through the solution of those. -\n\nThank You ! \n\nRegards,\nNCCPS 2018,\nFOSSEE - IIT Bombay""" - #send_mail(subject, message, sender_email, to) - # context.update(csrf(request)) + #email = EmailMultiAlternatives( + # subject, '', + # sender_email, to, + # headers={"Content-type": "text/html;charset=iso-8859-1"} + #) + #email.attach_alternative(message, "text/html") + #email.send(fail_silently=True) proposals = Proposal.objects.all() context['proposals'] = proposals context['user'] = user @@ -1089,6 +1095,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 @@ -1157,67 +1187,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} - 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 - elif marks['10'][0] <= p.answered_q.question_day <= marks['10'][1]: - leaderboard[i] +=10 - else: - leaderboard[i] +=1 - - sorted_leaderboard = sorted(leaderboard.items(), key=lambda kv: kv[1]) +def leaderboard(request): + sorted_leaderboard = calculate_leader() 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 |