def listfiles(request): try: # Load documents for the list page messages = Message.objects.all() # Return the file list as JSON. return HttpResponse(serializers.serialize('json', messages), mimetype="application/json") except Exception as ex: # Respond with error as JSON. return HttpResponse(ApiResponse.from_exception(ex).to_json(), mimetype="application/json")
def savefile(request): try: # Handle file upload if request.method == 'POST': newMsg = __uploadhelper(request) # Return success message as JSON. return HttpResponse(ApiResponse(success=True, message=newMsg.altered_file).to_json(), mimetype="application/json") else: raise Exception('Must use HTTP POST method!') except Exception as ex: # Respond with error as JSON. return HttpResponse(ApiResponse.from_exception(ex).to_json(), mimetype="application/json")