create_registry()   A
last analyzed

Complexity

Conditions 2

Size

Total Lines 24
Code Lines 17

Duplication

Lines 24
Ratio 100 %

Importance

Changes 0
Metric Value
cc 2
eloc 17
nop 1
dl 24
loc 24
rs 9.55
c 0
b 0
f 0
1
import logging
2
3
import requests
4
from atramhasis import skos
5
from cachecontrol import CacheControl
6
from cachecontrol.heuristics import ExpiresAfter
7
from skosprovider.registry import Registry
8
from skosprovider_getty.providers import AATProvider
9
from skosprovider_getty.providers import TGNProvider
10
11
log = logging.getLogger(__name__)
12
LICENSES = [
13
    'https://creativecommons.org/licenses/by/4.0/',
14
    'http://data.vlaanderen.be/doc/licentie/modellicentie-gratis-hergebruik/v1.0'
15
]
16
17
18 View Code Duplication
def create_registry(request):
19
    try:
20
        registry = Registry(instance_scope='threaded_thread')
21
22
        getty_session = CacheControl(requests.Session(), heuristic=ExpiresAfter(weeks=1))
23
24
        aat = AATProvider(
25
            {'id': 'AAT', 'subject': ['external']},
26
            session=getty_session
27
        )
28
29
        tgn = TGNProvider(
30
            {'id': 'TGN', 'subject': ['external']},
31
            session=getty_session
32
        )
33
34
        registry.register_provider(aat)
35
        registry.register_provider(tgn)
36
        skos.register_providers_from_db(registry, request.db)
37
38
        return registry
39
    except AttributeError:
40
        log.exception("Attribute error during creation of Registry.")
41
        raise
42