-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from acdh-oeaw/1-incorporate-apis
moved apis into codebase; updated to latest django; switched to PostgreSQL app not working
- Loading branch information
Showing
289 changed files
with
72,446 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,3 +42,5 @@ requirements_dev.txt | |
media/pmb-log.csv | ||
media/professions.csv | ||
hansi.csv | ||
pmb_dump.sql | ||
apis_core/.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
__version__ = '0.10.2' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.