def new_error(status_code): ''' Create a new OperationOutcome resource from HTTP status_code ''' msg, severity = CODES[status_code] outcome_content = { 'resourceType': 'OperationOutcome', 'issue': { 'severity': severity, 'details': msg } } is_xml = (request.args.get('_format', 'xml') == 'xml') response= (json_response(json.dumps(outcome_content)) if not is_xml else xml_response(json_to_xml(outcome_content))) response.status = status_code return response
def as_response(self, request, created=False): ''' return the resource as a HTTP response ''' status = '201' if created else '200' if request.format == 'json': response = json_response(status=status) response.data = self.data else: response = xml_response(status=status) response.data = json_to_xml(json.loads(self.data)) loc_header = 'Location' if created else 'Content-Location' response.headers[loc_header] = urljoin( request.api_base, '%s/%s/_history/%s' % (self.resource_type, self.resource_id, self.version)) return response
def as_response(self, request, created=False): ''' return the resource as a HTTP response ''' status = '201' if created else '200' if request.format == 'json': response = json_response(status=status) response.data = self.data else: response = xml_response(status=status) response.data = json_to_xml(json.loads(self.data)) loc_header = 'Location' if created else 'Content-Location' response.headers[loc_header] = urljoin(request.api_base, '%s/%s/_history/%s' % ( self.resource_type, self.resource_id, self.version)) return response