commit

parent 6f91df7b
......@@ -180,9 +180,15 @@ function prevTab(elem) {
// csrfmiddlewaretoken: '{{ csrf_token }}'
// },
success : function(p) {
console.log(JSON.parse(p).status) ;
q = JSON.parse(p);
console.log(q) ;
// if(p.status == '')
alert("Successfully added to database") ;
if(q.status=='Failed'){
alert('Reason'+' : '+q.reason)
}
else{
alert("Successfully added to database") ;
}
},
error : function(xhr,errmsg,err) {
alert(xhr.status + ": " + xhr.responseText);
......
......@@ -316,12 +316,22 @@ def add_question(request):
question_data = dict(json.loads(request.POST['client_response']))
args = question_data['question_data']
print args['question_text']
if args['question_text']=='':
print 'failed'
return HttpResponse(json.dumps({'status':'Failed','reason':'No question provided'}))
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()
flag = False
for i in range(0,len(options)):
if options[str(i)]['option_Value']:
flag = True
break
if not(flag):
return HttpResponse(json.dumps({'status':'Failed','reason':'No correct option provided'}))
question = models.Question(**args)
question.save()
for i in range(0,len(options)):
......
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