Commit edc4a72b authored by Rahul-chunduru's avatar Rahul-chunduru

ui for images in questions

parent 0a4a3412
This diff is collapsed.
...@@ -16,6 +16,12 @@ Total Time :<b > {{total_time.hours}} {{total_time.minutes}} </b> ...@@ -16,6 +16,12 @@ Total Time :<b > {{total_time.hours}} {{total_time.minutes}} </b>
<h2 align="center" style=" text-decoration: underline;"><b> {{testName.test_name}} </b> </h2> <h2 align="center" style=" text-decoration: underline;"><b> {{testName.test_name}} </b> </h2>
</div> </div>
<script> <script>
function submitExam()
{
document.getElementById('ExamForm').submit() ;
}
</script>
<script>
// Set the date we're counting down to // Set the date we're counting down to
var countDownDate = new Date( {{ end_time }} ); var countDownDate = new Date( {{ end_time }} );
...@@ -51,19 +57,37 @@ var x = setInterval(function() { ...@@ -51,19 +57,37 @@ var x = setInterval(function() {
<div style="margin-left: 5%; margin-top: 10%"> <div style="margin-left: 5%; margin-top: 10%">
<ol> <ol>
<font size="3"> <font size="3">
<form class="exam-form" method="POST" action="/arfa/result"> <form class="exam-form" method="POST" action="/arfa/result" id="ExamForm">
<p style="margin-right: 5%"> <b> Questions </b></p> <p style="margin-right: 5%"> <b> Questions </b></p>
{% csrf_token %} {% csrf_token %}
<input name="testID" value="{{testID}}" type="hidden" > <input name="testID" value="{{testID}}" type="hidden" >
{% for question, options in questions.items %} {{images}}
{% for question, data in questions.items %}
<div class="row" style="margin-top: 10px; margin-bottom: 10px"> <div class="row" style="margin-top: 10px; margin-bottom: 10px">
<li style="font-weight: bold;" > {{ question }}</li> <li style="font-weight: bold;margin-left: 10px; margin-bottom: 10px" > {{ question }}<br></li>
{% for option in options %}
<!-- adding an image -->
{% for image in data.images %}
{%load static%}
{%if image.0 %}
<div align="center" style="margin-top:30px">
<img src = "{% static "" %}{{ image.0 }}" width="35%" height="35%" >
<p style="margin-top:5px">{{image.1}}</p>
{%endif%}
</div>
{% endfor %}
{% for option in data.options %}
<input type="checkbox" name = "{{option.0}}" value= "{{option.1}}" > {{ option.2 }} </br> <input type="checkbox" name = "{{option.0}}" value= "{{option.1}}" > {{ option.2 }} </br>
{% endfor %} {% endfor %}
</div> </div>
{% endfor %} {% endfor %}
<button type="submit" class="btn btn-login" style="float: right;">Submit</button> <button onclick="submitExam()" class="btn btn-login" style="float: right;">Submit</button>
</form> </form>
</font> </font>
......
...@@ -34,7 +34,9 @@ View all Question ...@@ -34,7 +34,9 @@ View all Question
</li> </li>
{%else%} {%else%}
<li> <li>
<p>
{{option.option_text}} {{option.option_text}}
</p>
</li> </li>
{%endif%} {%endif%}
{%endfor%} {%endfor%}
......
...@@ -4,7 +4,12 @@ ...@@ -4,7 +4,12 @@
View personal Question View personal Question
{%endblock%} {%endblock%}
{%block body%} {%block body%}
<h1> You CAN VIEW personal QUESTION HERE prof {{username}}</h1> <style>
p {
font-size: 130%
}
</style>
<h2 align="center"> You CAN VIEW personal QUESTIONS HERE prof {{username}}</h2>
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.min.css"> <link rel="stylesheet" href="//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.min.css">
<div class="container"> <div class="container">
<div class="panel-default"> <div class="panel-default">
...@@ -18,7 +23,17 @@ View personal Question ...@@ -18,7 +23,17 @@ View personal Question
<!-- <li> --> <!-- <li> -->
<div class="row toggle"> <div class="row toggle">
<div class="col-xs-10"> <div class="col-xs-10">
{{question.question_text}} <p> <b> Question. </b> {{question.question_text}} </p>
{%if question.ip%}
{%load static%}
<div align="center">
<img src = "{% static "" %}{{question.ip|slice:"16:" }}" width="35%" height="35%">
<p style="margin-top:5px">
{{question.imdesc}}
</p>
</div>
{%endif%}
</div> </div>
</div> </div>
<div> <div>
...@@ -31,7 +46,9 @@ View personal Question ...@@ -31,7 +46,9 @@ View personal Question
</li> </li>
{%else%} {%else%}
<li> <li>
<p>
{{option.option_text}} {{option.option_text}}
</p>
</li> </li>
{%endif%} {%endif%}
{%endfor%} {%endfor%}
......
...@@ -265,13 +265,16 @@ def loadStudentTest(request): ...@@ -265,13 +265,16 @@ def loadStudentTest(request):
args = {} args = {}
args['username'] = request.session['username'] args['username'] = request.session['username']
args['is_session'] = True args['is_session'] = True
test_ID = request.POST['testID']
taken_res=models.Takes.objects.filter(student__username = args['username'], test_ID__test_ID= test_ID)
if taken_res:
return redirect('/arfa')
test_ID = request.POST['testID']
testName = Test.objects.values('test_name').get(pk=test_ID) testName = Test.objects.values('test_name').get(pk=test_ID)
st = Test.objects.values('start_time').get(pk=test_ID) st = Test.objects.values('start_time').get(pk=test_ID)
start_time = st['start_time'] start_time = st['start_time']
# start_time = start_time + datetime.timedelta(hours=5,minutes=30)
M = Test.objects.values('max_marks').get(pk=test_ID) M = Test.objects.values('max_marks').get(pk=test_ID)
total_time = Test.objects.values('expected_time_for_completion').get(pk=test_ID) total_time = Test.objects.values('expected_time_for_completion').get(pk=test_ID)
end_time = start_time + total_time['expected_time_for_completion'] end_time = start_time + total_time['expected_time_for_completion']
...@@ -279,20 +282,32 @@ def loadStudentTest(request): ...@@ -279,20 +282,32 @@ def loadStudentTest(request):
secs = (total_time['expected_time_for_completion'].seconds) secs = (total_time['expected_time_for_completion'].seconds)
hours = secs // 3600 hours = secs // 3600
minute = (secs % 3600) // 60 minute = (secs % 3600) // 60
questions = Contains.objects.filter(test_ID=test_ID).values('q_ID') questions = Contains.objects.filter(test_ID=test_ID).values('q_ID')
options = models.Options.objects.select_related('q_ID').filter(q_ID__in = questions) options = models.Options.objects.select_related('q_ID').filter(q_ID__in = questions)
print test_ID images = models.QuestionImage.objects.select_related('q_ID').filter(q_ID__in = questions)
print questions.all()
questionsJSON = {} questionsJSON = {}
for option in options: for option in options:
if option.q_ID.question_text in questionsJSON: if option.q_ID.question_text in questionsJSON:
questionsJSON[option.q_ID.question_text].append( questionsJSON[option.q_ID.question_text]['options'].append(
[option.q_ID.q_ID, option.pk, option.option_Value]) [option.q_ID.q_ID, option.pk, option.option_Value])
else: else:
questionsJSON[option.q_ID.question_text] = [[option.q_ID.q_ID, questionsJSON[option.q_ID.question_text] = {}
questionsJSON[option.q_ID.question_text]['options'] = [[option.q_ID.q_ID,
option.pk, option.option_Value]] option.pk, option.option_Value]]
# print option.option_Value
# print option.q_ID.q_ID # imageJSON = {}
for image in images:
if (image.q_ID.question_text in questionsJSON) and \
('images' in questionsJSON[image.q_ID.question_text]):
questionsJSON[option.q_ID.question_text]['images'].append(
[str(image.image)[16:],image.imageDesc])
else:
questionsJSON[option.q_ID.question_text] = {}
questionsJSON[option.q_ID.question_text]['images'] = [[str(image.image)[16:],
image.imageDesc]]
args['questions'] = questionsJSON args['questions'] = questionsJSON
args['testName'] = testName args['testName'] = testName
args['testID'] = test_ID args['testID'] = test_ID
...@@ -381,9 +396,11 @@ def view_personal_question(request): ...@@ -381,9 +396,11 @@ def view_personal_question(request):
args={'username':request.session['username'], 'is_session':True} args={'username':request.session['username'], 'is_session':True}
cursor = connection.cursor() cursor = connection.cursor()
cursor.execute(''' SELECT s.subject,q."q_ID" as q_ID,q.question_text,q.topic,q.subtopic,q.source, cursor.execute(''' SELECT s.subject,q."q_ID" as q_ID,q.question_text,q.topic,q.subtopic,q.source,
q.difficulty_set,q.visibility,q.ownership,o."option_Value" as option_details, q.difficulty_set,q.visibility,q.ownership,q.image as ip , q."imageDesc" as imdesc,
o."option_Value" as option_details,
o."is_Answer" o."is_Answer"
FROM "ARFA_app_question" as q, FROM ("ARFA_app_question" as u LEFT OUTER JOIN "ARFA_app_questionimage" as v ON
u."q_ID" = v."q_ID_id") as q,
"ARFA_app_options" as o,"ARFA_app_subject" as s "ARFA_app_options" as o,"ARFA_app_subject" as s
WHERE q.faculty_id = %s and s."subject_ID" = q."subject_ID_id" and q."q_ID" = o."q_ID_id" WHERE q.faculty_id = %s and s."subject_ID" = q."subject_ID_id" and q."q_ID" = o."q_ID_id"
order by s.subject,q_ID ''',[args['username']]) order by s.subject,q_ID ''',[args['username']])
...@@ -433,75 +450,6 @@ def view_all_question(request): ...@@ -433,75 +450,6 @@ def view_all_question(request):
args.update(request.session.get('args',None)) args.update(request.session.get('args',None))
return render(request,'ARFA_app/view_all_question.html',args) return render(request,'ARFA_app/view_all_question.html',args)
# def create_Test(request):
# if(request.session.get('session',None)!=True):
# return render(request,'ARFA_app/login.html')
# if(request.session.get('role',None)!="faculty"):
# return render(request,'ARFA_app/not_a_faculty.html')
# res = utilities.get_all_questions(request)
# test = None
# 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)
# print vars(form)
# #TODO: validation - starttime < now
# if form.is_valid():
# test = form.save()
# creator = models.Created_BY(test_ID=test,faculty=models.Faculty.objects.filter(username=request.session['username']).get())
# creator.save()
# else:
# 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
# containsObj = models.Contains(test_ID=test)
# # print data
# for q in data.keys():
# if len(data[q]) != 3:
# continue
# try:
# int(q)
# containsObj.q_ID_id = q
# #data[q] is an array ['True', 'pos_marks', 'neg_marks']
# containsObj.marks_pos = data[q][1]
# containsObj.marks_neg = data[q][2]
# containsObj.pk = None
# containsObj.save()
# print "success"
# print containsObj
# except ValueError as e:
# data.pop(q)
# print e
# continue
# #schedule ranking function when test is finished
# tasks.testRanks(test.test_ID, test.start_time+test.expected_time_for_completion)
# return render(request,'ARFA_app/view_personal_Test.html',args)
def create_Test(request): def create_Test(request):
if(request.session.get('session',None)!=True): if(request.session.get('session',None)!=True):
return render(request,'ARFA_app/login.html') return render(request,'ARFA_app/login.html')
......
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