Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
ARFA
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
ARFA
ARFA
Commits
49184b4b
Commit
49184b4b
authored
Nov 07, 2018
by
SANCHIT JAIN
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of
https://git.cse.iitb.ac.in/ARFA/ARFA
parents
a0335296
16fb181d
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
241 additions
and
59 deletions
+241
-59
ARFA/ARFA_app/forms.py
ARFA/ARFA_app/forms.py
+12
-9
ARFA/ARFA_app/models.py
ARFA/ARFA_app/models.py
+7
-0
ARFA/ARFA_app/templates/ARFA_app/create_Test.html
ARFA/ARFA_app/templates/ARFA_app/create_Test.html
+46
-0
ARFA/ARFA_app/templates/ARFA_app/home.html
ARFA/ARFA_app/templates/ARFA_app/home.html
+6
-6
ARFA/ARFA_app/templates/ARFA_app/view_all_question.html
ARFA/ARFA_app/templates/ARFA_app/view_all_question.html
+1
-1
ARFA/ARFA_app/utilities.py
ARFA/ARFA_app/utilities.py
+112
-0
ARFA/ARFA_app/views.py
ARFA/ARFA_app/views.py
+57
-43
No files found.
ARFA/ARFA_app/forms.py
View file @
49184b4b
...
@@ -5,15 +5,18 @@ from .models import *
...
@@ -5,15 +5,18 @@ from .models import *
class
QuestionForm
(
forms
.
ModelForm
):
#
class QuestionForm(forms.ModelForm):
class
m
eta
:
# class M
eta:
model
=
Question
#
model = Question
fields
=
(
'question_text'
,)
#
fields = ('question_text',)
class
OptionsForm
(
forms
.
ModelForm
):
#
class OptionsForm(forms.ModelForm):
class
m
eta
:
# class M
eta:
model
=
Options
#
model = Options
fields
=
(
'option_value'
,)
#
fields = ('option_value',)
class
class
TestForm
(
forms
.
ModelForm
):
\ No newline at end of file
class
Meta
:
model
=
Test
exclude
=
[
'test_ID'
,
'ownsership'
]
\ No newline at end of file
ARFA/ARFA_app/models.py
View file @
49184b4b
...
@@ -33,6 +33,13 @@ class Test(models.Model):
...
@@ -33,6 +33,13 @@ class Test(models.Model):
start_time
=
models
.
DateTimeField
(
auto_now
=
False
,
auto_now_add
=
False
)
start_time
=
models
.
DateTimeField
(
auto_now
=
False
,
auto_now_add
=
False
)
max_marks
=
models
.
FloatField
(
null
=
True
)
max_marks
=
models
.
FloatField
(
null
=
True
)
# class TestQuestions(models.Model):
# test_ID = models.ForeignKey(
# 'Test', on_delete=models.CASCADE)
# q_ID = models.ForeignKey(
# 'Question', on_delete=models.CASCADE)
class
Subject
(
models
.
Model
):
class
Subject
(
models
.
Model
):
subject_ID
=
models
.
CharField
(
max_length
=
20
,
primary_key
=
True
)
subject_ID
=
models
.
CharField
(
max_length
=
20
,
primary_key
=
True
)
subject
=
models
.
CharField
(
max_length
=
20
)
subject
=
models
.
CharField
(
max_length
=
20
)
...
...
ARFA/ARFA_app/templates/ARFA_app/create_Test.html
View file @
49184b4b
...
@@ -9,4 +9,50 @@ Create Test
...
@@ -9,4 +9,50 @@ Create Test
{%block body%}
{%block body%}
<h1>
You CAN CREATE A Test HERE prof {{username}}
</h1>
<h1>
You CAN CREATE A Test HERE prof {{username}}
</h1>
<link
rel=
"stylesheet"
href=
"//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.min.css"
>
<div
class=
"container"
>
<div
class=
"panel-default"
>
<div
class=
"panel-heading"
>
<h3
class=
"panel-title"
>
Choose which questions are to be a part of the test
</h3>
</div>
<ul
class=
"list-group"
>
<!-- <ul> -->
<form
method=
"POST"
action=
"create_Test"
>
{% csrf_token %}
{{ TestForm }}
{%for question in questions%}
<li
class=
"list-group-item"
>
<!-- <li> -->
<div
class=
"row toggle"
>
<div
class=
"col-xs-10"
>
<input
type=
"checkbox"
value=
"True"
name =
"{{question.q_id}}"
>
{{question.question_text}} {{question.q_id}}
</br>
</div>
</div>
<div>
<hr></hr>
<ul>
{%for option in question.option_details%}
<li>
{{option.is_answer}}
{{option.option_text}}
</li>
<!-- marks -->
{%endfor%}
<label>
marks
<input
type=
"number"
name=
"{{question.q_id}}"
min=
"0"
max=
"10"
placeholder=
"4"
step=
"0.25"
value=
"4"
>
<input
type=
"number"
name=
"{{question.q_id}}"
min=
"-10"
max=
"0"
placeholder=
"-1"
step=
"0.25"
value=
"0"
>
</label>
</ul>
</div>
</li>
{%endfor%}
<button
type=
"submit"
class=
"btn btn-login float-right"
>
Submit
</button>
</form>
</ul>
</div>
</div>
{%endblock%}
{%endblock%}
\ No newline at end of file
ARFA/ARFA_app/templates/ARFA_app/home.html
View file @
49184b4b
...
@@ -5,9 +5,9 @@ profile
...
@@ -5,9 +5,9 @@ profile
{%endblock%}
{%endblock%}
{%block head%}
{%block head%}
<link
href=
"//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css"
rel=
"stylesheet"
id=
"bootstrap-css"
>
<
!-- <
link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css">
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/js/bootstrap.min.js"></script>
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/js/bootstrap.min.js"></script>
<script
src=
"//code.jquery.com/jquery-1.11.1.min.js"
></script>
<script src="//code.jquery.com/jquery-1.11.1.min.js"></script>
-->
{% load static %}
{% load static %}
<link
rel=
"stylesheet"
href=
"{% static 'ARFA_app/home.css' %}"
type=
"text/css"
>
<link
rel=
"stylesheet"
href=
"{% static 'ARFA_app/home.css' %}"
type=
"text/css"
>
...
@@ -48,7 +48,7 @@ profile
...
@@ -48,7 +48,7 @@ profile
{%endblock%}
{%endblock%}
{%block body%}
{%block body%}
<
link
href=
"http://fontawesome.io/assets/font-awesome/css/font-awesome.css"
rel=
"stylesheet"
media=
"screen"
>
<
!-- <link href="http://fontawesome.io/assets/font-awesome/css/font-awesome.css" rel="stylesheet" media="screen"> -->
<div
class=
"container"
>
<div
class=
"container"
>
<div
class=
"row user-menu-container square"
>
<div
class=
"row user-menu-container square"
>
<div
class=
"col-md-7 user-details"
>
<div
class=
"col-md-7 user-details"
>
...
@@ -224,7 +224,7 @@ profile
...
@@ -224,7 +224,7 @@ profile
<p id = "demo">
<p id = "demo">
</p>
</p>
<!--
<button type="button" class="btn btn-login float-right" onclick="loadTest()">Load Test</button> -->
<button type="button" class="btn btn-login float-right" onclick="loadTest()">Load Test</button> -->
<form
action=
"testHome"
method=
'POST'
>
<form
action=
"testHome"
method=
'POST'
>
{% csrf_token %}
{% csrf_token %}
...
@@ -241,13 +241,13 @@ profile
...
@@ -241,13 +241,13 @@ profile
{% for question, options in data.questions.items %}
{% for question, options in data.questions.items %}
<li
style=
"font-weight: bold;"
>
Question : {{ question }}
</li>
<li
style=
"font-weight: bold;"
>
Question : {{ question }}
</li>
{% for option in options %}
{% for option in options %}
<input
type=
"checkbox"
value=
"{{option.1}}"
name =
"{{option.0
}}"
>
{{ option.2 }}
</br>
<input
type=
"checkbox"
name =
"{{option.0}}"
value=
"{{option.1
}}"
>
{{ option.2 }}
</br>
{% endfor %}
{% endfor %}
{% endfor %}
{% endfor %}
<button
type=
"submit"
class=
"btn btn-login float-right"
>
Submit
</button>
<button
type=
"submit"
class=
"btn btn-login float-right"
>
Submit
</button>
</form>
</form>
</ol>
{%endblock%}
{%endblock%}
ARFA/ARFA_app/templates/ARFA_app/view_all_question.html
View file @
49184b4b
...
@@ -4,7 +4,7 @@
...
@@ -4,7 +4,7 @@
View personal Question
View personal Question
{%endblock%}
{%endblock%}
{%block body%}
{%block body%}
<h1>
You CAN VIEW
personal
QUESTION HERE prof {{username}}
</h1>
<h1>
You CAN VIEW
all questions
QUESTION HERE prof {{username}}
</h1>
<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"
>
...
...
ARFA/ARFA_app/
engine
.py
→
ARFA/ARFA_app/
utilities
.py
View file @
49184b4b
from
.models
import
*
from
__future__
import
unicode_literals
from
django.db
import
IntegrityError
from
django.http
import
HttpResponse
from
django.shortcuts
import
render
,
redirect
from
.
import
models
from
.models
import
Responses
from
.models
import
Test
from
.models
import
Question
from
.models
import
Options
from
.models
import
Student
from
django.contrib.auth.decorators
import
login_required
from
django.http
import
HttpResponse
from
django.views.decorators.cache
import
cache_control
import
json
from
django.db
import
connection
from
django.db
import
IntegrityError
def
evaluate
(
responses
,
otherData
):
def
evaluate
(
responses
,
otherData
):
#create evaluation object
#create evaluation object
...
@@ -52,3 +66,47 @@ def evaluate(responses, otherData):
...
@@ -52,3 +66,47 @@ def evaluate(responses, otherData):
print
"Integrity error - evaluation not recorded"
print
"Integrity error - evaluation not recorded"
pass
pass
def
getOptions
(
question
):
#returns queryset
return
models
.
Options
.
objects
.
get
(
q_ID
=
question
)
def
get_all_questions
(
request
):
args
=
{
'username'
:
request
.
session
[
'username'
]}
# args = {'username':'mathura'}
cursor
=
connection
.
cursor
()
cursor
.
execute
(
''' SELECT s.subject,q."q_ID" as q_ID,q.question_text,q.topic,q.subtopic,q.source,
q.difficulty_set,q.image_link,q.visibility,q.ownership,o."option_Value" as option_details,
o."is_Answer"
FROM "ARFA_app_question" as q,
"ARFA_app_options" as o,"ARFA_app_subject" as s
WHERE ( q.faculty_id =
%
s or q.visibility='public' ) and s."subject_ID" = q."subject_ID_id" and q."q_ID" = o."q_ID_id"
order by s.subject,q_ID '''
,[
args
[
'username'
]])
rows
=
cursor
.
fetchall
()
# print(len(rows))
columns
=
[
col
[
0
]
for
col
in
cursor
.
description
]
res
=
[]
options_so_far
=
[]
preval
=
[]
first
=
True
for
val
in
rows
:
if
(
first
==
True
):
first
=
False
preval
=
list
(
val
[:
-
1
])
options_so_far
=
[{
"option_text"
:
val
[
-
2
],
"is_answer"
:
val
[
-
1
]}]
else
:
if
not
(
preval
[
0
]
==
val
[
0
]
and
preval
[
1
]
==
val
[
1
]):
preval
[
-
1
]
=
options_so_far
# preval[1] = "q"+str(preval[1])
t
=
dict
(
zip
(
columns
[:
-
1
],
preval
))
res
.
append
(
t
)
options_so_far
=
[{
"option_text"
:
val
[
-
2
],
"is_answer"
:
val
[
-
1
]}]
preval
=
list
(
val
[:
-
1
])
else
:
options_so_far
.
append
({
"option_text"
:
val
[
-
2
],
"is_answer"
:
val
[
-
1
]})
if
not
(
first
):
preval
[
-
1
]
=
options_so_far
# preval[1] = "q"+str(preval[1])
t
=
dict
(
zip
(
columns
[:
-
1
],
preval
))
res
.
append
(
t
)
return
res
\ No newline at end of file
ARFA/ARFA_app/views.py
View file @
49184b4b
...
@@ -9,8 +9,9 @@ from .models import Test
...
@@ -9,8 +9,9 @@ from .models import Test
from
.models
import
Question
from
.models
import
Question
from
.models
import
Options
from
.models
import
Options
from
.models
import
Student
from
.models
import
Student
from
.
import
engine
from
.
import
utilities
from
.engine
import
evaluate
from
.utilities
import
evaluate
from
.
import
forms
from
django.contrib.auth.decorators
import
login_required
from
django.contrib.auth.decorators
import
login_required
from
django.http
import
HttpResponse
from
django.http
import
HttpResponse
...
@@ -227,7 +228,7 @@ def result(request):
...
@@ -227,7 +228,7 @@ def result(request):
responses
.
append
({
int
(
q
):
data
[
q
]})
responses
.
append
({
int
(
q
):
data
[
q
]})
#call evaluate function
#call evaluate function
engine
.
evaluate
(
responses
,
utilities
.
evaluate
(
responses
,
{
'username'
:
request
.
session
[
'username'
],
'testID'
:
responseObj
.
test_ID_id
})
{
'username'
:
request
.
session
[
'username'
],
'testID'
:
responseObj
.
test_ID_id
})
return
HttpResponse
(
"Result page should be here"
)
return
HttpResponse
(
"Result page should be here"
)
...
@@ -295,44 +296,7 @@ def view_all_question(request):
...
@@ -295,44 +296,7 @@ def view_all_question(request):
if
(
request
.
session
.
get
(
'role'
,
None
)
!=
"faculty"
):
if
(
request
.
session
.
get
(
'role'
,
None
)
!=
"faculty"
):
return
render
(
request
,
'ARFA_app/not_a_faculty.html'
)
return
render
(
request
,
'ARFA_app/not_a_faculty.html'
)
args
=
{
'username'
:
request
.
session
[
'username'
]}
res
=
utilities
.
get_all_questions
(
request
)
# args = {'username':'mathura'}
cursor
=
connection
.
cursor
()
cursor
.
execute
(
''' SELECT s.subject,q."q_ID" as q_ID,q.question_text,q.topic,q.subtopic,q.source,
q.difficulty_set,q.image_link,q.visibility,q.ownership,o."option_Value" as option_details,
o."is_Answer"
FROM "ARFA_app_question" as q,
"ARFA_app_options" as o,"ARFA_app_subject" as s
WHERE ( q.faculty_id =
%
s or q.visibility='public' ) and s."subject_ID" = q."subject_ID_id" and q."q_ID" = o."q_ID_id"
order by s.subject,q_ID '''
,[
args
[
'username'
]])
rows
=
cursor
.
fetchall
()
# print(len(rows))
columns
=
[
col
[
0
]
for
col
in
cursor
.
description
]
res
=
[]
options_so_far
=
[]
preval
=
[]
first
=
True
for
val
in
rows
:
if
(
first
==
True
):
first
=
False
preval
=
list
(
val
[:
-
1
])
options_so_far
=
[{
"option_text"
:
val
[
-
2
],
"is_answer"
:
val
[
-
1
]}]
else
:
if
not
(
preval
[
0
]
==
val
[
0
]
and
preval
[
1
]
==
val
[
1
]):
preval
[
-
1
]
=
options_so_far
preval
[
1
]
=
"q"
+
str
(
preval
[
1
])
t
=
dict
(
zip
(
columns
[:
-
1
],
preval
))
res
.
append
(
t
)
options_so_far
=
[{
"option_text"
:
val
[
-
2
],
"is_answer"
:
val
[
-
1
]}]
preval
=
list
(
val
[:
-
1
])
else
:
options_so_far
.
append
({
"option_text"
:
val
[
-
2
],
"is_answer"
:
val
[
-
1
]})
if
not
(
first
):
preval
[
-
1
]
=
options_so_far
preval
[
1
]
=
"q"
+
str
(
preval
[
1
])
t
=
dict
(
zip
(
columns
[:
-
1
],
preval
))
res
.
append
(
t
)
args
=
{
'username'
:
request
.
session
[
'username'
],
'questions'
:
res
}
args
=
{
'username'
:
request
.
session
[
'username'
],
'questions'
:
res
}
args
.
update
(
request
.
session
.
get
(
'args'
,
None
))
args
.
update
(
request
.
session
.
get
(
'args'
,
None
))
...
@@ -340,8 +304,58 @@ def view_all_question(request):
...
@@ -340,8 +304,58 @@ def view_all_question(request):
def
create_Test
(
request
):
def
create_Test
(
request
):
args
=
{
'username'
:
request
.
session
[
'username'
]}
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
TestForm
=
forms
.
TestForm
()
args
=
{
'username'
:
request
.
session
[
'username'
],
'questions'
:
res
,
'TestForm'
:
TestForm
}
if
request
.
method
==
"GET"
:
print
res
return
render
(
request
,
'ARFA_app/create_Test.html'
,
args
)
return
render
(
request
,
'ARFA_app/create_Test.html'
,
args
)
if
request
.
method
==
"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
()
# 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
)
for
q
in
data
.
keys
():
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
()
except
ValueError
as
e
:
data
.
pop
(
q
)
continue
# for q in data:
print
data
def
view_personal_Test
(
request
):
def
view_personal_Test
(
request
):
args
=
{
'username'
:
request
.
session
[
'username'
]}
args
=
{
'username'
:
request
.
session
[
'username'
]}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment