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
c30f50dc
Commit
c30f50dc
authored
Nov 06, 2018
by
SANCHIT JAIN
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
"create_question done by majestic rahul"
parent
4788f7a7
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
272 additions
and
114 deletions
+272
-114
ARFA/ARFA_app/templates/ARFA_app/create_question.html
ARFA/ARFA_app/templates/ARFA_app/create_question.html
+242
-62
ARFA/ARFA_app/templates/ARFA_app/not_a_faculty.html
ARFA/ARFA_app/templates/ARFA_app/not_a_faculty.html
+1
-10
ARFA/ARFA_app/templates/ARFA_app/view_all_question.html
ARFA/ARFA_app/templates/ARFA_app/view_all_question.html
+0
-15
ARFA/ARFA_app/urls.py
ARFA/ARFA_app/urls.py
+2
-1
ARFA/ARFA_app/views.py
ARFA/ARFA_app/views.py
+27
-26
No files found.
ARFA/ARFA_app/templates/ARFA_app/create_question.html
View file @
c30f50dc
{%extends 'base2.html'%}
{%block head%}
<link
href=
"//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css"
rel=
"stylesheet"
id=
"bootstrap-css"
>
<script
src=
"https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.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>
{%
load static
%}
<script
src=
"http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"
></script>
{%
load static
%}
<link
rel=
"stylesheet"
href=
"{% static 'ARFA_app/create_question.css' %}"
type=
"text/css"
>
<script>
$
(
document
).
ready
(
function
()
{
<script
type=
"text/javascript"
>
$
(
document
).
ready
(
function
()
{
//Initialize tooltips
$
(
'
.nav-tabs > li a[title]
'
).
tooltip
();
...
...
@@ -22,7 +26,7 @@
});
$
(
"
.next-step
"
).
click
(
function
(
e
)
{
console
.
log
(
"
next is clicked
"
)
var
$active
=
$
(
'
.wizard .nav-tabs li.active
'
);
$active
.
next
().
removeClass
(
'
disabled
'
);
nextTab
(
$active
);
...
...
@@ -43,86 +47,260 @@ function prevTab(elem) {
$
(
elem
).
prev
().
find
(
'
a[data-toggle="tab"]
'
).
click
();
}
</script>
{%endblock%}
{% csrf_token %}
<script
type=
"text/javascript"
>
var
question_data
=
{}
;
var
options_details
=
{};
function
addOption
()
{
var
n
=
document
.
getElementById
(
"
optno
"
);
var
x
=
n
.
value
;
x
++
;
n
.
value
=
x
;
var
container
=
document
.
getElementById
(
"
options
"
);
var
que
=
document
.
createElement
(
"
div
"
);
que
.
className
=
"
form-group
"
;
que
.
style
.
width
=
400
;
que
.
id
=
x
;
var
label
=
document
.
createElement
(
"
label
"
);
label
.
innerHTML
=
"
Option
"
+
x
+
"
:
"
;
que
.
appendChild
(
label
);
// que.className = "row" ;
var
r
=
document
.
createElement
(
"
div
"
)
;
r
.
className
=
"
row
"
;
// r.innerHTML = "
<
tr
><
input
class
=
\
"
form-control
\"
size=
\"
30
\"
type=
\"
text
\"
><input class =
\"
form-control
\"
size=
\"
30
\"
type=
\"
text
\"
></tr>
"
;
var
input
=
document
.
createElement
(
"
input
"
);
var
check
=
document
.
createElement
(
"
input
"
);
var
check_ans
=
document
.
createElement
(
"
label
"
);
check_ans
.
for
=
"
c
"
+
x
;
check_ans
.
innerHTML
=
"
Is this an / the answer?
"
check
.
type
=
"
checkbox
"
;
check
.
className
=
"
form-control
"
;
check
.
name
=
"
c
"
+
x
;
input
.
required
=
true
;
input
.
id
=
"
i
"
+
x
;
check
.
id
=
"
c
"
+
x
;
input
.
type
=
"
text
"
;
input
.
size
=
"
30
"
;
input
.
name
=
x
;
check
.
style
.
float
=
"
right
"
;
input
.
className
=
"
form-control
"
;
input
.
placeholder
=
'
Enter an option Here
'
;
r
.
appendChild
(
input
);
r
.
appendChild
(
check
)
;
r
.
appendChild
(
check_ans
)
;
que
.
appendChild
(
r
);
// var text = que.value ;
// text = text + "
<
input
className
=
'
form-control
'
type
=
'
text
'
size
=
'
20
'
placeholder
=
'
Enter an option
'
>
"
;
// document.getElementById('options').innerHTML = text ;
container.appendChild(que);
}
function deleteLastOption()
{
var n = document.getElementById(
"
optno
"
);
var x = n.value;
var last_option = document.getElementById(x) ;
x--;
n.value=x;
last_option.parentNode.removeChild(last_option);
}
function step1()
{
var subject = document.getElementById('subject') ;
var qtext = document.getElementById('qtext').value ;
question_data['subject_ID'] = subject.value ;
question_data['question_text'] = qtext ;
console.log(question_data['question_text']) ;
console.log(question_data['subject_ID']) ;
document.getElementById('l2').click() ;
}
function step2()
{
var O = document.getElementById(
"
options
"
) ;
var children = O.children;
for (var i = 0; i < children.length; i++) {
var tableChild = children[i];
console.log(tableChild) ;
j = i + 1 ;
data = { 'option_Value' : document.getElementById(
"
i
"
+ j).value , 'id' : i , 'is_Answer' : document.getElementById(
"
c
"
+ j).checked} ;
options_details[i] = data ;
console.log(options_details[i]) ;
// Do stuff
}
console.log(options_details) ;
document.getElementById('l3').click() ;
}
function step3()
{
document.getElementById('l4').click() ;
}
function post()
{
// var xhttp = new XMLHttpRequest();
Data = { 'question_data': question_data , 'options_details' : options_details } ;
console.log(Data) ;
// D = {
// client_response : Data,
// csrfmiddlewaretoken: '{{ csrf_token }}'
// } ;
// console.log(D) ;
// var csrftoken = Cookies.get('csrftoken');
// xhttp.onreadystatechange = function() {
// if (this.readyState == 4 && this.status == 200) {
// alert(this.responseText);
// }
// };
// xhttp.open(
"
POST
"
,
"
add_question
"
, true);
// xhttp.send();
// $.post({
// url:
"
add_question
"
,
// data: Data,
//
"
success
"
: function(result) {
// console.log(result);
// }
// }) ;
$.ajax({
url :
"
add_question
"
,
type :
"
POST
"
,
data : {
client_response : JSON.stringify(Data),
csrfmiddlewaretoken: '{{ csrf_token }}'
},
// data : Data ,
// headers: {
// csrfmiddlewaretoken: '{{ csrf_token }}'
// },
success : function(p) {
console.log(JSON.parse(p).status) ;
// if(p.status == '')
alert(
"
Successfully
added
to
database
"
) ;
},
error : function(xhr,errmsg,err) {
alert(xhr.status +
"
:
"
+ xhr.responseText);
}
});
}
</script>
{% endblock%}
{%block title%}
Create Question
{%endblock%}
{%block body%}
<h1>
You CAN CREATE A QUESTION HERE prof {{username}}
</h1>
<!------ Include the above in your HEAD tag ---------->
<div
class=
"container"
>
<h3>
You CAN CREATE A QUESTION HERE prof {{username}}
</h3>
<div
class=
"container"
title=
"this is title"
>
<div
class=
"row"
>
<section>
<div
class=
"wizard"
>
<div
class=
"wizard-inner"
>
<div
class=
"connecting-line"
></div>
<ul
class=
"nav nav-tabs"
role=
"tablist"
>
<li
role=
"presentation"
class=
"active"
>
<a
href=
"#step1"
data-toggle=
"tab"
aria-controls=
"step1"
role=
"tab"
title=
"Step
1"
>
<span
class=
"round-tab"
>
<i
class=
"glyphicon glyphicon-folder-open"
></i>
</span>
</a>
</li>
<li
role=
"presentation"
class=
"disabled"
>
<a
href=
"#step2"
data-toggle=
"tab"
aria-controls=
"step2"
role=
"tab"
title=
"Step
2"
>
<span
class=
"round-tab"
>
<i
class=
"glyphicon glyphicon-pencil"
></i>
</span>
</a>
</li>
<li
role=
"presentation"
class=
"disabled"
>
<a
href=
"#step3"
data-toggle=
"tab"
aria-controls=
"step3"
role=
"tab"
title=
"Step
3"
>
<span
class=
"round-tab"
>
<i
class=
"glyphicon glyphicon-picture"
></i>
</span>
</a>
</li>
<li
role=
"presentation"
class=
"disabled"
>
<a
href=
"#complete"
data-toggle=
"tab"
aria-controls=
"complete"
role=
"tab"
title=
"Complete
"
>
<span
class=
"round-tab"
>
<i
class=
"glyphicon glyphicon-ok"
></i>
</span>
</a>
</li>
</ul>
</div>
<div
class=
"wizard-inner"
>
<div
class=
"connecting-line"
></div>
<ul
class=
"nav nav-tabs"
role=
"tablist"
>
<li
role=
"presentation"
class=
"active"
>
<a
href=
"#step1"
data-toggle=
"tab"
aria-controls=
"step1"
role=
"tab"
title=
"Step 1"
id =
"l
1"
>
<span
class=
"round-tab"
>
<i
class=
"glyphicon glyphicon-folder-open"
></i>
</span>
</a>
</li>
<li
role=
"presentation"
class=
"disabled"
>
<a
href=
"#step2"
data-toggle=
"tab"
aria-controls=
"step2"
role=
"tab"
title=
"Step 2"
id =
"l
2"
>
<span
class=
"round-tab"
>
<i
class=
"glyphicon glyphicon-pencil"
></i>
</span>
</a>
</li>
<li
role=
"presentation"
class=
"disabled"
>
<a
href=
"#step3"
data-toggle=
"tab"
aria-controls=
"step3"
role=
"tab"
title=
"Step 3"
id =
"l
3"
>
<span
class=
"round-tab"
>
<i
class=
"glyphicon glyphicon-picture"
></i>
</span>
</a>
</li>
<li
role=
"presentation"
class=
"disabled"
>
<a
href=
"#complete"
data-toggle=
"tab"
aria-controls=
"complete"
role=
"tab"
title=
"Complete"
id =
"l4
"
>
<span
class=
"round-tab"
>
<i
class=
"glyphicon glyphicon-ok"
></i>
</span>
</a>
</li>
</ul>
</div>
<form
role=
"form"
>
{% csrf_token %}
<div
class=
"tab-content"
>
<div
class=
"tab-pane active"
role=
"tabpanel"
id=
"step1"
>
<h3>
Step 1
</h3>
<p>
This is step 1
</p>
<ul
class=
"list-inline pull-right"
>
<li><button
type=
"button"
class=
"btn btn-primary next-step"
>
Save and continue
</button></li>
</ul>
<h3>
Step 1 - Frame the question
</h3>
<p>
Type your text here.
</p>
<div
class=
"form-group col-lg-4"
>
<label>
Subject
</label>
<!-- <input type="text" class="form-control" name="subject"> -->
<select
type=
"text"
class=
"form-control"
id=
"subject"
>
<option
value=
"M"
>
Maths
</option>
<option
value=
"P"
>
Physics
</option>
<option
value=
"Ch"
>
Chemistry
</option>
</select>
</div>
<ul
class=
"list-inline pull-right"
>
<li><a
href=
"#step2"
><button
type=
"button"
class=
"btn btn-primary next-step"
onclick=
"step1()"
>
Save and continue
</button></a></li>
</ul>
<div
class=
"clearfix"
></div>
<div
class=
"form-group col-lg-12"
>
<label>
Question Text
</label>
<textarea
class=
"form-control"
rows=
"6"
id=
"qtext"
></textarea>
</div>
</div>
<div
class=
"tab-pane"
role=
"tabpanel"
id=
"step2"
>
<h3>
Step 2
</h3>
<p>
This is step 2
</p>
<h3>
Step 2 - Add some options
</h3>
<input
type=
"hidden"
id=
"optno"
value=
"0"
>
<p>
Trick the students !!
</p>
<ul
class=
"list-inline pull-right"
>
<li><button
type=
"button"
class=
"btn btn-default prev-step"
>
Previous
</button></li>
<li><button
type=
"button"
class=
"btn btn-primary next-step"
>
Save and continue
</button></li>
<li><button
type=
"button"
class=
"btn btn-default prev-step"
onclick=
"document.getElementById('l1').click() ; "
>
Previous
</button></li>
<li><button
type=
"button"
class=
"btn btn-primary next-step"
onclick=
"step2()"
>
Save and continue
</button></li>
</ul>
<div
id =
"options"
></div>
<div>
<button
align=
"left"
type=
"button"
class=
"btn btn-primary"
id=
"addratedque"
onclick=
"deleteLastOption()"
>
Delete Last option
</button>
<button
align=
"left"
type=
"button"
class=
"btn btn-primary"
id=
"addsubjectiveque"
onclick=
"addOption()"
>
Add an option
</button>
</div>
</div>
<div
class=
"tab-pane"
role=
"tabpanel"
id=
"step3"
>
<h3>
Step 3
</h3>
<p>
This is step 3
</p>
<h3>
Step 3
- Add some pictures
</h3>
<p>
Drop images in the order you want to display
</p>
<ul
class=
"list-inline pull-right"
>
<li><button
type=
"button"
class=
"btn btn-default prev-step"
>
Previous
</button></li>
<li><button
type=
"button"
class=
"btn btn-default next-step"
>
Skip
</button></li>
<li><button
type=
"button"
class=
"btn btn-primary btn-info-full next-step"
>
Save and continue
</button></li>
<li><button
type=
"button"
class=
"btn btn-default prev-step"
onclick=
"document.getElementById('l2').click() ;"
>
Previous
</button></li>
<li><button
type=
"button"
class=
"btn btn-default next-step"
onclick=
"document.getElementById('l4').click() ;"
>
Skip
</button></li>
<li><button
type=
"button"
class=
"btn btn-primary btn-info-full next-step"
onclick=
"step3()"
>
Save and continue
</button></li>
</ul>
</div>
<div
class=
"tab-pane"
role=
"tabpanel"
id=
"complete"
>
<h3>
Complete
</h3>
<p>
You have successfully completed all steps.
</p>
<p>
You have successfully completed all steps. Here's the preview
</p>
<ul
class=
"list-inline pull-right"
>
<li><button
type=
"button"
class=
"btn btn-default prev-step"
>
Previous
</button></li>
<li><button
type=
"button"
class=
"btn btn-primary btn-info-full next-step"
onclick=
"post()"
>
Post
</button></li>
</ul>
</div>
<div
class=
"clearfix"
></div>
</div>
...
...
@@ -130,5 +308,7 @@ Create Question
</div>
</section>
</div>
</div>
<div><br><br><br><br><br><br><br><br></div>
{%endblock%}
\ No newline at end of file
ARFA/ARFA_app/templates/ARFA_app/not_a_faculty.html
View file @
c30f50dc
{%extends 'base.html'%}
{%block name%}
{{ username }}
{%endblock%}
{%block login_logout%}
<a
href=
"/arfa/logout"
>
Logout
</a>
{%endblock%}
{%extends 'base2.html'%}
...
...
ARFA/ARFA_app/templates/ARFA_app/view_all_question.html
View file @
c30f50dc
<
<<<<<<
HEAD
{%extends 'base2.html'%}
=======
{%
extends
'
base
.
html
'%}
{%
block
name
%}
{{
username
}}
{%
endblock
%}
{%
block
login_logout
%}
<
a
href=
"/arfa/logout"
>
Logout
</a>
{%endblock%}
>>>>>>> c97fad376417d6d43767e7d367382fb1422dfddb
{%block title%}
View personal Question
...
...
ARFA/ARFA_app/urls.py
View file @
c30f50dc
...
...
@@ -18,6 +18,7 @@ urlpatterns=[
url
(
r'^faculty'
,
views
.
faculty
),
url
(
r'^ContactUs'
,
views
.
ContactUs
),
url
(
r'^send_mess'
,
views
.
send_mess
),
url
(
r'^add_question'
,
views
.
add_question
),
]
ARFA/ARFA_app/views.py
View file @
c30f50dc
...
...
@@ -7,7 +7,7 @@ from . import models
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
...
...
@@ -226,29 +226,30 @@ def view_all_Test(request):
# def add_question(request):
# print("adding")
# 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')
# else:
# try:
# args = {'faculty':request.session['username'],**request.POST['question_details']}
# options = request.POST['options_data']
# # args = sanitize(args)
# # options = sanitize(options)
# # question = models.Question(faculty=args['faculty'],subject=args['subject'],
# # question_text=args['question'])
# question = models.Question(**args)
# question.save()
# for i in len(args['options']):
# option = models.Options(q_id=question,option_Value=options['option_Value'],is_answer=options['is_answer'][i])
# option.save()
# return HttpResponse(json.dumps({'status':'Success'}))
# except:
# return HttpResponse(json.dumps({'status':'Failed','reason':'input/database error'}))
def
add_question
(
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'
)
else
:
try
:
question_data
=
dict
(
json
.
loads
(
request
.
POST
[
'client_response'
]))
args
=
question_data
[
'question_data'
]
args
[
'faculty'
]
=
models
.
Faculty
.
objects
.
filter
(
username
=
request
.
session
[
'username'
])
.
get
()
options
=
question_data
[
'options_details'
]
args
[
'subject_ID'
]
=
models
.
Subject
.
objects
.
filter
(
subject_ID
=
args
[
'subject_ID'
])
.
get
()
question
=
models
.
Question
(
**
args
)
question
.
save
()
for
i
in
range
(
0
,
len
(
options
)):
option
=
models
.
Options
(
q_ID
=
question
,
option_Value
=
options
[
str
(
i
)][
'option_Value'
],
is_Answer
=
options
[
str
(
i
)][
'is_Answer'
],
option_ID
=
options
[
str
(
i
)][
'id'
])
option
.
save
()
return
HttpResponse
(
json
.
dumps
({
'status'
:
'Success'
}))
except
:
return
HttpResponse
(
json
.
dumps
({
'status'
:
'Failed'
,
'reason'
:
'input/database error'
}))
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