def present_welcome(): # check for a cookie, if present, then extract value cookie = bottle.request.get_cookie("session") username = sessions.get_username(cookie) # see if user is logged in if username is None: # print "welcome: can't identify user...redirecting to signup" bottle.redirect('/') else: result = get_myinfo(username) dummy_list = [] if result != None: # dummy_list.append(result) # wrapped_response = ResponseWrapper() # wrapped_response.set_error(False) # wrapped_response.set_data(dummy_list) wrapper_response = { 'error':False, 'data':result } # json_result = json.dumps(wrapped_response, default=ResponseWrapper.__str__) json_result = json.dumps(wrapper_response) bottle.response.content_type="application/json" return json_result else: wrapped_response = ResponseWrapper() wrapped_response.set_error(True) wrapped_response.set_data([]) json_result = json.dumps(wrapped_response, default=ResponseWrapper.__str__) return json_result
def app_info(): result = get_myinfo() if result != None: wrapped_response = ResponseWrapper() wrapped_response.set_error(False) wrapped_response.set_data(result) json_result = json.dumps(wrapped_response, default=ResponseWrapper.__str__) return json_result else: wrapped_response = ResponseWrapper() wrapped_response.set_error(True) wrapped_response.set_data([]) json_result = json.dumps(wrapped_response, default=ResponseWrapper.__str__) return json_result
def get_batch_ids(): result = batches.get_all_batch_ids() wrapped_response = ResponseWrapper() bottle.response.content_type = "application/json" if result != None: wrapped_response.set_data(result) wrapped_response.set_error(False) json_result = json.dumps(wrapped_response, default=ResponseWrapper.__str__) else: wrapped_response.set_error(True) json_result = json.dumps(wrapped_response, default=ResponseWrapper.__str__) return json_result
def get_batch(batchid): result = batches.get_batch_by_id(batchid) bottle.response.content_type = "application/json" array = [result] wrapped_response = ResponseWrapper() json_result = None if result != None : wrapped_response.set_data(array) wrapped_response.set_error(False) json_result = json.dumps(wrapped_response, default=ResponseWrapper.__str__) else: wrapped_response.set_error(True) json_result = json.dumps(wrapped_response, default=ResponseWrapper.__str__) return json_result
def get_myratings_by_sem(semno): cookie = bottle.request.get_cookie("session") username = sessions.get_username(cookie) # see if user is logged in print username, semno result = ratings.get_user_ratings_by_sem(username,semno) wrapped_response = ResponseWrapper() json_result = None if result != None : wrapped_response.set_data(result) wrapped_response.set_error(False) json_result = json.dumps(wrapped_response, default=ResponseWrapper.__str__) else: wrapped_response.set_error(True) json_result = json.dumps(wrapped_response, default=ResponseWrapper.__str__) bottle.response.content_type = "application/json" return json_result