Skip to content

Commit

Permalink
Merge pull request #83 from arthur-schnitzler/main
Browse files Browse the repository at this point in the history
updates
  • Loading branch information
csae8092 authored May 8, 2024
2 parents ffe8ebf + 564060e commit 196508b
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions apis_core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,30 @@

from apis_core.apis_metainfo.models import TempEntityClass, Uri

entity_list = ["place", "person", "work", "event", "institution"]


def get_object_from_pk_or_uri(pk):
"""checks if the given pk exists, if not checks if a matching apis-default uri exists
and returns its entity"""
try:
instance = TempEntityClass.objects_inheritance.get_subclass(pk=pk)
instance = TempEntityClass.objects_inheritance.select_subclasses(
*entity_list
).get(pk=pk)
return instance
except ObjectDoesNotExist:
domain = "https://pmb.acdh.oeaw.ac.at/"
new_uri = f"{domain}entity/{pk}/"
uri2 = Uri.objects.filter(uri=new_uri)
if uri2.count() == 1:
instance = TempEntityClass.objects_inheritance.get_subclass(
pk=uri2[0].entity_id
)
instance = TempEntityClass.objects_inheritance.select_subclasses(
*entity_list
).get(pk=uri2[0].entity_id)
elif uri2.count() == 0:
temp_obj = get_object_or_404(Uri, uri=new_uri[:-1])
instance = TempEntityClass.objects_inheritance.get_subclass(
pk=temp_obj.entity_id
)
instance = TempEntityClass.objects_inheritance.select_subclasses(
*entity_list
).get(pk=temp_obj.entity_id)
else:
raise Http404
return instance

0 comments on commit 196508b

Please sign in to comment.