diff options
Diffstat (limited to 'website')
-rwxr-xr-x | website/forms.py | 13 | ||||
-rw-r--r-- | website/models.py | 16 | ||||
-rw-r--r-- | website/urls.py | 1 | ||||
-rw-r--r-- | website/views.py | 59 |
4 files changed, 77 insertions, 12 deletions
diff --git a/website/forms.py b/website/forms.py index 5b094e7..bee9ba9 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,13 @@ class QuestionUploadForm(forms.ModelForm): widgets = { 'question_day': DateInput(), - }
\ No newline at end of file + } + + +#To upload model for each question +''' +class UploadModelForm(forms.ModelForm): + class Meta: + model = UploadModel + fields = ['model_file'] +''' diff --git a/website/models.py b/website/models.py index 2481177..e482453 100644 --- a/website/models.py +++ b/website/models.py @@ -34,7 +34,11 @@ 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) - + + +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,) @@ -123,4 +127,12 @@ 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, null=True) + model_file = models.FileField(upload_to=attachments) +'''
\ No newline at end of file diff --git a/website/urls.py b/website/urls.py index 7cf47c5..f0dbe60 100644 --- a/website/urls.py +++ b/website/urls.py @@ -20,6 +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'^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 35686e7..7effb8b 100644 --- a/website/views.py +++ b/website/views.py @@ -16,11 +16,12 @@ from website.models import (Proposal, Comments, Ratings, Question, AnswerPaper, Profile) 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 @@ -1163,17 +1164,59 @@ def take_quiz(request): 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: - profile_data = AnswerPaper.objects.filter(participant=i) - for pro in profile_data: - if pro.validate_ans==1: - leaderboard[i] +=1 + 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['5'][0] <= p.answered_q.question_day <= marks['5'][1]: + leaderboard[i] +=10 + else: + 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 uploadmodel(request): + 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') + + ''' + 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}) +
\ No newline at end of file |