Skip to content

Commit

Permalink
Merge pull request #75 from arthur-schnitzler/main
Browse files Browse the repository at this point in the history
updates
  • Loading branch information
csae8092 authored Mar 5, 2024
2 parents 377c400 + f8d8beb commit 5400454
Show file tree
Hide file tree
Showing 15 changed files with 449 additions and 25 deletions.
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,12 @@ in order to avoid errors on a new instance you'll need to set an environment var

* bundling js-code (used for network-vis) is not part of the docker-setup
* for development make sure the vite-dev-server is running `pnpm run vite`
* for building new bundle, run `pn run build`
* for building new bundle, run `pn run build`


## reset sequence
```SQL
BEGIN;
SELECT setval(pg_get_serial_sequence('"django_migrations"','id'), coalesce(max("id"), 1), max("id") IS NOT null) FROM "django_migrations";
COMMIT;
```
26 changes: 26 additions & 0 deletions apis_core/apis_entities/management/commands/save_all.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import os
import warnings

from datetime import datetime
from tqdm import tqdm
from django.conf import settings
from django.core.management.base import BaseCommand

from apis_core.apis_metainfo.models import TempEntityClass
from dumper.utils import write_report

warnings.filterwarnings("ignore")


class Command(BaseCommand):
help = "saves all TempEntity objects"

def handle(self, *args, **kwargs):
start_time = datetime.now().strftime(settings.PMB_TIME_PATTERN)
items = TempEntityClass.objects.all()
print(f"{items.count()} objects to save")
for x in tqdm(items, total=items.count()):
x.save()
end_time = datetime.now().strftime(settings.PMB_TIME_PATTERN)
report = [os.path.basename(__file__), start_time, end_time]
write_report(report)
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Generated by Django 5.0.1 on 2024-03-01 14:24

from django.db import migrations


class Migration(migrations.Migration):
dependencies = [
("apis_entities", "0002_initial"),
]

operations = [
migrations.AlterModelOptions(
name="event",
options={
"ordering": ["id"],
"verbose_name": "Ereignis",
"verbose_name_plural": "Ereignisse",
},
),
migrations.AlterModelOptions(
name="institution",
options={
"ordering": ["id"],
"verbose_name": "Institution",
"verbose_name_plural": "Institutionen",
},
),
migrations.AlterModelOptions(
name="person",
options={
"ordering": ["id"],
"verbose_name": "Person",
"verbose_name_plural": "Personen",
},
),
migrations.AlterModelOptions(
name="place",
options={
"ordering": ["id"],
"verbose_name": "Ort",
"verbose_name_plural": "Orte",
},
),
migrations.AlterModelOptions(
name="work",
options={
"ordering": ["id"],
"verbose_name": "Werk",
"verbose_name_plural": "Werke",
},
),
]
7 changes: 2 additions & 5 deletions apis_core/apis_entities/resolver_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from django.urls.exceptions import NoReverseMatch

from apis_core.apis_metainfo.models import TempEntityClass, Uri
from apis_core.utils import get_object_from_pk_or_uri


def uri_resolver(request):
Expand Down Expand Up @@ -37,11 +38,7 @@ def uri_resolver(request):


