Skip to content

Commit

Permalink
Merge pull request #2 from acdh-oeaw/1-incorporate-apis
Browse files Browse the repository at this point in the history
moved apis into codebase; updated to latest django; switched to PostgreSQL
app not working
  • Loading branch information
csae8092 authored Nov 17, 2023
2 parents cfc621e + 9fca506 commit 7a0d875
Show file tree
Hide file tree
Showing 289 changed files with 72,446 additions and 57 deletions.
8 changes: 4 additions & 4 deletions .env
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
APIS_DB_NAME=pmb
APIS_DB_USER=pmb
APIS_DB_PASSWORD=pmb
APIS_DB_HOST=172.17.0.1
POSTGRES_DB=pmb
POSTGRES_USER=pmb
POSTGRES_PASSWORD=pmb
POSTGRES_HOST=172.17.0.1
DEBUG=True
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,5 @@ requirements_dev.txt
media/pmb-log.csv
media/professions.csv
hansi.csv
pmb_dump.sql
apis_core/.DS_Store
2 changes: 2 additions & 0 deletions apis_core/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{
}
1 change: 1 addition & 0 deletions apis_core/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__version__ = '0.10.2'
54 changes: 54 additions & 0 deletions apis_core/api_renderers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import re
from collections import OrderedDict

from rest_framework import renderers


class NetJsonRenderer(renderers.JSONRenderer):
media_type = "application/json"
format = "json+net"

def render(self, data, media_type=None, renderer_context=None):
try:
test = re.search(r"/relations/([^/]+)/", data["results"][0]["url"])
except IndexError:
return super().render(
data, accepted_media_type=media_type, renderer_context=renderer_context
)
if test:
rel = test.group(1)
for r in data["results"][0].keys():
if r.startswith("related_"):
r2 = r.split("_")[1]
rel2 = re.match("^{}[a-z]*".format(r2), rel)
if rel2:
source = r
elif r.endswith('A'):
source = r
elif r.endswith('B'):
target = r
rel2 = re.match("^[a-z]*?{}$".format(r2), rel)
if rel2:
target = r
results2 = []
for d in data["results"]:
d2 = OrderedDict(
[
("target", v)
if k == target
else ("source", v)
if k == source
else (k, v)
for k, v in d.items()
]
)
if d2["source"] is None or d2["target"] is None: #fix needed to not get 500s if relations without source or target exist in the data
continue
target_type = d2["target"]["url"].split("/")[-3].title()
source_type = d2["source"]["url"].split("/")[-3].title()
d2["target"]["type"] = target_type
d2["source"]["type"] = source_type
results2.append(d2)
data["results"] = results2
res3 = super().render(data, accepted_media_type=media_type, renderer_context=renderer_context)
return res3
Loading

0 comments on commit 7a0d875

Please sign in to comment.