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
def get_context_data(self, **kwargs): target_uri = "http://*****:*****@tonsmitshuis.nl" } }, { "thumbnail": "", "deepzoom": "", "mime_type": "audio/wav", "source_uri": "media/189467__speedenza__poem-darkness-voice.wav", "metadata": { "dc_title": "Poem: Darkness (Voice)", "dc_creator": "Speedenza (freesound.org)", "dc_rights": "freesound.org" } }, { "thumbnail": "", "deepzoom": "", "mime_type": "video/mp4", "source_uri": "media/NuclearExplosionwww.keepvid.com.mp4", "metadata": { "dc_title": "Nuclear explosion", "dc_creator": "Oppenheimer", "dc_rights": "Destructive Commons" } } ] # Todo add search results # * build query on uri or property # * add facets from configuration + property facet # * get NaveResponse # * add to context as data return context
def get_context_data(self, **kwargs): # todo later add acceptance mode target_uri = self.request.build_absolute_uri().replace('/page/', '/resource/') if "?" in target_uri: target_uri = re.sub("\?.*$", '', target_uri) # target_uri = target_uri.split('?')[:-1] if not self.request.path.startswith("/page"): target_uri = re.sub('/[a-z]{2}/resource/', '/resource/', target_uri, count=1) if target_uri.endswith('graph'): target_uri = re.sub("/graph$", "", target_uri) context = super(LoDHTMLView, self).get_context_data(**kwargs) # default and test mode mode = self.request.REQUEST.get('mode', 'default') acceptance = True if mode == 'acceptance' else False if not acceptance: acceptance = self.request.COOKIES.get('NAVE_ACCEPTANCE_MODE', False) object_local_cache = None cached = False context['about'] = target_uri context['ugc'] = None if "/resource/cache/" in target_uri: # lookup solution # rdfstore.get_rdfstore().get_cached_source_uri(target_uri) cached = True target_uri = target_uri.split('/resource/cache/')[-1] if target_uri.endswith("about.rdf"): target_uri = re.sub('about.rdf$', '', target_uri) else: target_uri = target_uri.rstrip('/') resolved_uri = RDFRecord.get_internal_rdf_base_uri(target_uri) if UserGeneratedContent.objects.filter(source_uri=resolved_uri).exists(): context['ugc'] = UserGeneratedContent.objects.filter(source_uri=resolved_uri) if settings.RDF_USE_LOCAL_GRAPH: object_local_cache = ElasticSearchRDFRecord(source_uri=resolved_uri) object_local_cache.get_graph_by_source_uri(uri=resolved_uri) if not object_local_cache.exists(): context['source_uri'] = target_uri context['unknown_graph'] = True return context target_uri = resolved_uri elif self.store.ask(uri=resolved_uri): target_uri = resolved_uri context['source_uri'] = target_uri context['about_label'] = target_uri.split('/')[-1] context['about_spec'] = target_uri.split('/')[-2] context['cached'] = cached # special query for skos def is_skos(): return self.store.ask( query="where {{<{subject}> <{predicate}> <{object}>}}".format( subject=target_uri, predicate=RDF.type, object=SKOS.Concept)) if object_local_cache: # todo: add code to retrieve proxyresources # (with_mappings=True, include_mapping_target=True, acceptance=acceptance) graph = object_local_cache.get_context_graph(with_mappings=True, include_mapping_target=True) nr_levels = 4 elif cached: if CacheResource.objects.filter(document_uri=target_uri).exists(): cache_object = CacheResource.objects.filter(document_uri=target_uri).first() graph = cache_object.get_graph() nr_levels = 3 else: context['unknown_graph'] = True return context elif is_skos(): graph, nr_levels = RDFModel.get_skos_context_graph(store=self.store, target_uri=target_uri) # nav_tree = RDFModel.get_nav_tree(target_uri=target_uri, store=self.store) # todo finish the nav tree implementation if 'skos_nav' in self.request.GET: return context elif '/resource/aggregation' in target_uri: target_named_graph = "{}/graph".format(target_uri.rstrip('/')) graph, nr_levels = RDFModel.get_context_graph(store=self.store, named_graph=target_named_graph) else: graph, nr_levels = RDFModel.get_context_graph(target_uri=target_uri, store=self.store) graph_contains_target = graph.query("""ASK {{ <{}> ?p ?o }} """.format(target_uri)).askAnswer if not graph_contains_target or len(graph) == 0: context['unknown_graph'] = True return context if context['about'].endswith('/'): context['about'] = context['about'].rstrip('/') context['graph'] = graph context['nr_levels'] = nr_levels context['namespaces'] = [(prefix, uri) for prefix, uri in graph.namespaces()] graph_bindings = GraphBindings(target_uri, graph, excluded_properties=settings.RDF_EXCLUDED_PROPERTIES) context['skos_links'], context['skos_filter'] = graph_bindings.get_all_skos_links() context['resources'] = graph_bindings resource = graph_bindings.get_about_resource() context['items'] = resource.get_items(as_tuples=True) rdf_type = graph_bindings.get_about_resource().get_type() context['rdf_type'] = rdf_type context['content_template'] = self.get_content_type_template(rdf_type.search_label) context['graph_stats'] = RDFModel.get_graph_statistics(graph) context['alt'] = "" context['points'] = RDFModel.get_geo_points(graph) # DEEPZOOM VALUE(S) zooms = graph_bindings.get_list('nave_deepZoomUrl') if zooms: context['deepzoom_count'] = len(zooms) context['deepzoom_urls'] = [zoom.value for zoom in zooms] # EXPERT MODE expert_mode = self.request.COOKIES.get('NAVE_DETAIL_EXPERT_MODE', False) if expert_mode: # do expert mode stuff like more like this context['expert_mode'] = True if settings.MLT_DETAIL_ENABLE and object_local_cache: context['data'] = {'items': object_local_cache.get_more_like_this()} if settings.MLT_BANNERS and isinstance(settings.MLT_BANNERS, dict) and object_local_cache: from collections import OrderedDict context['data'] = {"mlt_banners": OrderedDict()} for name, config in settings.MLT_BANNERS.items(): mlt_fields = config.get("fields", None) if mlt_fields and any(".raw" in field for field in mlt_fields): # .raw fields don't work with MORE LIKE THIS queries so are # queried directly. context['data']['mlt_banners'][name] = object_local_cache.get_raw_related( query_fields=mlt_fields, filter_query=config.get("filter_query", None), graph_bindings=graph_bindings ) else: context['data']['mlt_banners'][name] = object_local_cache.get_more_like_this( mlt_count=10, mlt_fields=mlt_fields, filter_query=config.get("filter_query", None) ) view_modes = { 'properties': "rdf/_rdf_properties.html" } display_mode = self.request.GET.get('display') if display_mode: self.template_name = view_modes.get(display_mode, self.template_name) return context