Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/craws/OpenAtlas into dev…
Browse files Browse the repository at this point in the history
…elop
  • Loading branch information
AlexanderWatzinger committed Nov 3, 2023
2 parents 0fe27a7 + 7629133 commit 55f576e
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 26 deletions.
48 changes: 42 additions & 6 deletions config/api.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
API_VERSIONS = ['0.3', '0.4']

API_CONTEXT = {
'LPF': 'https://raw.githubusercontent.com/LinkedPasts/linked-places/'
'master/linkedplaces-context-v1.1.jsonld',
Expand All @@ -22,12 +24,12 @@

LOGICAL_OPERATOR: list[str] = ['and', 'or']
STR_CATEGORIES: list[str] = [
"entityName", "entityDescription", "entityAliases", "entityCidocClass",
"entitySystemClass", "typeName", "typeNameWithSubs",
"beginFrom", "beginTo", "endFrom", "endTo"]
'entityName', 'entityDescription', 'entityAliases', 'entityCidocClass',
'entitySystemClass', 'typeName', 'typeNameWithSubs',
'beginFrom', 'beginTo', 'endFrom', 'endTo']
INT_CATEGORIES: list[str] = [
"entityID", "typeID", "typeIDWithSubs", "relationToID"]
SET_CATEGORIES: list[str] = ["valueTypeID"]
'entityID', 'typeID', 'typeIDWithSubs', 'relationToID']
SET_CATEGORIES: list[str] = ['valueTypeID']
VALID_CATEGORIES: list[str] = [
*STR_CATEGORIES,
*INT_CATEGORIES,
Expand All @@ -41,4 +43,38 @@

# Used to connect to password protected Vocabs systems
VOCABS_PASS = ''
API_VERSIONS = ['0.3']

IMAGE_FORMATS = {
'jpg': 'image/jpeg',
'jpeg': 'image/jpeg',
'jpe': 'image/jpeg',
'jfif': 'image/jpeg',
'pjpeg': 'image/pjpeg',
'pjp': 'image/pjpeg',
'png': 'image/png',
'gif': 'image/gif',
'bmp': 'image/bmp',
'ico': 'image/x-icon',
'tiff': 'image/tiff',
'tif': 'image/tiff',
'webp': 'image/webp',
'svg': 'image/svg+xml',
'svgz': 'image/svg+xml',
'apng': 'image/apng',
'wbmp': 'image/vnd.wap.wbmp',
'xbm': 'image/x-xbitmap',
'avif': 'image/avif',
'heic': 'image/heic',
'heif': 'image/heif',
'jp2': 'image/jp2',
'jpx': 'image/jpx',
'jpm': 'image/jpm',
'jxr': 'image/jxr',
'wdp': 'image/vnd.ms-photo',
'hdp': 'image/vnd.ms-photo',
'bpg': 'image/bpg',
'dib': 'image/bmp',
'jpeg2000': 'image/jpeg2000',
'exr': 'image/aces',
'hdr': 'image/vnd.radiance',
}
64 changes: 44 additions & 20 deletions openatlas/api/formats/loud.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
from collections import defaultdict
from typing import Any, Optional

from flask import url_for
from flask import url_for, g

from openatlas import app
from openatlas.api.resources.util import (
remove_spaces_dashes, date_to_str, get_crm_relation, get_crm_code)
from openatlas.display.util import get_file_path
from openatlas.models.gis import Gis
from openatlas.api.resources.util import remove_spaces_dashes, date_to_str, \
get_crm_relation, get_crm_code
from openatlas.models.entity import Entity
from openatlas.models.gis import Gis
from openatlas.models.type import Type


Expand Down Expand Up @@ -40,9 +40,9 @@ def get_domain_links() -> dict[str, Any]:
property_ = {
'id': url_for('api.entity', id_=link_.domain.id, _external=True),
'type': loud[get_crm_code(link_, True).replace(' ', '_')],
'_label': link_.domain.name, }
if type_ := get_standard_type_loud(link_.domain.types):
property_['classified_as'] = get_type_property(type_)
'_label': link_.domain.name}
if standard_type := get_standard_type_loud(link_.domain.types):
property_['classified_as'] = get_type_property(standard_type)
return property_

for link_ in data['links']:
Expand All @@ -61,6 +61,7 @@ def get_domain_links() -> dict[str, Any]:
base_property = get_range_links()
properties_set[property_name].append(base_property)

image_links = []
for link_ in data['links_inverse']:
if link_.property.code in ['OA7', 'OA8', 'OA9']:
continue
Expand All @@ -78,21 +79,44 @@ def get_domain_links() -> dict[str, Any]:
base_property = get_domain_links()
properties_set[property_name].append(base_property)

if image_id := Entity.get_profile_image_id(data['entity']):
label = ''
for item in properties_set["referred_to_by"]:
if int(item['id'].split("/")[-1]) == image_id:
label = item['_label']
path = get_file_path(image_id)
properties_set['representation'].append({
if link_.domain.class_.name == 'file' and g.files.get(link_.domain.id):
image_links.append(link_)

if image_links:
profile_image = Entity.get_profile_image_id(data['entity'])
print(profile_image)
representation = {
"type": "VisualItem",
"digitally_shown_by": [{
"digitally_shown_by": []}
for link_ in image_links:
id_ = link_.domain.id
suffix = g.files[id_].suffix.replace('.', '')

if not app.config['IMAGE_FORMATS'].get(suffix):
continue

path = get_file_path(id_)
image = {
"id": url_for(
'api.display',
filename=path.stem,
_external=True) if path else "N/A",
"_label": label,
"type": "DigitalObject"}]})
'api.entity',
id_=id_,
_external=True),
"_label": link_.domain.name,
"type": "DigitalObject",
"format": app.config['IMAGE_FORMATS'][suffix],
"access_point": [{
"id": url_for(
'api.display',
filename=path.stem,
_external=True),
"type": "DigitalObject",
"_label": "ProfileImage" if id_ == profile_image else ''}]}

if type_ := get_standard_type_loud(link_.domain.types):
image['classified_as'] = get_type_property(type_)
representation['digitally_shown_by'].append(image)

properties_set['representation'].append(representation)

return {'@context': app.config['API_CONTEXT']['LOUD']} | \
base_entity_dict() | properties_set
Expand Down

0 comments on commit 55f576e

Please sign in to comment.