Skip to content

Commit

Permalink
moved API config to separate config
Browse files Browse the repository at this point in the history
  • Loading branch information
BernhardKoschicek committed Oct 4, 2023
1 parent 2dd27e1 commit 3a9038b
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 45 deletions.
43 changes: 43 additions & 0 deletions config/api_config.py
Original file line number Diff line number Diff line change
@@ -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 = ''
43 changes: 0 additions & 43 deletions config/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'}

Expand Down
1 change: 1 addition & 0 deletions openatlas/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion openatlas/api/formats/linked_places.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
3 changes: 2 additions & 1 deletion openatlas/api/formats/loud.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, \
Expand Down Expand Up @@ -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


Expand Down

0 comments on commit 3a9038b

Please sign in to comment.