def test_get_geo_points(self): graph = Graph() subject = URIRef('joachim') graph.add((subject, URIRef("http://www.w3.org/2003/01/geo/wgs84_pos#lat"), Literal("51.54"))) graph.add((subject, URIRef("http://www.w3.org/2003/01/geo/wgs84_pos#long"), Literal("5.2"))) points = RDFModel.get_geo_points(graph) assert points is not None assert points == [[51.54, 5.2]] graph = Graph() points = RDFModel.get_geo_points(graph) assert points == []
def get_context_data(self, **kwargs): context = super(NaveDocumentTemplateView, self).get_context_data(**kwargs) absolute_uri = self.request.build_absolute_uri() target_uri = RDFRecord.get_internal_rdf_base_uri(absolute_uri) if "detail/foldout/" in target_uri: slug = self.kwargs.get('slug') record = ElasticSearchRDFRecord(hub_id=slug) graph = record.get_graph_by_id(self.kwargs.get('slug')) if graph is not None: target_uri = record.source_uri else: logger.warn("Unable to find source_uri for slug: {}".format(slug)) else: target_uri = RDFRecord.get_internal_rdf_base_uri(absolute_uri) record = ElasticSearchRDFRecord(hub_id=self.kwargs.get('slug')) graph = record.get_graph_by_source_uri(target_uri) if graph is None: raise UnknownGraph("URI {} is not known in our graph store".format(target_uri)) if "/resource/cache/" in target_uri: target_uri = target_uri.rstrip('/') cache_resource = CacheResource.objects.filter(document_uri=target_uri) if cache_resource.exists(): graph = cache_resource.first().get_graph() elif settings.RDF_USE_LOCAL_GRAPH: mode = self.request.REQUEST.get('mode', 'default') acceptance = True if mode == 'acceptance' else False context['acceptance'] = acceptance elif '/resource/aggregation' in target_uri: target_named_graph = "{}/graph".format(target_uri.rstrip('/')) graph, nr_levels = RDFModel.get_context_graph(store=rdfstore.get_rdfstore(), named_graph=target_named_graph) else: graph, nr_levels = RDFModel.get_context_graph( store=rdfstore.get_rdfstore(), target_uri=target_uri ) # todo: remove: should no longer be necessary with the addition of common.middleware.ForceLangMiddleware language = self.request.GET.get('lang', None) if language: activate(language) bindings = GraphBindings( about_uri=target_uri, graph=graph, excluded_properties=settings.RDF_EXCLUDED_PROPERTIES ) context['resources'] = bindings context['absolute_uri'] = RDFRecord.get_external_rdf_url(target_uri, self.request) for rdf_type in bindings.get_about_resource().get_types(): search_label = rdf_type.search_label.lower() content_template = settings.RDF_CONTENT_FOLDOUTS.get(search_label) if content_template: self.template_name = content_template break context['points'] = RDFModel.get_geo_points(graph) return context
def get_context_data(self, **kwargs): context = super(NaveDocumentDetailView, self).get_context_data(**kwargs) target_uri = self.object.document_uri if "/resource/cache/" in target_uri: target_uri = target_uri.rstrip('/') cache_resource = CacheResource.objects.filter(document_uri=target_uri) if cache_resource.exists(): graph = cache_resource.first().get_graph() elif settings.RDF_USE_LOCAL_GRAPH: mode = self.request.REQUEST.get('mode', 'default') acceptance = True if mode == 'acceptance' else False context['acceptance'] = acceptance if isinstance(self.object, EDMRecord): graph = self.object.get_graph(with_mappings=True, include_mapping_target=True, acceptance=acceptance) else: graph = self.object.get_graph(acceptance=acceptance) elif '/resource/aggregation' in target_uri: target_named_graph = "{}/graph".format(target_uri.rstrip('/')) graph, nr_levels = RDFModel.get_context_graph(store=rdfstore.get_rdfstore(), named_graph=target_named_graph) else: graph, nr_levels = RDFModel.get_context_graph( store=rdfstore.get_rdfstore(), target_uri=target_uri ) # todo: remove: should no longer be necessary with the addition of common.middleware.ForceLangMiddleware language = self.request.GET.get('lang', None) if language: activate(language) bindings = GraphBindings( about_uri=target_uri, graph=graph, excluded_properties=settings.RDF_EXCLUDED_PROPERTIES ) context['resources'] = bindings for rdf_type in bindings.get_about_resource().get_types(): search_label = rdf_type.search_label.lower() content_template = settings.RDF_CONTENT_FOLDOUTS.get(search_label) if content_template: self.template_name = content_template break context['points'] = RDFModel.get_geo_points(graph) return context