def entity_resolver(request, pk):
try:
TempEntityClass.objects.get(id=pk)
except ObjectDoesNotExist:
raise Http404
entity = TempEntityClass.objects_inheritance.get_subclass(pk=pk)
entity = get_object_from_pk_or_uri(pk)
try:
url = entity.get_absolute_url()
except NoReverseMatch:
Expand Down
14 changes: 14 additions & 0 deletions apis_core/apis_entities/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from apis_core.apis_entities.forms import get_entities_form
from apis_core.apis_entities.models import Person, Place
from apis_core.helper_functions.DateParser import parse_date
from apis_core.apis_metainfo.models import Uri
from normdata.forms import NormDataImportForm
from normdata.utils import (
Expand Down Expand Up @@ -402,3 +403,16 @@ def test_028_beacons(self):
url = reverse("apis_core:wikidata_beacon")
r = client.get(url)
self.assertEqual(r.status_code, 200)

def test_029_parse_date(self):
dates = [
["1900", ["1900-01-01", "1900-01-01", "1900-12-31"]],
["1800-02", ["1800-02-01", "1800-02-01", "1800-02-28"]],
["1800-02-02", ["1800-02-02", "None", "None"]],
["um 1900<1900-03-03>", ["1900-03-03", "None", "None"]],
]
for x in dates:
results = parse_date(x[0])
for i, r in enumerate(results):
date_str = f"{r}"[:10]
self.assertEqual(date_str, x[1][i])
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
# Generated by Django 5.0.1 on 2024-03-01 14:24

from django.db import migrations


class Migration(migrations.Migration):
dependencies = [
("apis_relations", "0002_initial"),
]

operations = [
migrations.AlterModelOptions(
name="eventevent",
options={
"default_manager_name": "objects",
"ordering": ["start_date", "id"],
},
),
migrations.AlterModelOptions(
name="eventwork",
options={
"default_manager_name": "objects",
"ordering": ["start_date", "id"],
},
),
migrations.AlterModelOptions(
name="institutionevent",
options={
"default_manager_name": "objects",
"ordering": ["start_date", "id"],
},
),
migrations.AlterModelOptions(
name="institutioninstitution",
options={
"default_manager_name": "objects",
"ordering": ["start_date", "id"],
},
),
migrations.AlterModelOptions(
name="institutionplace",
options={
"default_manager_name": "objects",
"ordering": ["start_date", "id"],
},
),
migrations.AlterModelOptions(
name="institutionwork",
options={
"default_manager_name": "objects",
"ordering": ["start_date", "id"],
},
),
migrations.AlterModelOptions(
name="personevent",
options={
"default_manager_name": "objects",
"ordering": ["start_date", "id"],
},
),
migrations.AlterModelOptions(
name="personinstitution",
options={
"default_manager_name": "objects",
"ordering": ["start_date", "id"],
},
),
migrations.AlterModelOptions(
name="personperson",
options={
"default_manager_name": "objects",
"ordering": ["start_date", "id"],
},
),
migrations.AlterModelOptions(
name="personplace",
options={
"default_manager_name": "objects",
"ordering": ["start_date", "id"],
},
),
migrations.AlterModelOptions(
name="personwork",
options={
"default_manager_name": "objects",
"ordering": ["start_date", "id"],
},
),
migrations.AlterModelOptions(
name="placeevent",
options={
"default_manager_name": "objects",
"ordering": ["start_date", "id"],
},
),
migrations.AlterModelOptions(
name="placeplace",
options={
"default_manager_name": "objects",
"ordering": ["start_date", "id"],
},
),
migrations.AlterModelOptions(
name="placework",
options={
"default_manager_name": "objects",
"ordering": ["start_date", "id"],
},
),
migrations.AlterModelOptions(
name="workwork",
options={
"default_manager_name": "objects",
"ordering": ["start_date", "id"],
},
),
]
6 changes: 4 additions & 2 deletions apis_core/apis_tei/templates/apis_tei/place.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@
</note>
{% endif %}
{% if object.img_url %}
<figure>
<note type="image">
<figure>
<graphic url="{{ object.img_url }}"/>
</figure>
</figure>
</note>
{% endif %}
</place>
10 changes: 2 additions & 8 deletions apis_core/helper_functions/DateParser.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import math
import re
from datetime import datetime, timedelta
from datetime import datetime


def parse_date(date_string: str) -> (datetime, datetime, datetime):
Expand Down Expand Up @@ -303,12 +302,7 @@ def parse_iso_date(date_string):
if date_ab > date_bis:
raise ValueError("'ab-date' must be before 'bis-date' in time")

# calculate difference between start and end date of range,
# and use it to calculate a single date for usage as median.
days_delta_half = math.floor(
(date_bis - date_ab).days / 2,
)
date_single = date_ab + timedelta(days=days_delta_half)
date_single = date_ab

elif date_ab is not None and date_bis is None:
# date is only the start of a range, save it also as the single date
Expand Down
5 changes: 4 additions & 1 deletion download_files.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@ wget -O /opt/app/media/listorg.xml https://oeawcloud.oeaw.ac.at/index.php/s/a5qC
wget -O /opt/app/media/listbibl.xml https://oeawcloud.oeaw.ac.at/index.php/s/bwT4yWGdBeLkSP3/download/listbibl.xml
wget -O /opt/app/media/listplace.xml https://oeawcloud.oeaw.ac.at/index.php/s/Kbnien5KfnPaFsK/download/listplace.xml
wget -O /opt/app/media/listperson.xml https://oeawcloud.oeaw.ac.at/index.php/s/sRyi2H54eaCiCXJ/download/listperson.xml
wget -O /opt/app/media/relations.csv https://oeawcloud.oeaw.ac.at/index.php/s/2BWWMY8etP6tEj7/download/relations.csv
wget -O /opt/app/media/relations.csv https://oeawcloud.oeaw.ac.at/index.php/s/2BWWMY8etP6tEj7/download/relations.csv
wget -O /opt/app/media/nodes.csv https://oeawcloud.oeaw.ac.at/index.php/s/6nRiLxeDn6skcSN/download/nodes.csv
wget -O /opt/app/media/edges.csv https://oeawcloud.oeaw.ac.at/index.php/s/T8Q76ymStZANDyf/download/edges.csv
wget -O /opt/app/media/relations.gexf https://oeawcloud.oeaw.ac.at/index.php/s/MemNBMyd8HB4Tky/download/relations.gexf
Loading

0 comments on commit 5400454

Please sign in to comment.