Skip to content

Commit

Permalink
Merge pull request #97 from arthur-schnitzler/main
Browse files Browse the repository at this point in the history
code updates
  • Loading branch information
csae8092 authored Oct 26, 2024
2 parents 3511bf7 + e963950 commit 972e6d8
Show file tree
Hide file tree
Showing 11 changed files with 271 additions and 17 deletions.
1 change: 0 additions & 1 deletion apis_core/apis_entities/detail_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ def get(self, request, *args, **kwargs):
table = get_generic_relations_table(
relation_class=rel, entity_instance=instance, detail=True
)
print(match, entity)
if match[0] == entity:
link_to_relations = f"{rel.get_listview_url()}?source={pk}"
rel_type = match[1]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ <h2 class="text-center">Ganz sicher?</h2>
{% csrf_token %}
<div class="row">
<div class="col d-flex justify-content-start">
<input class="btn btn-danger" type="submit" value="Ja ich bin mir ganz sicher" />
<input class="btn btn-danger" type="submit" value="Ja, ich bin sicher" />
</div>
<div class="col d-flex justify-content-end"">
<input class="btn btn-success" type="submit" value="Nein, ich habs mir anders überlegt" onclick="goBack()" />
<input class="btn btn-success" type="submit" value="Nein, lieber doch nicht" onclick="goBack()" />
</div>
</div>

Expand Down
4 changes: 4 additions & 0 deletions apis_core/apis_relations/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,10 @@ def get_related_entity_field_nameb(cls):

class PersonPerson(AbstractRelation):

@classmethod
def get_icon(self):
return "bi bi-people apis-person"

@classmethod
def get_second_icon(self):
return "bi bi-people apis-person"
Expand Down
2 changes: 1 addition & 1 deletion apis_core/apis_relations/person_event_relation_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class PersonEventListView(GenericListView):
"target",
"crud",
]
verbose_name = "Personen und Orte"
verbose_name = "Personen und Ereignisse"
exclude_columns = FIELDS_TO_EXCLUDE
enable_merge = False
template_name = "apis_relations/list_view.html"
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class PersonInstitutionListView(GenericListView):
"target",
"crud",
]
verbose_name = "Personen und Orte"
verbose_name = "Personen und Institutionen"
exclude_columns = FIELDS_TO_EXCLUDE
enable_merge = False
template_name = "apis_relations/list_view.html"
2 changes: 1 addition & 1 deletion apis_core/apis_relations/person_person_relation_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class PersonPersonListView(GenericListView):
"target",
"crud",
]
verbose_name = "Personen und Orte"
verbose_name = "Personen und Personen"
exclude_columns = FIELDS_TO_EXCLUDE
enable_merge = False
template_name = "apis_relations/list_view.html"
2 changes: 1 addition & 1 deletion apis_core/apis_relations/person_work_relation_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class PersonWorkListView(GenericListView):
"target",
"crud",
]
verbose_name = "Personen und Orte"
verbose_name = "Personen und Werke"
exclude_columns = FIELDS_TO_EXCLUDE
enable_merge = False
template_name = "apis_relations/list_view.html"
1 change: 1 addition & 0 deletions apis_core/apis_relations/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class MyTable(tables.Table):

