def get_all(request): """ Method to handle a request for all Person objects :param request: Django HttpRequest Object :return: an HttpResponse object embedded with the completed return template for all People """ # get all people try: people_list = Person().get_all() except TypeError as e: print(e) return finish_request(error=API_ERRORS['NOT_FOUND']) except InvalidId as e: print(e) return finish_request(error=API_ERRORS['INVALID_PARAMETER']) except: return finish_request(error="Unexpected error:" + sys.exc_info()[0]) # get return template t = get_return_template('PERSON') out_list = [] for p in people_list: out_list.append(extract_to_template(object=p, template=t)) return finish_request(out_list)
def get(request, id): """ Method to handle a request for a single person object from the API :param request: Django HttpRequest Object :param id: the ID of the Person object to get (can be string or ObjectID) :return: an HttpResponse object embedded with the completed return template for Person """ # get person object try: p = Person().GET(id) except TypeError as e: print(e) return finish_request(error=API_ERRORS['NOT_FOUND']) except InvalidId as e: print(e) return finish_request(error=API_ERRORS['INVALID_PARAMETER']) except: return finish_request(error="Unexpected error:" + sys.exc_info()[0]) #get return template t = get_return_template('PERSON') out_list = [] out_list.append(extract_to_template(object=p, template=t)) return finish_request(out_list)
def get(request, id): """ Method to handle a request for a single sample object from the API :param request: a Django HTTPRequest object :param id: the id of the Sample object (can be string or ObjectID) :return: an HttpResponse object embedded with the completed return template for Sample """ # get sample and source objects try: ss = Sample().get_sample_and_source(id) except TypeError as e: print(e) return finish_request(error=API_ERRORS['NOT_FOUND']) except InvalidId as e: print(e) return finish_request(error=API_ERRORS['INVALID_PARAMETER']) except: print("Unexpected error:", sys.exc_info()[0]) raise source = ss['source'] sample = ss['sample'] # get template for return type t_source = get_return_template('SOURCE') t_sample = get_return_template('SAMPLE') # extract fields for both source and sample tmp_source = extract_to_template(object=source, template=t_source) tmp_sample = extract_to_template(object=sample, template=t_sample) tmp_sample['source'] = tmp_source out_list = [] out_list.append(tmp_sample) return finish_request(out_list)
def get_all(request): """ Method to handle a request for all :param request: a Django HttpRequest object :return: A dictionary containing all samples in COPO """ out_list = [] # get sample and source objects try: sample_list = Sample().get_samples_across_profiles() except TypeError as e: print(e) return finish_request(error=API_ERRORS['NOT_FOUND']) except InvalidId as e: print(e) return finish_request(error=API_ERRORS['INVALID_PARAMETER']) except: print("Unexpected error:", sys.exc_info()[0]) raise for s in sample_list: # get template for return type t_source = get_return_template('SOURCE') t_sample = get_return_template('SAMPLE') # get source for sample source = Source().GET(s['source_id']) # extract fields for both source and sample tmp_source = extract_to_template(object=source, template=t_source) tmp_sample = extract_to_template(object=s, template=t_sample) tmp_sample['source'] = tmp_source out_list.append(tmp_sample) return finish_request(out_list)