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 %} + +
Term | +Description | +
{{ settings.SITE_URL }}{% url 'datalink:datalink-semantics' %}{{ semantics }} | +{{ description }} | +