class Meta:
model = MyModelClass
order_by = "-updated"
sequence = (
"id",
"source",
Expand Down
106 changes: 106 additions & 0 deletions notebooks/issue_227_theatre_titles.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "535b021a-300f-4140-96b6-5a50b96336bc",
"metadata": {},
"outputs": [],
"source": [
"# run against production 2024-10-16\n",
"from tqdm import tqdm\n",
"from dumper.utils import gsheet_to_df\n",
"from apis_core.utils import get_object_from_pk_or_uri"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a914f665-cd8b-4698-8499-e4fb92c9f709",
"metadata": {},
"outputs": [],
"source": [
"df = gsheet_to_df(\"1wgLHBHeJECkmgJUIpPdG-JS8F-0ht_LdVTxNmWwW8O0\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "08aefefc-762f-4400-9893-1043d69ca874",
"metadata": {},
"outputs": [],
"source": [
"col, _ = Collection.objects.get_or_create(name=\"Schnitzler-Theater\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d6e188f0-371b-4527-8df1-3758d8eeee85",
"metadata": {},
"outputs": [],
"source": [
"# don't run twice!!!\n",
"pmb_ids = []\n",
"for i, row in tqdm(df.iterrows()):\n",
" work = Work.objects.create(name=row[\"Title\"])\n",
" pmb_ids.append(work.id)\n",
" work.collection.add(col)\n",
" uri, _ = Uri.objects.get_or_create(\n",
" uri=f'https://{row[\"URI\"]}',\n",
" domain=\"schnitzler-theater\",\n",
" entity=work\n",
" )"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a845af15-a476-4e16-a8c1-ed33d1c7da86",
"metadata": {},
"outputs": [],
"source": [
"df[\"pmb_ids\"] = pmb_ids"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b682fa0f-4b92-4f90-b2c8-53d0f9f332a0",
"metadata": {},
"outputs": [],
"source": [
"df.to_csv(\"theater-uris.csv\", index=False)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "63d06a2d-bc85-4ae4-8142-a287f471a2fa",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Django Shell-Plus",
"language": "python",
"name": "django_extensions"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.3"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
145 changes: 145 additions & 0 deletions notebooks/issue__213.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "abdba1e8-027e-4931-a35b-03aaf8aa9464",
"metadata": {},
"outputs": [],
"source": [
"from django.core.exceptions import ObjectDoesNotExist\n",
"from tqdm import tqdm\n",
"from dumper.utils import gsheet_to_df\n",
"from apis_core.utils import get_object_from_pk_or_uri"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "cdb36196-46aa-4b7b-9871-0a8a3dd279ea",
"metadata": {},
"outputs": [],
"source": [
"df = gsheet_to_df(\"1-_WXbdmpLzz_9vBiZ1y9v2tle_26m4tAhPTGzkkin5E\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "682d2d62-1e30-4db5-8323-c07a3f62222e",
"metadata": {},
"outputs": [],
"source": [
"df"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "342c4e3d-39c5-4f8b-b0b0-950cde457983",
"metadata": {},
"outputs": [],
"source": [
"relation_type_lookup = {\n",
" \"1049\": {\n",
" \"relation_type\":PersonWork,\n",
" \"relation\": PersonWorkRelation.objects.get(id=1049),\n",
" \"target_class\": Work\n",
" },\n",
" \"1052\": {\n",
" \"relation_type\": PersonWork,\n",
" \"relation\": PersonWorkRelation.objects.get(id=1052),\n",
" \"target_class\": Work\n",
" },\n",
" \"1053\": {\n",
" \"relation_type\": PersonWork,\n",
" \"relation\": PersonWorkRelation.objects.get(id=1053),\n",
" \"target_class\": Work\n",
" },\n",
" \"1181\": {\n",
" \"relation_type\": PersonPlace,\n",
" \"relation\": PersonPlaceRelation.objects.get(id=1181),\n",
" \"target_class\": Place\n",
" },\n",
" \"1217\": {\n",
" \"relation_type\": PersonWork,\n",
" \"relation\": PersonWorkRelation.objects.get(id=1217),\n",
" \"target_class\": Work\n",
" }\n",
"}"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "6748b522-2617-4436-ab9b-0c46c1867e6a",
"metadata": {},
"outputs": [],
"source": [
"does_not_exist = set()\n",
"for g, ndf in df.groupby(\"relation-id\"):\n",
" relation = relation_type_lookup[str(g)][\"relation\"]\n",
" relation_class = relation_type_lookup[str(g)][\"relation_type\"]\n",
" target_class = relation_type_lookup[str(g)][\"target_class\"]\n",
" print(relation, relation_class, target_class)\n",
" if \"ork\" in relation_class.__name__:\n",
" print(\"work\")\n",
" else:\n",
" print(\"place\")\n",
" for i, row in tqdm(ndf.iterrows(), total=len(ndf)):\n",
" try:\n",
" source = Person.objects.get(pk=row[\"source_id\"])\n",
" except ObjectDoesNotExist:\n",
" does_not_exist.add(row[\"source_id\"])\n",
" continue\n",
" try:\n",
" target = target_class.objects.get(pk=row[\"target_id\"])\n",
" except ObjectDoesNotExist:\n",
" does_not_exist.add(row[\"target_id\"])\n",
" if isinstance(row[\"relation_start_date_written\"], str):\n",
" start_date_written = row[\"relation_start_date_written\"]\n",
" end_date_written = row[\"relation_end_date_written\"]\n",
" else:\n",
" start_date_written = None\n",
" end_date_written = None\n",
" if \"ork\" in relation_class.__name__:\n",
" relation_class.objects.get_or_create(\n",
" related_person=source,\n",
" related_work=target,\n",
" relation_type=relation,\n",
" start_date_written=start_date_written,\n",
" end_date_written=end_date_written\n",
" )\n",
" else:\n",
" relation_class.objects.get_or_create(\n",
" related_person=source,\n",
" related_place=target,\n",
" relation_type=relation,\n",
" start_date_written=start_date_written,\n",
" end_date_written=end_date_written\n",
" )\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Django Shell-Plus",
"language": "python",
"name": "django_extensions"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.3"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
19 changes: 9 additions & 10 deletions templates/partials/navbar.html
Original file line number Diff line number Diff line change
Expand Up @@ -79,37 +79,36 @@
<li>
<a class="dropdown-item" href="{% url 'apis:apis_relations:personperson' %}">
<i class="bi bi-people apis-person"></i>
Personen und Personen
<i class="bi bi-people apis-person"></i>
Personen und <i class="bi bi-people apis-person"></i> Personen</i>
</a>
</li>
<li>
<a class="dropdown-item" href="{% url 'apis:apis_relations:personplace' %}">
<i class="bi bi-people apis-person"></i>
Personen und Orte
<i class="bi bi-map apis-place"></i>
Personen und <i class="bi bi-map apis-place"></i> Orte

</a>
</li>
<li>
<a class="dropdown-item" href="{% url 'apis:apis_relations:personwork' %}">
<i class="bi bi-people apis-person"></i>
Personen und Werke
<i class="bi bi-book apis-work"></i>
Personen und <i class="bi bi-book apis-work"></i> Werke

</a>
</li>
<li>
<a class="dropdown-item" href="{% url 'apis:apis_relations:personevent' %}">
<i class="bi bi-people apis-person"></i>
Personen und Events
<i class="bi bi-calendar3 apis-event"></i>
Personen und <i class="bi bi-calendar3 apis-event"></i> Events

</a>
</li>

<li>
<a class="dropdown-item" href="{% url 'apis:apis_relations:personinstitution' %}">
<i class="bi bi-people apis-person"></i>
Personen und Institutionen
<i class="bi bi-building-gear apis-institution"></i>
Personen und <i class="bi bi-building-gear apis-institution"></i> Institutionen

</a>
</li>
<li><hr class="dropdown-divider"></li>
Expand Down

0 comments on commit 972e6d8

Please sign in to comment.