Skip to content

Commit

Permalink
code updates (#103)
Browse files Browse the repository at this point in the history
* limit relations to 50

* liniting

* hot fix for event related person filter; removed (hopefully) superfluos code for generic relation table

* some info text if relations are capped

* cap relations in edit views

* 241 add dynamic beacon files (#242)

* adds domain-uri endpoint ToDo: add to documentation

* docu added
  • Loading branch information
csae8092 authored Nov 5, 2024
1 parent d5a2383 commit 2c10f12
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 4 deletions.
7 changes: 5 additions & 2 deletions apis_core/apis_entities/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ def get(self, request, *args, **kwargs):
objects = objects[:20]
disable_sort = True
table = get_generic_relations_table(
relation_class=rel, entity_instance=instance, detail=False, disable_sort=disable_sort
relation_class=rel,
entity_instance=instance,
detail=False,
disable_sort=disable_sort,
)
tb_object = table(data=objects, prefix=prefix)
tb_object_open = request.GET.get(prefix + "page", None)
Expand All @@ -73,7 +76,7 @@ def get(self, request, *args, **kwargs):
tb_object_open,
link_to_relations,
disable_sort,
object_count
object_count,
)
)
form = get_entities_form(entity.title())
Expand Down
34 changes: 33 additions & 1 deletion apis_core/apis_metainfo/views.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import json
import pandas as pd
from typing import Any
from django.conf import settings
from django.contrib.auth.decorators import login_required
from django.http import HttpResponse
from django.http import HttpResponse, Http404, JsonResponse
from django.urls import reverse_lazy
from django.utils.decorators import method_decorator
from django.views.generic.detail import DetailView
from django.views.generic.edit import DeleteView


from browsing.browsing_utils import BaseCreateView, BaseUpdateView

from .forms import UriForm
Expand Down Expand Up @@ -39,6 +42,35 @@ def wikidata_beacon(request):
return HttpResponse(result, content_type="text/plain")


def domain_uris(request, domain):
df = pd.DataFrame(
list(
Uri.objects.filter(domain__icontains=domain).values(
"uri", "entity_id", "entity__name"
)
)
)
if df.empty:
raise Http404
df["entity_id"] = df.apply(
lambda x: f"https://pmb.acdh.oeaw.ac.at/entity/{x['entity_id']}", axis=1
)
format = request.GET.get("format", "csv")
if format not in ["csv", "json"]:
format = "csv"
if format == "csv":
response = HttpResponse(
content_type="text/csv",
headers={"Content-Disposition": f'attachment; filename="{domain}.csv"'},
)
df.to_csv(response, index=False)
else:
df = df.set_index("uri")
out = df.to_json(orient="index")
response = JsonResponse(json.loads(out))
return response


class UriDetailView(DetailView):
model = Uri
template_name = "apis_metainfo/uri_detail.html"
Expand Down
3 changes: 2 additions & 1 deletion apis_core/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from rest_framework import routers

from apis_core.api_routers import views
from apis_core.apis_metainfo.views import beacon, wikidata_beacon
from apis_core.apis_metainfo.views import beacon, wikidata_beacon, domain_uris
from apis_core.apis_vocabularies.api_views import UserViewSet
from apis_core.helper_functions.ContentType import GetContentTypes
from apis_core.apis_entities.autocomplete3 import GenericEntitiesAutocomplete
Expand Down Expand Up @@ -45,6 +45,7 @@
),
path("gnd-beacon/", beacon, name="beacon"),
path("wikidata-beacon/", wikidata_beacon, name="wikidata_beacon"),
path("domain-uris/<str:domain>", domain_uris, name="domain_uris"),
path("labels/", include("apis_core.apis_labels.urls", namespace="apis_labels")),
path("tei/", include("apis_core.apis_tei.tei_urls", namespace="apis_tei")),
path(
Expand Down
5 changes: 5 additions & 0 deletions dumper/templates/dumper/about.html
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,11 @@ <h3>URIs</h3>
href="{% url 'apis_core:wikidata_beacon' %}">BEACON Datei<a /> bezogen werden.</p>
<p>Wikipedia-Einträge werden nicht direkt verlinkt. Auf der linken Seite im Menü eines Wikipedia-Eintrags
steht ein Link auf das entsprechende Wikidata-Objekt.</p>
<p>Konkordanz-Listen zwischen Projekt-URIS und PMB-URIs können nach diesem Schema heruntergeladen werden: <code>https://pmb.acdh.oeaw.ac.at/apis/domain-uris/{projekt-uri-domain}</code>, also z.B:
<ul>
<li><a href="https://pmb.acdh.oeaw.ac.at/apis/domain-uris/hanslick">https://pmb.acdh.oeaw.ac.at/apis/domain-uris/hanslick</a> generiert eine CSV Datei aller PMB Entitiäten die mit einer URI aus dem Hanslick-Online Projekt verbunden sind</li></li>
<li><a href="https://pmb.acdh.oeaw.ac.at/apis/domain-uris/brahms?format=json">https://pmb.acdh.oeaw.ac.at/apis/domain-uris/brahms?format=json</a> generiert eine JSON Datei aller PMB Entitiäten die mit einer URI aus dem Brahms Projekt verbunden sind</li>
</ul></p>

<h3>Zur Personensuche</h3>
<h4>Wien</h4>
Expand Down

0 comments on commit 2c10f12

Please sign in to comment.