diff --git a/network/templates/network/list_view.html b/network/templates/network/list_view.html index 7787346..701d560 100644 --- a/network/templates/network/list_view.html +++ b/network/templates/network/list_view.html @@ -14,6 +14,7 @@

CSV + TEI JSON Als Netzwerk Als Kalender diff --git a/network/urls.py b/network/urls.py index f0eceb8..9347ff6 100644 --- a/network/urls.py +++ b/network/urls.py @@ -7,6 +7,7 @@ edges_as_geojson, edges_as_calender, MapView, + get_person_person_tei, ) @@ -19,4 +20,5 @@ path("calender-data/", edges_as_calender, name="calender_data"), path("calender/", CalenderView.as_view(), name="calender"), path("map/", MapView.as_view(), name="map"), + path("tei/", get_person_person_tei, name="tei"), ] diff --git a/network/views.py b/network/views.py index 65c2cd8..f46e89b 100644 --- a/network/views.py +++ b/network/views.py @@ -1,10 +1,12 @@ import csv import json import pandas as pd +import lxml.etree as ET from django.apps import apps from django.http import HttpResponse, JsonResponse +from django.utils.text import slugify from django.views.generic import TemplateView - +from acdh_tei_pyutils.tei import TeiReader from browsing.browsing_utils import ( GenericListView, @@ -17,7 +19,61 @@ from network.utils import get_coords, df_to_geojson_vect, iso_to_lat_long +tei_template = """ + + + + + PMB-Beziehungen + + +

Publication Information

+
+ +

PMB-Export

+
+
+
+ + + + + +
+""" + + +def get_person_person_tei(request): + doc = TeiReader(tei_template) + root = doc.any_xpath(".//tei:listRelation")[0] + query_params = request.GET + qs = EdgeListFilter(query_params, queryset=Edge.objects.all()).qs + for x in qs: + relation = ET.SubElement(root, "{http://www.tei-c.org/ns/1.0}relation") + print(x.edge_label) + relation.attrib["name"] = slugify(x.edge_label) + relation.attrib["active"] = f"#pmb{x.source_id}" + relation.attrib["passive"] = f"#pmb{x.target_id}" + if x.start_date: + relation.attrib["from-iso"] = f"{x.start_date}" + if x.end_date: + relation.attrib["to-iso"] = f"{x.end_date}" + relation.attrib["n"] = f"{x.target_label} — {x.edge_label} — {x.source_label}" + xml_str = doc.return_string() + return HttpResponse(xml_str, content_type="application/xml") + + class NetworkView(TemplateView): + """ + A Django view that renders the network template and provides context data for the template. + Attributes: + template_name (str): The path to the template used by this view. + Methods: + get_context_data(**kwargs): + Retrieves context data for the template, including a list of models with their associated + color, icon, and verbose name. Models that do not have these attributes are skipped. + """ + template_name = "network/network.html" def get_context_data(self, **kwargs): @@ -69,7 +125,7 @@ def edges_as_calender(request): .exclude(start_date__lte="0001-01-01") ) values_list = [x.name for x in Edge._meta.get_fields()] - qs = EdgeListFilter(request.GET, queryset=queryset).qs + qs = EdgeListFilter(query_params, queryset=queryset).qs items = list(qs.values_list(*values_list)) df = pd.DataFrame(list(items), columns=values_list) start_date = str(df["start_date"].min())