pub1c-web/app/api/infobases.py

39 lines
1.2 KiB
Python
Raw Normal View History

2021-10-07 10:57:39 +00:00
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
2021-10-07 11:35:46 +00:00
from app.brackets import get_infobases as br_get_infobases
2021-10-07 10:57:39 +00:00
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