39 lines
1.1 KiB
Python
39 lines
1.1 KiB
Python
|
from typing import List, Dict
|
||
|
|
||
|
from flask_restful import Resource
|
||
|
|
||
|
from app.glob import get_config, get_manager
|
||
|
from app.manager import infobase_data_blank
|
||
|
from brackets import get_infobases as br_get_infobases
|
||
|
|
||
|
|
||
|
def load_infobases(config) -> List[str]:
|
||
|
result = []
|
||
|
if 'infobases' in config and 'server_file' in config['infobases']:
|
||
|
result = br_get_infobases(config['infobases']['server_file'])
|
||
|
return result
|
||
|
|
||
|
|
||
|
class InfobasesAvailable(Resource):
|
||
|
def get(self) -> List[str]:
|
||
|
cfg = get_config()
|
||
|
bases = load_infobases(cfg)
|
||
|
return bases
|
||
|
|
||
|
|
||
|
class InfobasesAll(Resource):
|
||
|
def get(self) -> List[Dict[str, str]]:
|
||
|
cfg = get_config()
|
||
|
manager = get_manager()
|
||
|
infobase_names = load_infobases(cfg)
|
||
|
pubs = manager.publications()
|
||
|
result: List[Dict[str, str]] = []
|
||
|
for name in infobase_names:
|
||
|
publicated = False
|
||
|
for pub in filter(lambda x: x["name"] == name, pubs):
|
||
|
publicated = True
|
||
|
result.append(pub)
|
||
|
break
|
||
|
if not publicated:
|
||
|
result.append(infobase_data_blank(name))
|
||
|
return result
|