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
8bd93373
Commit
8bd93373
authored
Nov 26, 2018
by
NARRA SURAJ
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ranking done
parent
6d27c864
Changes
7
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
409 additions
and
13 deletions
+409
-13
ARFA/ARFA_app/forms.py
ARFA/ARFA_app/forms.py
+11
-3
ARFA/ARFA_app/migrations/0001_initial.py
ARFA/ARFA_app/migrations/0001_initial.py
+244
-0
ARFA/ARFA_app/migrations/__init__.py
ARFA/ARFA_app/migrations/__init__.py
+0
-0
ARFA/ARFA_app/tasks.py
ARFA/ARFA_app/tasks.py
+37
-0
ARFA/ARFA_app/templates/ARFA_app/studentTestHome.html
ARFA/ARFA_app/templates/ARFA_app/studentTestHome.html
+1
-1
ARFA/ARFA_app/urls.py
ARFA/ARFA_app/urls.py
+1
-1
ARFA/ARFA_app/views.py
ARFA/ARFA_app/views.py
+115
-8
No files found.
ARFA/ARFA_app/forms.py
View file @
8bd93373
...
...
@@ -30,10 +30,18 @@ VISIBILITY_CHOICES= ('1980', '1981', '1982')
class
TestForm
(
forms
.
ModelForm
):
# start_time = forms.DateTimeField(input_formats=['%Y-%m-%dT%H:%M'])
# expected_time_for_completion = forms.DurationField(input_formats=['%HH:%M'])
class
Meta
:
model
=
Test
widgets
=
{
'expected_time_for_completion'
:
forms
.
TimeInput
(
attrs
=
{
'type'
:
'time'
}),
'start_time'
:
forms
.
DateInput
(
attrs
=
{
'type'
:
'datetime-local'
}),
#
'expected_time_for_completion': forms.TimeInput(attrs={'type':'time'}),
#
'start_time': forms.DateInput(attrs={'type':'datetime-local'}),
}
exclude
=
[
'test_ID'
,
'ownership'
]
\ No newline at end of file
exclude
=
[
'test_ID'
,
'ownership'
]
# def clean_start_time(self):
# dt = self.cleaned_data['start_time']
# print dt
# return dt['start_time'][0].replace('T', ' ') #remove the 'T' in HTML returned string
\ No newline at end of file
ARFA/ARFA_app/migrations/0001_initial.py
0 → 100644
View file @
8bd93373
This diff is collapsed.
Click to expand it.
ARFA/ARFA_app/migrations/__init__.py
0 → 100644
View file @
8bd93373
ARFA/ARFA_app/tasks.py
0 → 100644
View file @
8bd93373
from
background_task
import
background
from
django.contrib.auth.models
import
User
from
.
import
models
from
django.db.models
import
F
#https://django-background-tasks.readthedocs.io/en/latest/#creating-and-registering-tasks
@
background
(
schedule
=
60
)
def
testRanks
(
test_ID
):
#get all Takes objects with this test_ID
print
"testRanks called !
\n\n\n\n\n\n
"
takesObjects
=
models
.
Takes
.
objects
.
filter
(
test_ID
=
test_ID
)
.
order_by
(
F
(
'total_marks'
)
.
desc
())
num
=
len
(
takesObjects
)
i
=
0
oldMarks
=
-
10000
for
t
in
takesObjects
:
if
t
.
total_marks
!=
oldMarks
:
i
=
i
+
1
oldMarks
=
t
.
total_marks
t
.
rank
=
i
print
t
.
student_id
print
t
.
rank
try
:
print
"saving"
t
.
save
()
except
:
print
"some error"
# try:
# takesObjects.update()
# except:
# print "some error"
@
background
(
schedule
=
60
)
def
testTask
():
print
"test task"
\ No newline at end of file
ARFA/ARFA_app/templates/ARFA_app/studentTestHome.html
View file @
8bd93373
...
...
@@ -21,7 +21,7 @@ My Tests
<p>
{{t.test_name}}
</p>
</div>
<div
style=
"float:right"
>
<form
method=
"POST"
action=
"
arfa/
loadStudentTest"
>
<form
method=
"POST"
action=
"loadStudentTest"
>
{% csrf_token %}
<input
name=
"testID"
value=
"{{t.test_ID}}"
type=
"hidden"
>
<button
>
Load Test
</button>
...
...
ARFA/ARFA_app/urls.py
View file @
8bd93373
...
...
@@ -26,6 +26,6 @@ urlpatterns=[
url
(
r'^register'
,
views
.
register
),
url
(
r'^reg'
,
views
.
reg
),
url
(
r'^studentTestHome'
,
views
.
studentTestHome
),
url
(
r'^loadStudentTest'
,
views
.
loadStudentTest
)
url
(
r'^loadStudentTest'
,
views
.
loadStudentTest
)
,
]
ARFA/ARFA_app/views.py
View file @
8bd93373
...
...
@@ -14,6 +14,8 @@ from .models import Evaluation
from
.
import
utilities
from
.utilities
import
evaluate
from
.
import
forms
from
.
import
tasks
from
django.http
import
QueryDict
from
django.contrib.auth.decorators
import
login_required
from
django.http
import
HttpResponse
...
...
@@ -241,6 +243,10 @@ def studentTestHome(request):
data
[
'practiceTests'
]
=
[]
for
t
in
practiceTests
:
# debug
# print t.test_ID
# print datetime.datetime.now() - t.start_time - t.expected_time_for_completion
# debug
data
[
'practiceTests'
]
.
append
({
'test_ID'
:
t
.
test_ID
,
'test_name'
:
t
.
test_name
,
'marks'
:
t
.
max_marks
,
'start_time'
:
t
.
start_time
})
print
data
...
...
@@ -363,7 +369,7 @@ def view_personal_question(request):
if
(
request
.
session
.
get
(
'role'
,
None
)
!=
"faculty"
):
return
render
(
request
,
'ARFA_app/not_a_faculty.html'
,
request
.
session
.
get
(
'args'
,
None
))
args
=
{
'username'
:
request
.
session
[
'username'
]}
args
=
{
'username'
:
request
.
session
[
'username'
]
,
'is_session'
:
True
}
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,
...
...
@@ -419,6 +425,75 @@ def view_all_question(request):
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
):
if
(
request
.
session
.
get
(
'session'
,
None
)
!=
True
):
return
render
(
request
,
'ARFA_app/login.html'
)
...
...
@@ -434,12 +509,33 @@ def create_Test(request):
if
request
.
method
==
"GET"
:
return
render
(
request
,
'ARFA_app/create_Test.html'
,
args
)
if
request
.
method
==
"POST"
:
form
=
TestForm
(
request
.
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
)
print
data
# """dirty workaround"""
# #the data in request.POST must be modified to be valid in the form
# data['start_time'] = data['start_time'][0].replace('T', ' ') #remove the 'T' in HTML returned string
# data['expected_time_for_completion'] = data['expected_time_for_completion'][0]+":00"
# #add seconds to duration string
# data['max_marks'] = int(data['max_marks'][0]) #convert max_marks from string to int
# #if these are not in these exact formats everything may break.
# #see form cleanup for a potentially better solution
# qdict = QueryDict("", mutable=True)
# qdict.update(data)
form
=
forms
.
TestForm
(
request
.
POST
)
# form2 = forms.TestForm(request.POST)
# print "form2:"
# print vars(form2)
# print "\n\n\n"
print
"start time"
print
form
print
vars
(
form
)
if
form
.
is_valid
():
test
=
form
.
save
()
...
...
@@ -482,12 +578,23 @@ def create_Test(request):
print
e
continue
return
render
(
request
,
'ARFA_app/view_personal_Test.html'
,
args
)
#schedule ranking function when test is finished
print
type
(
test
.
start_time
)
print
type
(
test
.
expected_time_for_completion
)
tasks
.
testRanks
(
test
.
test_ID
,
schedule
=
(
test
.
start_time
+
test
.
expected_time_for_completion
))
print
test
.
start_time
+
test
.
expected_time_for_completion
print
"testRanks being called
\n\n\n\n
"
return
view_personal_Test
(
request
)
def
view_all_Test
(
request
):
args
=
{
'username'
:
request
.
session
[
'username'
]}
return
render
(
request
,
'ARFA_app/view_all_Test.html'
,
args
)
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'
,
request
.
session
.
get
(
'args'
,
None
))
if
request
.
method
==
'POST'
:
args
=
{
'username'
:
request
.
session
[
'username'
],
'is_session'
:
True
}
return
render
(
request
,
'ARFA_app/view_all_Test.html'
,
args
)
...
...
@@ -548,7 +655,7 @@ def view_personal_Test(request):
res
=
[]
for
val
in
rows
:
res
.
append
(
dict
(
zip
(
columns
,
val
)))
args
=
{
'username'
:
request
.
session
[
'username'
],
'tests'
:
res
}
args
=
{
'username'
:
request
.
session
[
'username'
],
'tests'
:
res
,
'is_session'
:
True
}
return
render
(
request
,
'ARFA_app/view_personal_Test.html'
,
args
)
...
...
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