#NEWLINE# @ login_required ( login_url = '/landpage' ) #NEWLINE# def delete_assignment( request , course_id ) : #NEWLINE# #INDENT# response_data = { #NEWLINE# #INDENT# 'status' : 'failed' , #NEWLINE# 'message' : 'unknown error with deleting' , #NEWLINE# #UNINDENT# } #NEWLINE# if request . is_ajax ( ) : #NEWLINE# #INDENT# if ( request . method == 'POST' ) : #NEWLINE# #INDENT# assignment_id = int ( request . POST [ 'assignment_id' ] ) #NEWLINE# teacher = Teacher . objects . get ( user = request . user ) #NEWLINE# try : #NEWLINE# #INDENT# assignment = Assignment . objects . get ( assignment_id = assignment_id ) #NEWLINE# if ( assignment . course . teacher == teacher ) : #NEWLINE# #INDENT# assignment . delete ( ) #NEWLINE# response_data = { #NEWLINE# #INDENT# 'status' : 'success' , #NEWLINE# 'message' : 'assignment was deleted' , #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# response_data = { #NEWLINE# #INDENT# 'status' : 'failed' , #NEWLINE# 'message' : 'unauthorized deletion' , #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# #UNINDENT# except Assignment . DoesNotExist : #NEWLINE# #INDENT# response_data = { #NEWLINE# #INDENT# 'status' : 'failed' , #NEWLINE# 'message' : 'record not found' , #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# return HttpResponse ( json . dumps ( response_data ) , content_type = 'application/json' )