diff --git a/config/api_config.py b/config/api_config.py new file mode 100644 index 000000000..cb8fe3c73 --- /dev/null +++ b/config/api_config.py @@ -0,0 +1,43 @@ +API_CONTEXT = { + 'LPF': 'https://raw.githubusercontent.com/LinkedPasts/linked-places/' + 'master/linkedplaces-context-v1.1.jsonld', + 'LOUD': 'https://linked.art/ns/v1/linked-art.json'} + +CORS_ALLOWANCE = '*' # Cross-Origin source (CORS) +ALLOWED_IPS = ['127.0.0.1'] +API_PROXY = '' + +RDF_FORMATS = { + 'pretty-xml': 'application/rdf+xml', + 'n3': 'text/rdf+n3', + 'turtle': 'application/x-turtle', + 'nt': 'text/plain', + 'xml': 'application/xml'} +JSON_FORMATS = { + 'lp': 'application/ld+json', + 'loud': 'application/ld+json', + 'geojson': 'application/json', + 'geojson-v2': 'application/json'} +API_FORMATS = RDF_FORMATS | JSON_FORMATS + +LOGICAL_OPERATOR: list[str] = ['and', 'or'] +STR_CATEGORIES: list[str] = [ + "entityName", "entityDescription", "entityAliases", "entityCidocClass", + "entitySystemClass", "typeName", "typeNameWithSubs", + "beginFrom", "beginTo", "endFrom", "endTo"] +INT_CATEGORIES: list[str] = [ + "entityID", "typeID", "typeIDWithSubs", "relationToID"] +SET_CATEGORIES: list[str] = ["valueTypeID"] +VALID_CATEGORIES: list[str] = [ + *STR_CATEGORIES, + *INT_CATEGORIES, + *SET_CATEGORIES] +COMPARE_OPERATORS: list[str] = [ + 'equal', 'notEqual', 'greaterThan', 'lesserThan', 'greaterThanEqual', + 'lesserThanEqual', 'like'] + +# Used to connect to ACDH-CH ARCHE systems +ARCHE = {'id': None, 'url': None} + +# Used to connect to password protected Vocabs systems +VOCABS_PASS = '' diff --git a/config/default.py b/config/default.py index 901bfe5d7..aab3fed06 100644 --- a/config/default.py +++ b/config/default.py @@ -56,49 +56,6 @@ REMEMBER_COOKIE_SECURE = True SESSION_COOKIE_SAMESITE = 'Lax' -# API -API_SCHEMA = \ - 'https://raw.githubusercontent.com/LinkedPasts/linked-places' \ - '/master/linkedplaces-context-v1.1.jsonld' -CORS_ALLOWANCE = '*' # Cross-Origin source (CORS) -ALLOWED_IPS = ['127.0.0.1'] -RDF_FORMATS = { - 'pretty-xml': 'application/rdf+xml', - 'n3': 'text/rdf+n3', - 'turtle': 'application/x-turtle', - 'nt': 'text/plain', - 'xml': 'application/xml'} -JSON_FORMATS = { - 'lp': 'application/ld+json', - 'loud': 'application/ld+json', - 'geojson': 'application/json', - 'geojson-v2': 'application/json'} -API_FORMATS = RDF_FORMATS | JSON_FORMATS - -API_PROXY = '' - -LOGICAL_OPERATOR: list[str] = ['and', 'or'] -STR_CATEGORIES: list[str] = [ - "entityName", "entityDescription", "entityAliases", "entityCidocClass", - "entitySystemClass", "typeName", "typeNameWithSubs", - "beginFrom", "beginTo", "endFrom", "endTo"] -INT_CATEGORIES: list[str] = [ - "entityID", "typeID", "typeIDWithSubs", "relationToID"] -SET_CATEGORIES: list[str] = ["valueTypeID"] -VALID_CATEGORIES: list[str] = [ - *STR_CATEGORIES, - *INT_CATEGORIES, - *SET_CATEGORIES] -COMPARE_OPERATORS: list[str] = [ - 'equal', 'notEqual', 'greaterThan', 'lesserThan', 'greaterThanEqual', - 'lesserThanEqual', 'like'] - -# Used to connect to ACDH-CH ARCHE systems -ARCHE = {'id': None, 'url': None} - -# Used to connect to password protected Vocabs systems -VOCABS_PASS = '' - # Table options TABLE_ROWS = {10: '10', 25: '25', 50: '50', 100: '100'} diff --git a/openatlas/__init__.py b/openatlas/__init__.py index 7499955aa..a100dce16 100644 --- a/openatlas/__init__.py +++ b/openatlas/__init__.py @@ -13,6 +13,7 @@ app: Flask = Flask(__name__, instance_relative_config=True) csrf = CSRFProtect(app) # Make sure all forms are CSRF protected app.config.from_object('config.default') +app.config.from_object('config.api_config') app.config.from_pyfile('production.py') app.config['WTF_CSRF_TIME_LIMIT'] = None # Set CSRF token valid for session diff --git a/openatlas/api/formats/linked_places.py b/openatlas/api/formats/linked_places.py index 80323f1ea..7d97fa269 100644 --- a/openatlas/api/formats/linked_places.py +++ b/openatlas/api/formats/linked_places.py @@ -20,7 +20,7 @@ def get_linked_places_entity( links_inverse = entity_dict['links_inverse'] return { 'type': 'FeatureCollection', - '@context': app.config['API_SCHEMA'], + '@context': app.config['API_CONTEXT']['LPF'], 'features': [replace_empty_list_values_in_dict_with_none({ '@id': url_for('view', id_=entity.id, _external=True), 'type': 'Feature', diff --git a/openatlas/api/formats/loud.py b/openatlas/api/formats/loud.py index f4eacbf30..738bcba10 100644 --- a/openatlas/api/formats/loud.py +++ b/openatlas/api/formats/loud.py @@ -3,6 +3,7 @@ from flask import url_for +from openatlas import app from openatlas.display.util import get_file_path from openatlas.models.gis import Gis from openatlas.api.resources.util import remove_spaces_dashes, date_to_str, \ @@ -93,7 +94,7 @@ def get_domain_links() -> dict[str, Any]: "_label": label, "type": "DigitalObject"}]}) - return {'@context': "https://linked.art/ns/v1/linked-art.json"} | \ + return {'@context': app.config['API_CONTEXT']['LOUD']} | \ base_entity_dict() | properties_set # type: ignore