Skip to content

Commit

Permalink
Merge pull request #67 from arthur-schnitzler/main
Browse files Browse the repository at this point in the history
updates
  • Loading branch information
csae8092 authored Feb 8, 2024
2 parents b855f88 + cda6812 commit 95938d0
Show file tree
Hide file tree
Showing 11 changed files with 127 additions and 505 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -179,3 +179,4 @@ hansi.csv
.docker
media/duplicated_*.csv
Untitled.ipynb
listevent.xml
3 changes: 3 additions & 0 deletions apis_core/apis_entities/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,9 @@ class Meta:
"id",
]

def get_tei_url(self):
return reverse("apis_core:apis_tei:event_as_tei", kwargs={"pk": self.id})

def get_api_url(self):
return f"/apis/api/entities/{self.__class__.__name__.lower()}/{self.id}/"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,11 @@ <h2>
{% block info-metadata %}
<tr>
<th class="w-25">Export</th>
<td>{% if entity_type != 'event' %}
<td>
<a href="{{ object.get_tei_url }}" title="zur TEI-Ansicht der Entität">
<i class="bi bi-filetype-xml"></i> TEI
</a>
|{% endif %}
|
<a href="{{ object.get_api_url }}">
<i class="bi bi-database" title="zur API-Ansicht der Entität"></i> JSON
</a>
Expand Down
2 changes: 1 addition & 1 deletion apis_core/apis_entities/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def test_001a_entity_resolver(self):

url = reverse("entity-resolver", kwargs={"pk": 11})
r = client.get(f"{url}?format=tei")
self.assertEqual(r.status_code, 404)
self.assertEqual(r.status_code, 302)

def test_001_list_view(self):
for x in MODELS:
Expand Down
62 changes: 62 additions & 0 deletions apis_core/apis_tei/management/commands/events_to_tei.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import lxml.etree as ET
from django.core.management.base import BaseCommand
from tqdm import tqdm

from apis_core.apis_entities.models import Event
from apis_core.apis_tei.tei_utils import get_node_from_template, tei_header


class Command(BaseCommand):
help = "Command to serialize APIS Events to XML/TEI places.xml"

def add_arguments(self, parser):
parser.add_argument(
"-l",
"--limit",
action="store_true",
help="number of entities should be limited",
)
parser.add_argument(
"-f",
"--full",
action="store_true",
help="should related entities e.g. birth-places be fully serialized",
)
parser.add_argument(
"--collection",
help="which collection?",
)

def handle(self, *args, **kwargs):
tei_doc = tei_header(title="ListEvent", ent_type="<listEvent/>")
entity_list = tei_doc.xpath("//*[local-name() = 'listEvent']")[0]

if kwargs["full"]:
print("full is set")
full = True
else:
print("simple")
full = False

if kwargs["collection"]:
try:
col_id = int(kwargs["collection"])
except ValueError:
print(
f"collection needs to be an integer and not: {kwargs['collection']}"
)
return False

items = Event.objects.filter(collection=col_id)
else:
items = Event.objects.all()
if kwargs["limit"]:
items = items[:25]
print(f"serialize {items.count()} Events")
for res in tqdm(items, total=len(items)):
item_node = get_node_from_template("apis_tei/event.xml", res, full=full)
entity_list.append(item_node)

with open("listevent.xml", "w") as f:
print(ET.tostring(tei_doc).decode("utf-8"), file=f)
print("done")
Loading

0 comments on commit 95938d0

Please sign in to comment.