-
Notifications
You must be signed in to change notification settings - Fork 11
/
__init__.py
57 lines (44 loc) · 1.75 KB
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import logging
import requests
from cachecontrol import CacheControl
from cachecontrol.heuristics import ExpiresAfter
from skosprovider.registry import Registry
from skosprovider_getty.providers import AATProvider
from skosprovider_getty.providers import TGNProvider
from sqlalchemy.orm import Session
from atramhasis import utils
from atramhasis.data.datamanagers import ProviderDataManager
log = logging.getLogger(__name__)
LICENSES = [
'https://creativecommons.org/licenses/by/4.0/',
'http://data.vlaanderen.be/doc/licentie/modellicentie-gratis-hergebruik/v1.0'
]
def register_providers_from_db(registry: Registry, session: Session) -> None:
"""
Retrieve all providers stored in the database and add them to the registry.
:param registry: The registry to which the providers will be added.
:param session: A database session.
"""
manager = ProviderDataManager(session)
for db_provider in manager.get_all_providers():
provider = utils.db_provider_to_skosprovider(db_provider)
registry.register_provider(provider)
def create_registry(request):
try:
registry = Registry(instance_scope='threaded_thread')
getty_session = CacheControl(requests.Session(), heuristic=ExpiresAfter(weeks=1))
aat = AATProvider(
{'id': 'AAT', 'subject': ['external']},
session=getty_session
)
tgn = TGNProvider(
{'id': 'TGN', 'subject': ['external']},
session=getty_session
)
registry.register_provider(aat)
registry.register_provider(tgn)
register_providers_from_db(registry, request.db)
return registry
except AttributeError:
log.exception("Attribute error during creation of Registry.")
raise