Commit 8d3997dd authored by SANCHIT JAIN's avatar SANCHIT JAIN

Merge branch 'master' of https://git.cse.iitb.ac.in/ARFA/ARFA

parents a7b025db 912e9e7e
{
"python.pythonPath": "/usr/bin/python",
"python.linting.pylintEnabled": true,
"python.linting.pylamaEnabled": false,
"python.linting.enabled": true,
"python.jediEnabled": false
}
\ No newline at end of file
python3
\ No newline at end of file
/usr/bin/python3
\ No newline at end of file
# -*- coding: utf-8 -*-
# Generated by Django 1.11.16 on 2018-11-06 21:27
# Generated by Django 1.11.16 on 2018-11-24 13:16
from __future__ import unicode_literals
import django.core.validators
......
......@@ -21,6 +21,8 @@ Create Test
<form method="POST" action="create_Test">
{% csrf_token %}
{{ TestForm }}
{{TestForm.errors}}
{{TestForm.non_field_errors}}
{%for question in questions%}
<li class="list-group-item">
<!-- <li> -->
......
......@@ -40,11 +40,11 @@ profile
});
</script>
<script type='text/javascript'>
<!-- <script type='text/javascript'>
function preventBack(){window.history.forward();}
setTimeout("preventBack()",0);
window.onunload =function(){null};
</script>
</script> -->
{%endblock%}
{%block body%}
......
......@@ -46,11 +46,11 @@ profile
});
</script>
<script type='text/javascript'>
<!-- <script type='text/javascript'>
function preventBack(){window.history.forward();}
setTimeout("preventBack()",0);
window.onunload =function(){null};
</script>
</script> -->
{%endblock%}
{%block body%}
......@@ -197,13 +197,13 @@ profile
</h2>
<center><i class="fa fa-cloud-upload fa-4x"></i></center>
<div class="share-links">
<a href="/arfa/view_my_tests">
<a href="/arfa/studentTestHome">
<center><button type="button" class="btn btn-lg btn-labeled btn-success" href="#" style="margin-bottom: 15px;">
<span class="btn-label"><i class="fa fa-bell-o"></i></span> Take a test
<span class="btn-label"><i class="fa fa-bell-o"></i></span>Take Test
</button></center>
</a>
</a>
<center><button type="button" class="btn btn-lg btn-labeled btn-warning" href="#">
<span class="btn-label"><i class="fa fa-bell-o"></i></span> View previous tests
<span class="btn-label"><i class="fa fa-bell-o"></i></span>Resume Test
</button></center>
</div>
</div>
......
{%extends 'base2.html'%}
{%block head%}
{%endblock%}
{%block title%}
My Tests
{%endblock%}
{%block body%}
<h1>Currently Active Tests </h1>
<div class="container">
<div class="panel-default">
<div class="panel-heading">
<h3 class="panel-title">Active Tests</h3>
</div>
<ul class="list-group">
{% for t in activeTests %}
<div>
<p>{{t.test_ID}}</p>
<p>{{t.test_name}}</p>
</div>
<div style="float:right">
<form method="POST" action="loadStudentTest">
<input name="testID" value="{{t.test_ID}}" type="hidden">
<button>Load Test</button>
</form>
</div>
{% endfor %}
</ul>
</div>
</div>
</div>
{% if practiceTests %}
<div class="container">
<div class="panel-default">
<div class="panel-heading">
<h3 class="panel-title">Practice Tests</h3>
</div>
<ul class="list-group">
{% for t in practiceTests %}
<div>
<p>{{t.test_ID}}</p>
<p>{{t.test_name}}</p>
</div>
<div style="float:right">
<form method="POST" action="loadStudentTest">
<input name="testID" value="{{t.test_ID}}" type="hidden">
<button>Load Test</button>
</form>
</div>
{% endfor %}
</ul>
</div>
</div>
</div>
{% endif %}
{%endblock%}
\ No newline at end of file
......@@ -25,6 +25,6 @@ urlpatterns=[
url(r'^add_question',views.add_question),
url(r'^register',views.register),
url(r'^reg',views.reg),
url(r'^studentTestHome', views.studentTestHome)
]
......@@ -19,7 +19,9 @@ from django.views.decorators.cache import cache_control
import json
from django.db import connection
from django.db import IntegrityError
from django.db.models import F
from .forms import TestForm
import datetime
def login(request):
print("session currently is "+str(request.session.get('session',None)))
......@@ -145,10 +147,39 @@ def logout(request):
request.session.flush()
return render(request,'ARFA_app/logout.html')
def testHome(request):
# if request.method == 'GET':
def studentTestHome(request):
if(request.session.get('session',None)!=True):
return render(request,'ARFA_app/login.html')
if(request.session.get('role',None)!="student"):
return HttpResponse("Not a student")
now = datetime.datetime.now()
activeTests = Test.objects.filter(start_time__gte = now - F('expected_time_for_completion'),
start_time__lte = now)
practiceTests = Test.objects.filter(start_time__lte = now - F('expected_time_for_completion'))
data = {}
data['username'] = request.session['username']
data['is_session'] = True
data['activeTests'] = []
for t in activeTests:
data['activeTests'].append({'test_ID':t.test_ID, 'test_name':t.test_name,
'marks':t.max_marks, 'start_time':t.start_time})
data['practiceTests'] = []
for t in practiceTests:
data['practiceTests'].append({'test_ID':t.test_ID, 'test_name':t.test_name,
'marks':t.max_marks, 'start_time':t.start_time})
print data
return render(request, 'ARFA_app/studentTestHome.html', data)
def loadStudentTest(request):
if request.method == 'POST':
test_ID = request.POST['test_ID']
def testHome(request):
# if request.method == 'GET':
allOptions = models.Options.objects.select_related('q_ID').all()
json = {'testID':'3'}
......@@ -280,22 +311,44 @@ def create_Test(request):
res = utilities.get_all_questions(request)
test = None
TestForm = forms.TestForm()
args={'username':request.session['username'],'questions':res, 'TestForm':TestForm}
form = forms.TestForm()
args={'username':request.session['username'],'questions':res, 'TestForm':TestForm,
'is_session':True}
if request.method == "GET":
return render(request,'ARFA_app/create_Test.html',args)
if request.method == "POST":
form = TestForm(request.POST)
data = dict(request.POST.copy()) #copy to make QueryDict mutable. HttpResponse is immutable
data.pop('csrfmiddlewaretoken')
if not data: #only csrf token was sent, display create test page
return render(request,'ARFA_app/create_Test.html',args)
if TestForm.is_valid():
test = TestForm.save()
if form.is_valid():
test = form.save()
else:
print form
if form.errors:
for field in form :
print field.errors
return HttpResponse("Test Form Invalid")
for attr in dir(Test):
print attr
try:
data.pop(attr)
except KeyError as e:
pass
#data is being sent
#create test object
# test = Test()
containsObj = models.Contains(test_ID=test)
print data
for q in data.keys():
if len(data[q]) != 3:
continue
try:
if q[0] != 'i':
continue ;
......@@ -310,7 +363,11 @@ def create_Test(request):
except ValueError as e:
data.pop(q)
continue
return render(request,'ARFA_app/view_personal_Test.html',args)
# for q in data:
return view_personal_Test(request)
def view_personal_Test(request):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment