Skip to content

Commit

Permalink
Merge pull request #93 from arthur-schnitzler/main
Browse files Browse the repository at this point in the history
code updates
  • Loading branch information
csae8092 authored Oct 10, 2024
2 parents 91bfa91 + 88e5043 commit f4b5f27
Show file tree
Hide file tree
Showing 7 changed files with 384 additions and 16 deletions.
12 changes: 12 additions & 0 deletions apis_core/apis_entities/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down Expand Up @@ -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()
Expand Down
80 changes: 66 additions & 14 deletions apis_core/apis_relations/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -359,15 +373,33 @@ 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):
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"


#######################################################################
Expand All @@ -378,19 +410,27 @@ class PersonWork(AbstractRelation):


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


#######################################################################
Expand All @@ -401,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


#######################################################################
Expand All @@ -420,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


#######################################################################
Expand All @@ -435,4 +485,6 @@ class EventWork(AbstractRelation):


class WorkWork(AbstractRelation):
pass
@classmethod
def get_listview_url(self):
return None
139 changes: 139 additions & 0 deletions apis_core/apis_relations/person_person_relation_views.py
Original file line number Diff line number Diff line change
@@ -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(
"""<a href="{{ record.related_persona.get_absolute_url }}">{{ record.related_persona }}</a>""",
verbose_name="Person",
)
related_personb = tables.TemplateColumn(
"""<a href="{{ record.related_personb.get_absolute_url }}">{{ record.related_personb }}</a>""",
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"
File renamed without changes.
Loading

0 comments on commit f4b5f27

Please sign in to comment.