Skip to content

Commit

Permalink
refactor api content endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
BernhardKoschicek committed Apr 4, 2024
1 parent 9d3cb19 commit 2ed4244
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 35 deletions.
24 changes: 10 additions & 14 deletions openatlas/api/endpoints/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,42 +28,38 @@ def get() -> tuple[Resource, int] | Response:
'url': g.settings['iiif_url'],
'version': int(g.settings['iiif_version'])}}
if parser['download']:
download(details, backend_details_template(), 'content')
return download(details, backend_details_template(), 'content')
return marshal(details, backend_details_template()), 200


class Classes(Resource):
@staticmethod
def get() -> tuple[Resource, int] | Response:
return marshal([{
"systemClass": class_.name,
"crmClass":
class_.cidoc_class.code if class_.cidoc_class else None,
"view": class_.view,
"standardTypeId": class_.standard_type_id,
"icon": class_.icon,
"en": class_.label}
for class_ in g.classes.values()],
"systemClass": item.name,
"crmClass": item.cidoc_class.code if item.cidoc_class else None,
"view": item.view,
"standardTypeId": item.standard_type_id,
"icon": item.icon,
"en": item.label} for item in g.classes.values()],
class_overview_template()), 200


class ClassMapping(Resource):
@staticmethod
def get() -> tuple[Resource, int] | Response:
parser = locale.parse_args()
results = {
"locale": session['language'],
"results": [{
"label": class_.label,
"systemClass": class_.name,
"crmClass":
class_.cidoc_class.code if class_.cidoc_class else
None,
class_.cidoc_class.code if class_.cidoc_class else None,
"view": class_.view,
"standardTypeId": class_.standard_type_id,
"icon": class_.icon} for class_ in g.classes.values()]}
if parser['download']:
download(results, class_mapping_template(), 'content')
if locale.parse_args()['download']:
return download(results, class_mapping_template(), 'content')
return marshal(results, class_mapping_template()), 200


Expand Down
2 changes: 1 addition & 1 deletion openatlas/api/resources/resolve_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ def get_by_page(

def download(
data: list[Any] | dict[Any, Any],
template: dict[Any, Any],
template: dict[str, Any],
name: str | int) -> Response:
return Response(
json.dumps(marshal(data, template)),
Expand Down
34 changes: 15 additions & 19 deletions openatlas/api/resources/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,44 +304,40 @@ def class_overview_template() -> dict[str, Type[String]]:


def class_mapping_template() -> dict[str, Type[String]]:
classes = {
'label': fields.String,
'systemClass': fields.String,
'crmClass': fields.String,
'view': fields.String,
'standardTypeId': fields.String,
'icon': fields.String}
return {
"locale": fields.String,
'results': fields.List(fields.Nested(classes))}
'results': fields.List(fields.Nested({
'label': fields.String,
'systemClass': fields.String,
'crmClass': fields.String,
'view': fields.String,
'standardTypeId': fields.String,
'icon': fields.String}))}


def backend_details_template() -> dict[str, Type[String]]:
image_processing = {
'enabled': fields.String,
'availableImageSizes': fields.Raw}
iiif = {
'enabled': fields.String,
'url': fields.String,
'version': fields.String}
return {
'version': fields.String,
'apiVersions': fields.Raw,
'siteName': fields.String,
'imageProcessing': fields.Nested(image_processing),
'IIIF': fields.Nested(iiif)}
'imageProcessing': fields.Nested({
'enabled': fields.String,
'availableImageSizes': fields.Raw}),
'IIIF': fields.Nested({
'enabled': fields.String,
'url': fields.String,
'version': fields.String})}


def licensed_file_template(entities: list[Entity]) -> dict[str, Any]:
dict_: dict[str, Any] = defaultdict()
file = {
'display': fields.String,
'thumbnail': fields.String,
'extension': fields.String,
'mimetype': fields.String,
'license': fields.String,
'IIIFManifest': fields.String}

dict_: dict[str, Any] = defaultdict()
for entity in entities:
dict_[str(entity.id)] = fields.Nested(file)
return dict_
2 changes: 1 addition & 1 deletion openatlas/models/openatlas_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class OpenatlasClass:
def __init__(
self,
name: str,
cidoc_class: str,
cidoc_class: str | None,
hierarchies: list[int],
alias_allowed: bool,
reference_system_allowed: bool,
Expand Down

0 comments on commit 2ed4244

Please sign in to comment.