From 3b39de98fe2a066c6c033a8b90f2d67ba0f948a6 Mon Sep 17 00:00:00 2001
From: csae8092
Date: Thu, 10 Oct 2024 07:30:28 +0200
Subject: [PATCH 1/2] adds person work relation
---
apis_core/apis_relations/models.py | 16 +-
...iews.py => person_place_relation_views.py} | 1 +
.../person_work_relation_views.py | 139 ++++++++++++++++++
apis_core/apis_relations/urls.py | 10 +-
templates/partials/navbar.html | 7 +
5 files changed, 170 insertions(+), 3 deletions(-)
rename apis_core/apis_relations/{relation_views.py => person_place_relation_views.py} (99%)
create mode 100644 apis_core/apis_relations/person_work_relation_views.py
diff --git a/apis_core/apis_relations/models.py b/apis_core/apis_relations/models.py
index a356bc6..730a734 100644
--- a/apis_core/apis_relations/models.py
+++ b/apis_core/apis_relations/models.py
@@ -367,7 +367,21 @@ class PersonEvent(AbstractRelation):
class PersonWork(AbstractRelation):
- pass
+ @classmethod
+ def get_listview_url(self):
+ return reverse_lazy("apis:apis_relations:person_work")
+
+ @classmethod
+ def get_icon(self):
+ return "bi bi-people apis-person"
+
+ @classmethod
+ def get_second_icon(self):
+ return "bi bi-book apis-work"
+
+ @classmethod
+ def get_color(self):
+ return "#720e07"
#######################################################################
diff --git a/apis_core/apis_relations/relation_views.py b/apis_core/apis_relations/person_place_relation_views.py
similarity index 99%
rename from apis_core/apis_relations/relation_views.py
rename to apis_core/apis_relations/person_place_relation_views.py
index d0b122f..d1cd4ac 100644
--- a/apis_core/apis_relations/relation_views.py
+++ b/apis_core/apis_relations/person_place_relation_views.py
@@ -10,6 +10,7 @@
from apis_core.apis_vocabularies.models import PersonPlaceRelation
from .models import PersonPlace
+from .models import PersonWork
excluded_cols = [
diff --git a/apis_core/apis_relations/person_work_relation_views.py b/apis_core/apis_relations/person_work_relation_views.py
new file mode 100644
index 0000000..b8cd27d
--- /dev/null
+++ b/apis_core/apis_relations/person_work_relation_views.py
@@ -0,0 +1,139 @@
+from browsing.browsing_utils import GenericListView
+from dal import autocomplete
+from crispy_forms.helper import FormHelper
+from crispy_forms.layout import Layout
+from django.urls import reverse_lazy
+from django_filters import FilterSet, ModelMultipleChoiceFilter, RangeFilter
+import django_tables2 as tables
+
+from apis_core.apis_entities.models import Person, Work
+from apis_core.apis_vocabularies.models import PersonWorkRelation
+
+from .models import PersonWork
+
+
+excluded_cols = [
+ "start_start_date",
+ "start_end_date",
+ "end_start_date",
+ "end_end_date",
+ "status",
+ "source",
+ "published",
+ "tempentityclass_ptr",
+ "review",
+]
+
+
+class PersonWorkListFilter(FilterSet):
+ related_person = ModelMultipleChoiceFilter(
+ queryset=Person.objects.all(),
+ help_text="Wähle eine oder mehrere Personen",
+ label="Personen",
+ widget=autocomplete.Select2Multiple(
+ url=reverse_lazy(
+ "apis:apis_entities:generic_entities_autocomplete",
+ kwargs={"entity": "person"},
+ ),
+ attrs={"data-html": True},
+ ),
+ )
+ related_work = ModelMultipleChoiceFilter(
+ queryset=Work.objects.all(),
+ help_text="Wähle einen oder mehrere Werke",
+ label="Werke",
+ widget=autocomplete.Select2Multiple(
+ url=reverse_lazy(
+ "apis:apis_entities:generic_entities_autocomplete",
+ kwargs={"entity": "work"},
+ ),
+ attrs={"data-html": True},
+ ),
+ )
+ relation_type = ModelMultipleChoiceFilter(
+ queryset=PersonWorkRelation.objects.all().order_by("name"),
+ label="Art der Beziehung",
+ help_text="Mehrfachauswahl möglich",
+ )
+ start_date__year = RangeFilter(
+ label="Anfang (Jahr)",
+ )
+ end_date__year = RangeFilter(
+ label="Ende (Jahr)",
+ )
+
+ class Meta:
+ model = PersonWork
+ fields = [
+ "related_person",
+ "related_work",
+ "relation_type",
+ "start_date__year",
+ "end_date__year",
+ ]
+
+
+class PersonWorkFormHelper(FormHelper):
+ def __init__(self, *args, **kwargs):
+ super(PersonWorkFormHelper, self).__init__(*args, **kwargs)
+ self.helper = FormHelper()
+ self.form_class = "genericFilterForm"
+ self.form_method = "GET"
+ self.form_tag = False
+ self.layout = Layout(
+ "related_person",
+ "related_work",
+ "relation_type",
+ "start_date__year",
+ "end_date__year",
+ )
+
+
+class PersonWorkTable(tables.Table):
+ related_person = tables.TemplateColumn(
+ """{{ record.related_person }}""",
+ verbose_name="Person",
+ )
+ related_work = tables.TemplateColumn(
+ """{{ record.related_work }}""",
+ verbose_name="Werk",
+ )
+ relation_type = tables.TemplateColumn(
+ "{{ record.relation_type }}", verbose_name="Art der Beziehung"
+ )
+ start_date_written = tables.TemplateColumn(
+ "{% if record.start_date_written %} {{ record.start_date_written }} {% endif %}",
+ verbose_name="Start",
+ )
+ end_date_written = tables.TemplateColumn(
+ "{% if record.end_date_written %} {{ record.end_date_written }} {% endif %}",
+ verbose_name="End",
+ )
+
+ class Meta:
+ model = PersonWork
+ sequence = (
+ "id",
+ "related_person",
+ "relation_type",
+ "related_work",
+ "start_date_written",
+ )
+
+
+class PersonWorkListView(GenericListView):
+ model = PersonWork
+ filter_class = PersonWorkListFilter
+ formhelper_class = PersonWorkFormHelper
+ table_class = PersonWorkTable
+ init_columns = [
+ "start_date_written",
+ "end_date_written",
+ "related_person",
+ "relation_type",
+ "related_work",
+ ]
+ verbose_name = "Personen und Werke"
+ exclude_columns = excluded_cols
+ enable_merge = False
+ template_name = "apis_relations/list_view.html"
diff --git a/apis_core/apis_relations/urls.py b/apis_core/apis_relations/urls.py
index f8a1342..011dd08 100644
--- a/apis_core/apis_relations/urls.py
+++ b/apis_core/apis_relations/urls.py
@@ -1,16 +1,22 @@
from django.urls import path
from . import views
-from . import relation_views
+from . import person_place_relation_views
+from . import person_work_relation_views
app_name = "apis_relations"
urlpatterns = [
path(
"person-place/",
- relation_views.PersonPlaceListView.as_view(),
+ person_place_relation_views.PersonPlaceListView.as_view(),
name="person_place",
),
+ path(
+ "person-work/",
+ person_work_relation_views.PersonWorkListView.as_view(),
+ name="person_work",
+ ),
path(
"delete//",
views.delete_relation_view,
diff --git a/templates/partials/navbar.html b/templates/partials/navbar.html
index f3f54ea..7e7e5eb 100644
--- a/templates/partials/navbar.html
+++ b/templates/partials/navbar.html
@@ -83,6 +83,13 @@
+
+
+
+ Personen und Werke
+
+
+
{% if user.is_authenticated %}
From 88e5043fe716a24c1324edd83a00a4ad47f2aac7 Mon Sep 17 00:00:00 2001
From: csae8092
Date: Thu, 10 Oct 2024 08:33:51 +0200
Subject: [PATCH 2/2] fixing tests
---
apis_core/apis_entities/tests.py | 12 ++
apis_core/apis_relations/models.py | 64 ++++++--
.../person_person_relation_views.py | 139 ++++++++++++++++++
.../person_place_relation_views.py | 1 -
apis_core/apis_relations/urls.py | 6 +
templates/partials/navbar.html | 7 +
6 files changed, 215 insertions(+), 14 deletions(-)
create mode 100644 apis_core/apis_relations/person_person_relation_views.py
diff --git a/apis_core/apis_entities/tests.py b/apis_core/apis_entities/tests.py
index b46ed07..e816910 100644
--- a/apis_core/apis_entities/tests.py
+++ b/apis_core/apis_entities/tests.py
@@ -26,6 +26,8 @@
MODELS = list(apps.all_models["apis_entities"].values())
+RELATION_MODELS = list(apps.all_models["apis_relations"].values())
+
class EntitiesTestCase(TestCase):
fixtures = [
@@ -70,6 +72,16 @@ def test_001_list_view(self):
response = client.get(url)
self.assertEqual(response.status_code, 200)
+ def test_001a_relation_list_view(self):
+ for x in RELATION_MODELS:
+ try:
+ url = x.get_listview_url()
+ except AttributeError:
+ url = False
+ if url:
+ response = client.get(url)
+ self.assertEqual(response.status_code, 200)
+
def test_002_detailviews(self):
for x in MODELS:
item = x.objects.first()
diff --git a/apis_core/apis_relations/models.py b/apis_core/apis_relations/models.py
index 730a734..80e1274 100644
--- a/apis_core/apis_relations/models.py
+++ b/apis_core/apis_relations/models.py
@@ -337,7 +337,21 @@ def get_related_entity_field_nameb(cls):
class PersonPerson(AbstractRelation):
- pass
+ @classmethod
+ def get_listview_url(self):
+ return reverse_lazy("apis:apis_relations:person_person")
+
+ @classmethod
+ def get_icon(self):
+ return "bi bi-people apis-person"
+
+ @classmethod
+ def get_second_icon(self):
+ return "bi bi-people apis-person"
+
+ @classmethod
+ def get_color(self):
+ return "#720e07"
class PersonPlace(AbstractRelation):
@@ -359,11 +373,15 @@ def get_color(self):
class PersonInstitution(AbstractRelation):
- pass
+ @classmethod
+ def get_listview_url(self):
+ return None
class PersonEvent(AbstractRelation):
- pass
+ @classmethod
+ def get_listview_url(self):
+ return None
class PersonWork(AbstractRelation):
@@ -392,19 +410,27 @@ def get_color(self):
class InstitutionInstitution(AbstractRelation):
- pass
+ @classmethod
+ def get_listview_url(self):
+ return None
class InstitutionPlace(AbstractRelation):
- pass
+ @classmethod
+ def get_listview_url(self):
+ return None
class InstitutionEvent(AbstractRelation):
- pass
+ @classmethod
+ def get_listview_url(self):
+ return None
class InstitutionWork(AbstractRelation):
- pass
+ @classmethod
+ def get_listview_url(self):
+ return None
#######################################################################
@@ -415,15 +441,21 @@ class InstitutionWork(AbstractRelation):
class PlacePlace(AbstractRelation):
- pass
+ @classmethod
+ def get_listview_url(self):
+ return None
class PlaceEvent(AbstractRelation):
- pass
+ @classmethod
+ def get_listview_url(self):
+ return None
class PlaceWork(AbstractRelation):
- pass
+ @classmethod
+ def get_listview_url(self):
+ return None
#######################################################################
@@ -434,11 +466,15 @@ class PlaceWork(AbstractRelation):
class EventEvent(AbstractRelation):
- pass
+ @classmethod
+ def get_listview_url(self):
+ return None
class EventWork(AbstractRelation):
- pass
+ @classmethod
+ def get_listview_url(self):
+ return None
#######################################################################
@@ -449,4 +485,6 @@ class EventWork(AbstractRelation):
class WorkWork(AbstractRelation):
- pass
+ @classmethod
+ def get_listview_url(self):
+ return None
diff --git a/apis_core/apis_relations/person_person_relation_views.py b/apis_core/apis_relations/person_person_relation_views.py
new file mode 100644
index 0000000..7575da6
--- /dev/null
+++ b/apis_core/apis_relations/person_person_relation_views.py
@@ -0,0 +1,139 @@
+from browsing.browsing_utils import GenericListView
+from dal import autocomplete
+from crispy_forms.helper import FormHelper
+from crispy_forms.layout import Layout
+from django.urls import reverse_lazy
+from django_filters import FilterSet, ModelMultipleChoiceFilter, RangeFilter
+import django_tables2 as tables
+
+from apis_core.apis_entities.models import Person
+from apis_core.apis_vocabularies.models import PersonPersonRelation
+
+from .models import PersonPerson
+
+
+excluded_cols = [
+ "start_start_date",
+ "start_end_date",
+ "end_start_date",
+ "end_end_date",
+ "status",
+ "source",
+ "published",
+ "tempentityclass_ptr",
+ "review",
+]
+
+
+class PersonPersonListFilter(FilterSet):
+ related_persona = ModelMultipleChoiceFilter(
+ queryset=Person.objects.all(),
+ help_text="Wähle eine oder mehrere Personen",
+ label="Personen",
+ widget=autocomplete.Select2Multiple(
+ url=reverse_lazy(
+ "apis:apis_entities:generic_entities_autocomplete",
+ kwargs={"entity": "person"},
+ ),
+ attrs={"data-html": True},
+ ),
+ )
+ related_personb = ModelMultipleChoiceFilter(
+ queryset=Person.objects.all(),
+ help_text="Wähle einen oder mehrere Persone",
+ label="Persone",
+ widget=autocomplete.Select2Multiple(
+ url=reverse_lazy(
+ "apis:apis_entities:generic_entities_autocomplete",
+ kwargs={"entity": "person"},
+ ),
+ attrs={"data-html": True},
+ ),
+ )
+ relation_type = ModelMultipleChoiceFilter(
+ queryset=PersonPersonRelation.objects.all().order_by("name"),
+ label="Art der Beziehung",
+ help_text="Mehrfachauswahl möglich",
+ )
+ start_date__year = RangeFilter(
+ label="Anfang (Jahr)",
+ )
+ end_date__year = RangeFilter(
+ label="Ende (Jahr)",
+ )
+
+ class Meta:
+ model = PersonPerson
+ fields = [
+ "related_persona",
+ "related_personb",
+ "relation_type",
+ "start_date__year",
+ "end_date__year",
+ ]
+
+
+class PersonPersonFormHelper(FormHelper):
+ def __init__(self, *args, **kwargs):
+ super(PersonPersonFormHelper, self).__init__(*args, **kwargs)
+ self.helper = FormHelper()
+ self.form_class = "genericFilterForm"
+ self.form_method = "GET"
+ self.form_tag = False
+ self.layout = Layout(
+ "related_persona",
+ "related_personb",
+ "relation_type",
+ "start_date__year",
+ "end_date__year",
+ )
+
+
+class PersonPersonTable(tables.Table):
+ related_persona = tables.TemplateColumn(
+ """{{ record.related_persona }}""",
+ verbose_name="Person",
+ )
+ related_personb = tables.TemplateColumn(
+ """{{ record.related_personb }}""",
+ verbose_name="Person",
+ )
+ relation_type = tables.TemplateColumn(
+ "{{ record.relation_type }}", verbose_name="Art der Beziehung"
+ )
+ start_date_written = tables.TemplateColumn(
+ "{% if record.start_date_written %} {{ record.start_date_written }} {% endif %}",
+ verbose_name="Start",
+ )
+ end_date_written = tables.TemplateColumn(
+ "{% if record.end_date_written %} {{ record.end_date_written }} {% endif %}",
+ verbose_name="End",
+ )
+
+ class Meta:
+ model = PersonPerson
+ sequence = (
+ "id",
+ "related_persona",
+ "relation_type",
+ "related_personb",
+ "start_date_written",
+ )
+
+
+class PersonPersonListView(GenericListView):
+ model = PersonPerson
+ filter_class = PersonPersonListFilter
+ formhelper_class = PersonPersonFormHelper
+ table_class = PersonPersonTable
+ init_columns = [
+ "start_date_written",
+ "end_date_written",
+ "related_persona",
+ "relation_type",
+ "related_personb",
+ ]
+ verbose_name = "Personen und Personen"
+ exclude_columns = excluded_cols
+ enable_merge = False
+ template_name = "apis_relations/list_view.html"
diff --git a/apis_core/apis_relations/person_place_relation_views.py b/apis_core/apis_relations/person_place_relation_views.py
index d1cd4ac..d0b122f 100644
--- a/apis_core/apis_relations/person_place_relation_views.py
+++ b/apis_core/apis_relations/person_place_relation_views.py
@@ -10,7 +10,6 @@
from apis_core.apis_vocabularies.models import PersonPlaceRelation
from .models import PersonPlace
-from .models import PersonWork
excluded_cols = [
diff --git a/apis_core/apis_relations/urls.py b/apis_core/apis_relations/urls.py
index 011dd08..2a4ae99 100644
--- a/apis_core/apis_relations/urls.py
+++ b/apis_core/apis_relations/urls.py
@@ -3,6 +3,7 @@
from . import views
from . import person_place_relation_views
from . import person_work_relation_views
+from . import person_person_relation_views
app_name = "apis_relations"
@@ -17,6 +18,11 @@
person_work_relation_views.PersonWorkListView.as_view(),
name="person_work",
),
+ path(
+ "person-person/",
+ person_person_relation_views.PersonPersonListView.as_view(),
+ name="person_person",
+ ),
path(
"delete//",
views.delete_relation_view,
diff --git a/templates/partials/navbar.html b/templates/partials/navbar.html
index 7e7e5eb..95eef23 100644
--- a/templates/partials/navbar.html
+++ b/templates/partials/navbar.html
@@ -90,6 +90,13 @@
+
+
+
+ Personen und Personen
+
+
+
{% if user.is_authenticated %}