#NEWLINE# @ csrf_exempt #NEWLINE# @ RequireLogin ( role = 'admin' ) #NEWLINE# def start( request ) : #NEWLINE# #INDENT# '\n    Start the proxy.\n    ' #NEWLINE# if ( request . method != 'GET' ) : #NEWLINE# #INDENT# return HttpResponse ( status = 405 ) #NEWLINE# #UNINDENT# from api.models import redis_wrapper #NEWLINE# r = redis_wrapper . init_redis ( ) #NEWLINE# response_key = str ( ObjectId ( ) ) #NEWLINE# redis_wrapper . publish_to_proxy ( json . dumps ( { #NEWLINE# #INDENT# 'operation' : 'start' , #NEWLINE# 'param' : None , #NEWLINE# 'key' : response_key , #NEWLINE# #UNINDENT# } ) ) #NEWLINE# for i in range ( 0 , 50 ) : #NEWLINE# #INDENT# response = r . get ( response_key ) #NEWLINE# if ( response is not None ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# response = json . loads ( response ) #NEWLINE# #UNINDENT# except ValueError : #NEWLINE# #INDENT# return HttpResponse ( status = 500 ) #NEWLINE# #UNINDENT# if ( ( 'code' in response ) and ( response [ 'code' ] == 200 ) ) : #NEWLINE# #INDENT# return JsonResponse ( { #NEWLINE# #INDENT# 'proxyResponse' : response , #NEWLINE# #UNINDENT# } , status = 200 ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return HttpResponse ( status = 500 ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# time . sleep ( 0.1 ) #NEWLINE# #UNINDENT# #UNINDENT# return HttpResponse ( status = 408 )