diff --git a/daiquiri/core/settings/django.py b/daiquiri/core/settings/django.py index 26217d43..5f5551ac 100644 --- a/daiquiri/core/settings/django.py +++ b/daiquiri/core/settings/django.py @@ -209,12 +209,11 @@ } SETTINGS_EXPORT = [ - 'LOGIN_URL', - 'LOGOUT_URL', 'ACCOUNT_LOGOUT_ON_GET', 'AUTH_WORKFLOW', 'AUTH_TERMS_OF_USE', - 'SITE_PUBLISHER', + 'LOGIN_URL', + 'LOGOUT_URL', 'METADATA_COLUMN_PERMISSIONS', 'QUERY_DROPDOWN_FUNCTIONS', 'QUERY_DROPDOWNS', @@ -223,6 +222,8 @@ 'QUERY_DOWNLOADS', 'QUERY_DOWNLOAD_FORMATS', 'QUERY_UPLOAD', + 'SITE_PUBLISHER', + 'SITE_URL', 'STATS_RESOURCE_TYPES' ] diff --git a/daiquiri/datalink/adapter.py b/daiquiri/datalink/adapter.py index aa1cd27c..909b4030 100644 --- a/daiquiri/datalink/adapter.py +++ b/daiquiri/datalink/adapter.py @@ -82,38 +82,34 @@ def get_datalink_rows(self, identifiers, **kwargs): '''Get the list of datalink entries for the provided identifiers (incl. table- and dynamic- datalink) ''' + # get the datalink entries from Datalink Table and metadata (Table and Schema) - field_names = [field['name'] for field in DATALINK_FIELDS] - rows = list(Datalink.objects.filter(ID__in=identifiers).values_list(*field_names)) + static_datalink_rows = list(Datalink.objects.filter(ID__in=identifiers).values()) # get the dynamic datalink entries + dyn_datalink_rows = self.get_dyn_datalink_links(identifiers) + datalink_rows = static_datalink_rows + dyn_datalink_rows + + + # create a full URI for the custom semantics + for row in datalink_rows: + if row['semantics'] in settings.DATALINK_CUSTOM_SEMANTICS: + row['semantics'] = settings.SITE_URL + reverse('datalink:datalink-semantics') + row['semantics'] + + field_names = [field['name'] for field in DATALINK_FIELDS] + try: - dyn_rows = [( - link['ID'], - link['access_url'], - link['service_def'], - link['error_message'], - link['description'], - link['semantics'], - link['content_type'], - link['content_length']) for link in self.get_dyn_datalink_links(identifiers) - ] - - # in case of malformation give some hints to the developper + rows = [[link[key] for key in field_names] for link in datalink_rows] except KeyError as e: class_name = str(self.__class__) - raise KeyError(f"The key '{e.args[0]}' is missing in one of the dictionaries returned by {class_name}.get_dyn_datalink_links(id)") - - # otherwise just raise + raise KeyError(f"The key '{e.args[0]}' is missing in one of the dictionaries returned by {class_name}.get_dyn_datalink_links(id) or in the Datalnk model.") except Exception as e: raise e - rows = rows + dyn_rows - # check for missing IDs and return error message for identifier in identifiers: - if not any(filter(lambda row: row[0] == identifier, rows)): - rows.append((identifier, None, None, 'NotFoundFault: {}'.format(identifier), None, None, None, None)) + if not any(filter(lambda row: row[0] == identifier, rows)): + rows.append((identifier, None, None, 'NotFoundFault: {}'.format(identifier), None, None, None, None)) return rows diff --git a/daiquiri/datalink/settings.py b/daiquiri/datalink/settings.py index aa9ec17d..a787b7fc 100644 --- a/daiquiri/datalink/settings.py +++ b/daiquiri/datalink/settings.py @@ -1,2 +1,6 @@ DATALINK_ADAPTER = 'daiquiri.datalink.adapter.DefaultDatalinkAdapter' DATALINK_TABLES = [] + +DATALINK_CUSTOM_SEMANTICS = { + "#doi": "The access_url points to the Digital Object Identifier (DOI) of the object.", +} diff --git a/daiquiri/datalink/templates/datalink/datalink-semantics.html b/daiquiri/datalink/templates/datalink/datalink-semantics.html new file mode 100644 index 00000000..631dcd5b --- /dev/null +++ b/daiquiri/datalink/templates/datalink/datalink-semantics.html @@ -0,0 +1,31 @@ +{% extends 'core/wide.html' %} +{% load i18n %} + +{% block wide %} + +

The extension to the Datalink-core dictionary

+ + + + + + + + + + + + + {% for semantics, description in custom_semantics.items %} + + + + + + + {% endfor %} + + + +
TermDescription
{{ settings.SITE_URL }}{% url 'datalink:datalink-semantics' %}{{ semantics }}{{ description }}
+{% endblock %} diff --git a/daiquiri/datalink/urls.py b/daiquiri/datalink/urls.py index 5fb70156..db75d249 100644 --- a/daiquiri/datalink/urls.py +++ b/daiquiri/datalink/urls.py @@ -2,7 +2,7 @@ from django.urls import include, path, re_path from django.views.generic import TemplateView -from .views import availability, capabilities, datalink +from .views import availability, capabilities, datalink, datalink_semantics from .viewsets import SyncDatalinkJobViewSet app_name = 'datalink' @@ -12,6 +12,7 @@ urlpatterns = [ path('', TemplateView.as_view(template_name='datalink/root.html'), name='root'), + path('semantics', datalink_semantics, name='datalink-semantics'), path('/', datalink, name='datalink'), path('availability', availability, name='availability'), path('capabilities', capabilities, name='capabilities'), diff --git a/daiquiri/datalink/views.py b/daiquiri/datalink/views.py index 8dc393a7..a74c5b75 100644 --- a/daiquiri/datalink/views.py +++ b/daiquiri/datalink/views.py @@ -4,14 +4,19 @@ from daiquiri.core.renderers.vosi import AvailabilityRenderer, CapabilitiesRenderer from .adapter import DatalinkAdapter +from .settings import DATALINK_CUSTOM_SEMANTICS from .vo import get_availability, get_capabilities def datalink(request, ID): adapter = DatalinkAdapter() context = adapter.get_context_data(request, ID=ID) + context['custom_semantics'] = DATALINK_CUSTOM_SEMANTICS return render(request, 'datalink/datalink.html', context) +def datalink_semantics(request): + context = { 'custom_semantics': DATALINK_CUSTOM_SEMANTICS } + return render(request, 'datalink/datalink-semantics.html', context) def availability(request): return HttpResponse(AvailabilityRenderer().render(get_availability()), content_type="application/xml")