#NEWLINE# @ login_required ( login_url = '/landpage' ) #NEWLINE# def save_exam( request , course_id ) : #NEWLINE# #INDENT# response_data = { #NEWLINE# #INDENT# 'status' : 'failed' , #NEWLINE# 'message' : 'unknown error with saving' , #NEWLINE# #UNINDENT# } #NEWLINE# if request . is_ajax ( ) : #NEWLINE# #INDENT# if ( request . method == 'POST' ) : #NEWLINE# #INDENT# course = Course . objects . get ( id = course_id ) #NEWLINE# exam_id = int ( request . POST [ 'exam_id' ] ) #NEWLINE# form = None #NEWLINE# if ( exam_id > 0 ) : #NEWLINE# #INDENT# exam = Exam . objects . get ( exam_id = exam_id ) #NEWLINE# form = ExamForm ( instance = exam , data = request . POST ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# form = ExamForm ( request . POST , request . FILES ) #NEWLINE# #UNINDENT# if form . is_valid ( ) : #NEWLINE# #INDENT# instance = form . save ( commit = False ) #NEWLINE# instance . course = course #NEWLINE# instance . save ( ) #NEWLINE# response_data = { #NEWLINE# #INDENT# 'status' : 'success' , #NEWLINE# 'message' : 'saved' , #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# response_data = { #NEWLINE# #INDENT# 'status' : 'failed' , #NEWLINE# 'message' : json . dumps ( form . errors ) , #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# return HttpResponse ( json . dumps ( response_data ) , content_type = 'application/json' )