def build_json(items_list, query_params): class_url = build_class_url(query_params) schema_url = unquote(build_schema_url_for_instance(query_params, class_url)) class_properties = get_class.get_cached_schema(query_params)["properties"] items_list = cast_items_values(items_list, class_properties) json = { '_schema_url': schema_url, 'pattern': '', '_class_prefix': expand_uri(query_params['class_prefix']), '_base_url': remove_last_slash(query_params.base_url), 'items': items_list, '@context': {"@language": query_params.get("lang")}, '@id': query_params['class_uri'] } def calculate_total_items(): result_dict = query_count_filter_instances(query_params) total_items = int(get_one_value(result_dict, 'total')) return total_items decorate_dict_with_pagination(json, query_params, calculate_total_items) return json
def assemble_instance_json(query_params, query_result_dict, class_schema): expand_object_properties = query_params.get( "expand_object_properties") == "1" include_meta_properties = query_params.get( "meta_properties") is None or query_params.get( "meta_properties") == "1" items = build_items_dict(query_result_dict['results']['bindings'], query_params["class_uri"], expand_object_properties, class_schema) if include_meta_properties: class_url = build_class_url(query_params) instance_uri = query_params['instance_uri'] instance_prefix, instance_id = split_prefix_and_id_from_uri( instance_uri) query_params.resource_url = u"{0}/{1}".format(class_url, instance_id) instance = { "_base_url": query_params.base_url, "_instance_prefix": instance_prefix, "_resource_id": instance_id, "@id": instance_uri, "@type": query_params["class_uri"], "_type_title": class_schema["title"] } check_and_clean_rdftype(instance['@type'], items) else: instance = {} instance.update(items) return instance
def assemble_instance_json(query_params, query_result_dict, class_schema): expand_object_properties = query_params.get("expand_object_properties") == "1" include_meta_properties = query_params.get("meta_properties") is None or query_params.get("meta_properties") == "1" items = build_items_dict(query_result_dict['results']['bindings'], query_params["class_uri"], expand_object_properties, class_schema) if include_meta_properties: class_url = build_class_url(query_params) instance_uri = query_params['instance_uri'] instance_prefix, instance_id = split_prefix_and_id_from_uri(instance_uri) query_params.resource_url = u"{0}/{1}".format(class_url, instance_id) instance = { "_base_url": query_params.base_url, "_instance_prefix": instance_prefix, "_resource_id": instance_id, "@id": instance_uri, "@type": query_params["class_uri"], "_type_title": class_schema["title"] } check_and_clean_rdftype(instance['@type'], items) else: instance = {} instance.update(items) return instance
def finalize(self, response): if isinstance(response, dict): self.write(response) class_url = build_class_url(self.query_params) schema_url = build_schema_url_for_instance(self.query_params, class_url) header_value = content_type_profile(schema_url) self.set_header("Content-Type", header_value) elif isinstance(response, int): # status code self.set_status(response)
def finalize(self, response): # FIXME: handle uniformly cache policy # Meanwhile we do not have a consitent external cache handling policy # this avoids a client (such as chrome browser) caching a resource for ever self.set_header("Cache-control", "private") self.set_header("max-age", "0") if isinstance(response, dict): self.write(response) class_url = build_class_url(self.query_params) schema_url = build_schema_url_for_instance(self.query_params, class_url) header_value = content_type_profile(schema_url) self.set_header("Content-Type", header_value) elif isinstance(response, int): # status code self.set_status(response)