def activateQuestion(): global activeQuestion, responses_tracker if request.method == 'POST': if isinstance(activeQuestion, Question): return f'There is Already an Active Question!' data = request.json if data["type"] == "multiple_choice": activeQuestion = MultipleChoiceQuestion(prompt=data["prompt"], choices=data["choices"], answer=data["answer"]) else: activeQuestion = MatchingQuestion( prompt=data["prompt"], left_choices=data["leftChoices"], right_choices=data["rightChoices"], answer_mapping=data["answerMapping"]) return flaskResponse( json.dumps(activeQuestion, cls=ProjectJSONEncoder), 200, {'Content-Type': 'application/json'}) else: if activeQuestion is not None: return flaskResponse( json.dumps(activeQuestion, cls=ProjectJSONEncoder), 200, {'Content-Type': 'application/json'}) else: return f'No Question Active!'
def buildResponse(ReqResponse, ContentType="text/plain"): '''Transfer requests response object into a flask Response object''' builtResponse = flaskResponse( status = ReqResponse.status_code, response = ReqResponse.content, mimetype = ContentType ) return builtResponse
def fetchResponses(): global activeQuestion, responses_tracker if activeQuestion is not None: responses = flaskResponse(json.dumps(activeQuestion.get_responses(), cls=ProjectJSONEncoder), mimetype='application/json') print( json.dumps(activeQuestion.get_responses(), cls=ProjectJSONEncoder)) return "NUMBER OF RESPONSES: {}".format(responses_tracker) return f'No Active '
from flask import Response as flaskResponse import requests def buildResponse(ReqResponse, ContentType="text/plain"): '''Transfer requests response object into a flask Response object''' builtResponse = flaskResponse( status = ReqResponse.status_code, response = ReqResponse.content, mimetype = ContentType ) return builtResponse # 401 Unauthorized EmptyAuth = flaskResponse( response = 'Missing Login information, cannot use MDS without authentication', status = 401, mimetype = 'text/plain' ) #Create some different error response objects for flask PostGet405 = flaskResponse( response = 'Method Not Allowed: POST or GET at this Endpoint', status = 405, mimetype = 'text/plain' ) Get405 = flaskResponse( response = 'Method Not Allowed: Only GET at this Endpoint', status = 405, mimetype = 'text/plain' )
if re.match("uuid:.*", Idenfitier): return "uuid" else: return "Unmatched Identifier" def jsonToANVL(JSONinput): '''Takes in JSON input and returns ANVL key value pairs seperated by newlines ''' decodedDict = json.JSONDecoder.decode(JSONinput) return "\n".join( [key + ': ' + value for key, value in decodedDict.items()]) # 401 Unauthorized EmptyAuth = flaskResponse( response='Missing Login information, cannot use MDS without authentication', status=401, mimetype='text/plain') # 404 NotFinished404 = flaskResponse(response='Funcionality Not Yet Implemented', status=404, mimetype='text/plain') def buildResponse(ReqResponse, ContentType="text/plain"): '''Transfer requests response object into a flask Response object''' builtResponse = flaskResponse(status=ReqResponse.status_code, response=ReqResponse.content, mimetype=ContentType) return builtResponse