From a0c81d39975644f09cc36c45923483725189463e Mon Sep 17 00:00:00 2001 From: csae8092 Date: Fri, 11 Oct 2024 11:30:27 +0200 Subject: [PATCH 1/5] place-x relation views added --- apis_core/apis_relations/models.py | 101 +++++++++++++++++- .../place_event_relation_views.py | 59 ++++++++++ .../place_place_relation_views.py | 59 ++++++++++ .../place_work_relation_views.py | 59 ++++++++++ apis_core/apis_relations/urls.py | 48 +++++++++ templates/partials/navbar.html | 22 ++++ 6 files changed, 345 insertions(+), 3 deletions(-) create mode 100644 apis_core/apis_relations/place_event_relation_views.py create mode 100644 apis_core/apis_relations/place_place_relation_views.py create mode 100644 apis_core/apis_relations/place_work_relation_views.py diff --git a/apis_core/apis_relations/models.py b/apis_core/apis_relations/models.py index aad9134..d79bb98 100644 --- a/apis_core/apis_relations/models.py +++ b/apis_core/apis_relations/models.py @@ -568,21 +568,116 @@ def get_listview_url(self): class PlacePlace(AbstractRelation): + @classmethod + def get_second_icon(self): + return "bi bi-map apis-place" + + @classmethod + def get_color(self): + return "#5bc0eb" + @classmethod def get_listview_url(self): - return None + return reverse_lazy(f"apis:apis_relations:{self.__name__.lower()}") + + @classmethod + def get_createview_url(self): + return reverse_lazy(f"apis:apis_relations:{self.__name__.lower()}_create") + + def get_object_list_view(self): + list_url = self.get_listview_url() + main_id = self.get_related_entity_instancea().id + return f"{list_url}?source={main_id}&sort=-updated" + + def get_edit_url(self): + return reverse_lazy( + f"apis:apis_relations:{self.__class__.__name__.lower()}_edit", + kwargs={"pk": self.id}, + ) + + def get_copy_url(self): + return reverse_lazy( + "apis:apis_relations:copy_relation", + kwargs={"pk": self.id, "relation_class": self.__class__.__name__.lower()}, + ) class PlaceEvent(AbstractRelation): + @classmethod + def get_icon(self): + return "bi bi-map apis-place" + + @classmethod + def get_second_icon(self): + return "bi bi-calendar3 apis-event" + + @classmethod + def get_color(self): + return "#5bc0eb" + @classmethod def get_listview_url(self): - return None + return reverse_lazy(f"apis:apis_relations:{self.__name__.lower()}") + + @classmethod + def get_createview_url(self): + return reverse_lazy(f"apis:apis_relations:{self.__name__.lower()}_create") + + def get_object_list_view(self): + list_url = self.get_listview_url() + main_id = self.get_related_entity_instancea().id + return f"{list_url}?source={main_id}&sort=-updated" + + def get_edit_url(self): + return reverse_lazy( + f"apis:apis_relations:{self.__class__.__name__.lower()}_edit", + kwargs={"pk": self.id}, + ) + + def get_copy_url(self): + return reverse_lazy( + "apis:apis_relations:copy_relation", + kwargs={"pk": self.id, "relation_class": self.__class__.__name__.lower()}, + ) class PlaceWork(AbstractRelation): + @classmethod + def get_icon(self): + return "bi bi-map apis-place" + + @classmethod + def get_second_icon(self): + return "bi bi-book apis-work" + + @classmethod + def get_color(self): + return "#5bc0eb" + @classmethod def get_listview_url(self): - return None + return reverse_lazy(f"apis:apis_relations:{self.__name__.lower()}") + + @classmethod + def get_createview_url(self): + return reverse_lazy(f"apis:apis_relations:{self.__name__.lower()}_create") + + def get_object_list_view(self): + list_url = self.get_listview_url() + main_id = self.get_related_entity_instancea().id + return f"{list_url}?source={main_id}&sort=-updated" + + def get_edit_url(self): + return reverse_lazy( + f"apis:apis_relations:{self.__class__.__name__.lower()}_edit", + kwargs={"pk": self.id}, + ) + + def get_copy_url(self): + return reverse_lazy( + "apis:apis_relations:copy_relation", + kwargs={"pk": self.id, "relation_class": self.__class__.__name__.lower()}, + ) ####################################################################### diff --git a/apis_core/apis_relations/place_event_relation_views.py b/apis_core/apis_relations/place_event_relation_views.py new file mode 100644 index 0000000..bb21138 --- /dev/null +++ b/apis_core/apis_relations/place_event_relation_views.py @@ -0,0 +1,59 @@ +from django.contrib.auth.decorators import login_required +from django.utils.decorators import method_decorator + +from browsing.browsing_utils import GenericListView, BaseCreateView, BaseUpdateView + +from apis_core.apis_vocabularies.models import PlaceEventRelation +from apis_core.apis_relations.models import PlaceEvent +from apis_core.apis_relations.config import FIELDS_TO_EXCLUDE +from apis_core.apis_relations.utils import ( + generate_relation_form, + generate_relation_filter_formhelper, + generate_relation_filter, + generate_relation_table, +) + + +class PlaceEventCreate(BaseCreateView): + + model = PlaceEvent + form_class = generate_relation_form(PlaceEvent) + + def get_success_url(self): + return self.object.get_object_list_view() + + @method_decorator(login_required) + def dispatch(self, *args, **kwargs): + return super(PlaceEventCreate, self).dispatch(*args, **kwargs) + + +class PlaceEventUpdate(BaseUpdateView): + + model = PlaceEvent + form_class = generate_relation_form(PlaceEvent) + + def get_success_url(self): + return self.object.get_object_list_view() + + @method_decorator(login_required) + def dispatch(self, *args, **kwargs): + return super(PlaceEventUpdate, self).dispatch(*args, **kwargs) + + +class PlaceEventListView(GenericListView): + model = PlaceEvent + filter_class = generate_relation_filter(PlaceEvent, PlaceEventRelation) + formhelper_class = generate_relation_filter_formhelper() + table_class = generate_relation_table(PlaceEvent) + init_columns = [ + "start_date_written", + "end_date_written", + "source", + "relation_type", + "target", + "crud", + ] + verbose_name = "Orte und Ereignisse" + exclude_columns = FIELDS_TO_EXCLUDE + enable_merge = False + template_name = "apis_relations/list_view.html" diff --git a/apis_core/apis_relations/place_place_relation_views.py b/apis_core/apis_relations/place_place_relation_views.py new file mode 100644 index 0000000..013e878 --- /dev/null +++ b/apis_core/apis_relations/place_place_relation_views.py @@ -0,0 +1,59 @@ +from django.contrib.auth.decorators import login_required +from django.utils.decorators import method_decorator + +from browsing.browsing_utils import GenericListView, BaseCreateView, BaseUpdateView + +from apis_core.apis_vocabularies.models import PlacePlaceRelation +from apis_core.apis_relations.models import PlacePlace +from apis_core.apis_relations.config import FIELDS_TO_EXCLUDE +from apis_core.apis_relations.utils import ( + generate_relation_form, + generate_relation_filter_formhelper, + generate_relation_filter, + generate_relation_table, +) + + +class PlacePlaceCreate(BaseCreateView): + + model = PlacePlace + form_class = generate_relation_form(PlacePlace) + + def get_success_url(self): + return self.object.get_object_list_view() + + @method_decorator(login_required) + def dispatch(self, *args, **kwargs): + return super(PlacePlaceCreate, self).dispatch(*args, **kwargs) + + +class PlacePlaceUpdate(BaseUpdateView): + + model = PlacePlace + form_class = generate_relation_form(PlacePlace) + + def get_success_url(self): + return self.object.get_object_list_view() + + @method_decorator(login_required) + def dispatch(self, *args, **kwargs): + return super(PlacePlaceUpdate, self).dispatch(*args, **kwargs) + + +class PlacePlaceListView(GenericListView): + model = PlacePlace + filter_class = generate_relation_filter(PlacePlace, PlacePlaceRelation) + formhelper_class = generate_relation_filter_formhelper() + table_class = generate_relation_table(PlacePlace) + init_columns = [ + "start_date_written", + "end_date_written", + "source", + "relation_type", + "target", + "crud", + ] + verbose_name = "Orte und Orte" + exclude_columns = FIELDS_TO_EXCLUDE + enable_merge = False + template_name = "apis_relations/list_view.html" diff --git a/apis_core/apis_relations/place_work_relation_views.py b/apis_core/apis_relations/place_work_relation_views.py new file mode 100644 index 0000000..51c02b2 --- /dev/null +++ b/apis_core/apis_relations/place_work_relation_views.py @@ -0,0 +1,59 @@ +from django.contrib.auth.decorators import login_required +from django.utils.decorators import method_decorator + +from browsing.browsing_utils import GenericListView, BaseCreateView, BaseUpdateView + +from apis_core.apis_vocabularies.models import PlaceWorkRelation +from apis_core.apis_relations.models import PlaceWork +from apis_core.apis_relations.config import FIELDS_TO_EXCLUDE +from apis_core.apis_relations.utils import ( + generate_relation_form, + generate_relation_filter_formhelper, + generate_relation_filter, + generate_relation_table, +) + + +class PlaceWorkCreate(BaseCreateView): + + model = PlaceWork + form_class = generate_relation_form(PlaceWork) + + def get_success_url(self): + return self.object.get_object_list_view() + + @method_decorator(login_required) + def dispatch(self, *args, **kwargs): + return super(PlaceWorkCreate, self).dispatch(*args, **kwargs) + + +class PlaceWorkUpdate(BaseUpdateView): + + model = PlaceWork + form_class = generate_relation_form(PlaceWork) + + def get_success_url(self): + return self.object.get_object_list_view() + + @method_decorator(login_required) + def dispatch(self, *args, **kwargs): + return super(PlaceWorkUpdate, self).dispatch(*args, **kwargs) + + +class PlaceWorkListView(GenericListView): + model = PlaceWork + filter_class = generate_relation_filter(PlaceWork, PlaceWorkRelation) + formhelper_class = generate_relation_filter_formhelper() + table_class = generate_relation_table(PlaceWork) + init_columns = [ + "start_date_written", + "end_date_written", + "source", + "relation_type", + "target", + "crud", + ] + verbose_name = "Orte und Werke" + exclude_columns = FIELDS_TO_EXCLUDE + 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 4bc4e6f..b6df6db 100644 --- a/apis_core/apis_relations/urls.py +++ b/apis_core/apis_relations/urls.py @@ -6,6 +6,9 @@ from . import person_person_relation_views from . import person_institution_relation_views from . import person_event_relation_views +from . import place_place_relation_views +from . import place_event_relation_views +from . import place_work_relation_views from .views import copy_relation @@ -17,6 +20,51 @@ copy_relation, name="copy_relation", ), + path( + "place-work/", + place_work_relation_views.PlaceWorkListView.as_view(), + name="placework", + ), + path( + "place-work/create/", + place_work_relation_views.PlaceWorkCreate.as_view(), + name="placework_create", + ), + path( + "place-work/edit/", + place_work_relation_views.PlaceWorkUpdate.as_view(), + name="placework_edit", + ), + path( + "place-event/", + place_event_relation_views.PlaceEventListView.as_view(), + name="placeevent", + ), + path( + "place-event/create/", + place_event_relation_views.PlaceEventCreate.as_view(), + name="placeevent_create", + ), + path( + "place-event/edit/", + place_event_relation_views.PlaceEventUpdate.as_view(), + name="placeevent_edit", + ), + path( + "place_place/", + place_place_relation_views.PlacePlaceListView.as_view(), + name="placeplace", + ), + path( + "place_place/create/", + place_place_relation_views.PlacePlaceCreate.as_view(), + name="placeplace_create", + ), + path( + "place_place/edit/", + place_place_relation_views.PlacePlaceUpdate.as_view(), + name="placeplace_edit", + ), path( "person-event/", person_event_relation_views.PersonEventListView.as_view(), diff --git a/templates/partials/navbar.html b/templates/partials/navbar.html index 0ea2654..7d64a22 100644 --- a/templates/partials/navbar.html +++ b/templates/partials/navbar.html @@ -112,6 +112,28 @@ +
  • +
  • + + + Orte und Orte + + +
  • +
  • + + + Orte und Werke + + +
  • +
  • + + + Orte und Ereignisse + + +
  • {% if user.is_authenticated %} From 62f605067878a161868a96f61080c7b5d40b0b44 Mon Sep 17 00:00:00 2001 From: csae8092 Date: Fri, 11 Oct 2024 11:53:15 +0200 Subject: [PATCH 2/5] done with instituion-x relation views --- .../institution_event_relation_views.py | 59 ++++++++ .../institution_institution_relation_views.py | 61 ++++++++ .../institution_place_relation_views.py | 59 ++++++++ .../institution_work_relation_views.py | 59 ++++++++ apis_core/apis_relations/models.py | 140 +++++++++++++++++- apis_core/apis_relations/urls.py | 64 ++++++++ apis_core/apis_relations/utils.py | 1 - templates/partials/navbar.html | 21 +++ 8 files changed, 459 insertions(+), 5 deletions(-) create mode 100644 apis_core/apis_relations/institution_event_relation_views.py create mode 100644 apis_core/apis_relations/institution_institution_relation_views.py create mode 100644 apis_core/apis_relations/institution_place_relation_views.py create mode 100644 apis_core/apis_relations/institution_work_relation_views.py diff --git a/apis_core/apis_relations/institution_event_relation_views.py b/apis_core/apis_relations/institution_event_relation_views.py new file mode 100644 index 0000000..3bd03ce --- /dev/null +++ b/apis_core/apis_relations/institution_event_relation_views.py @@ -0,0 +1,59 @@ +from django.contrib.auth.decorators import login_required +from django.utils.decorators import method_decorator + +from browsing.browsing_utils import GenericListView, BaseCreateView, BaseUpdateView + +from apis_core.apis_vocabularies.models import InstitutionEventRelation +from apis_core.apis_relations.models import InstitutionEvent +from apis_core.apis_relations.config import FIELDS_TO_EXCLUDE +from apis_core.apis_relations.utils import ( + generate_relation_form, + generate_relation_filter_formhelper, + generate_relation_filter, + generate_relation_table, +) + + +class InstitutionEventCreate(BaseCreateView): + + model = InstitutionEvent + form_class = generate_relation_form(InstitutionEvent) + + def get_success_url(self): + return self.object.get_object_list_view() + + @method_decorator(login_required) + def dispatch(self, *args, **kwargs): + return super(InstitutionEventCreate, self).dispatch(*args, **kwargs) + + +class InstitutionEventUpdate(BaseUpdateView): + + model = InstitutionEvent + form_class = generate_relation_form(InstitutionEvent) + + def get_success_url(self): + return self.object.get_object_list_view() + + @method_decorator(login_required) + def dispatch(self, *args, **kwargs): + return super(InstitutionEventUpdate, self).dispatch(*args, **kwargs) + + +class InstitutionEventListView(GenericListView): + model = InstitutionEvent + filter_class = generate_relation_filter(InstitutionEvent, InstitutionEventRelation) + formhelper_class = generate_relation_filter_formhelper() + table_class = generate_relation_table(InstitutionEvent) + init_columns = [ + "start_date_written", + "end_date_written", + "source", + "relation_type", + "target", + "crud", + ] + verbose_name = "Institutionen und Ereignisse" + exclude_columns = FIELDS_TO_EXCLUDE + enable_merge = False + template_name = "apis_relations/list_view.html" diff --git a/apis_core/apis_relations/institution_institution_relation_views.py b/apis_core/apis_relations/institution_institution_relation_views.py new file mode 100644 index 0000000..138cf53 --- /dev/null +++ b/apis_core/apis_relations/institution_institution_relation_views.py @@ -0,0 +1,61 @@ +from django.contrib.auth.decorators import login_required +from django.utils.decorators import method_decorator + +from browsing.browsing_utils import GenericListView, BaseCreateView, BaseUpdateView + +from apis_core.apis_vocabularies.models import InstitutionInstitutionRelation +from apis_core.apis_relations.models import InstitutionInstitution +from apis_core.apis_relations.config import FIELDS_TO_EXCLUDE +from apis_core.apis_relations.utils import ( + generate_relation_form, + generate_relation_filter_formhelper, + generate_relation_filter, + generate_relation_table, +) + + +class InstitutionInstitutionCreate(BaseCreateView): + + model = InstitutionInstitution + form_class = generate_relation_form(InstitutionInstitution) + + def get_success_url(self): + return self.object.get_object_list_view() + + @method_decorator(login_required) + def dispatch(self, *args, **kwargs): + return super(InstitutionInstitutionCreate, self).dispatch(*args, **kwargs) + + +class InstitutionInstitutionUpdate(BaseUpdateView): + + model = InstitutionInstitution + form_class = generate_relation_form(InstitutionInstitution) + + def get_success_url(self): + return self.object.get_object_list_view() + + @method_decorator(login_required) + def dispatch(self, *args, **kwargs): + return super(InstitutionInstitutionUpdate, self).dispatch(*args, **kwargs) + + +class InstitutionInstitutionListView(GenericListView): + model = InstitutionInstitution + filter_class = generate_relation_filter( + InstitutionInstitution, InstitutionInstitutionRelation + ) + formhelper_class = generate_relation_filter_formhelper() + table_class = generate_relation_table(InstitutionInstitution) + init_columns = [ + "start_date_written", + "end_date_written", + "source", + "relation_type", + "target", + "crud", + ] + verbose_name = "Institutionen und Institutionen" + exclude_columns = FIELDS_TO_EXCLUDE + enable_merge = False + template_name = "apis_relations/list_view.html" diff --git a/apis_core/apis_relations/institution_place_relation_views.py b/apis_core/apis_relations/institution_place_relation_views.py new file mode 100644 index 0000000..14bb520 --- /dev/null +++ b/apis_core/apis_relations/institution_place_relation_views.py @@ -0,0 +1,59 @@ +from django.contrib.auth.decorators import login_required +from django.utils.decorators import method_decorator + +from browsing.browsing_utils import GenericListView, BaseCreateView, BaseUpdateView + +from apis_core.apis_vocabularies.models import InstitutionPlaceRelation +from apis_core.apis_relations.models import InstitutionPlace +from apis_core.apis_relations.config import FIELDS_TO_EXCLUDE +from apis_core.apis_relations.utils import ( + generate_relation_form, + generate_relation_filter_formhelper, + generate_relation_filter, + generate_relation_table, +) + + +class InstitutionPlaceCreate(BaseCreateView): + + model = InstitutionPlace + form_class = generate_relation_form(InstitutionPlace) + + def get_success_url(self): + return self.object.get_object_list_view() + + @method_decorator(login_required) + def dispatch(self, *args, **kwargs): + return super(InstitutionPlaceCreate, self).dispatch(*args, **kwargs) + + +class InstitutionPlaceUpdate(BaseUpdateView): + + model = InstitutionPlace + form_class = generate_relation_form(InstitutionPlace) + + def get_success_url(self): + return self.object.get_object_list_view() + + @method_decorator(login_required) + def dispatch(self, *args, **kwargs): + return super(InstitutionPlaceUpdate, self).dispatch(*args, **kwargs) + + +class InstitutionPlaceListView(GenericListView): + model = InstitutionPlace + filter_class = generate_relation_filter(InstitutionPlace, InstitutionPlaceRelation) + formhelper_class = generate_relation_filter_formhelper() + table_class = generate_relation_table(InstitutionPlace) + init_columns = [ + "start_date_written", + "end_date_written", + "source", + "relation_type", + "target", + "crud", + ] + verbose_name = "Institutionen und Orte" + exclude_columns = FIELDS_TO_EXCLUDE + enable_merge = False + template_name = "apis_relations/list_view.html" diff --git a/apis_core/apis_relations/institution_work_relation_views.py b/apis_core/apis_relations/institution_work_relation_views.py new file mode 100644 index 0000000..b1049b8 --- /dev/null +++ b/apis_core/apis_relations/institution_work_relation_views.py @@ -0,0 +1,59 @@ +from django.contrib.auth.decorators import login_required +from django.utils.decorators import method_decorator + +from browsing.browsing_utils import GenericListView, BaseCreateView, BaseUpdateView + +from apis_core.apis_vocabularies.models import InstitutionWorkRelation +from apis_core.apis_relations.models import InstitutionWork +from apis_core.apis_relations.config import FIELDS_TO_EXCLUDE +from apis_core.apis_relations.utils import ( + generate_relation_form, + generate_relation_filter_formhelper, + generate_relation_filter, + generate_relation_table, +) + + +class InstitutionWorkCreate(BaseCreateView): + + model = InstitutionWork + form_class = generate_relation_form(InstitutionWork) + + def get_success_url(self): + return self.object.get_object_list_view() + + @method_decorator(login_required) + def dispatch(self, *args, **kwargs): + return super(InstitutionWorkCreate, self).dispatch(*args, **kwargs) + + +class InstitutionWorkUpdate(BaseUpdateView): + + model = InstitutionWork + form_class = generate_relation_form(InstitutionWork) + + def get_success_url(self): + return self.object.get_object_list_view() + + @method_decorator(login_required) + def dispatch(self, *args, **kwargs): + return super(InstitutionWorkUpdate, self).dispatch(*args, **kwargs) + + +class InstitutionWorkListView(GenericListView): + model = InstitutionWork + filter_class = generate_relation_filter(InstitutionWork, InstitutionWorkRelation) + formhelper_class = generate_relation_filter_formhelper() + table_class = generate_relation_table(InstitutionWork) + init_columns = [ + "start_date_written", + "end_date_written", + "source", + "relation_type", + "target", + "crud", + ] + verbose_name = "Institutionen und Werke" + exclude_columns = FIELDS_TO_EXCLUDE + enable_merge = False + template_name = "apis_relations/list_view.html" diff --git a/apis_core/apis_relations/models.py b/apis_core/apis_relations/models.py index d79bb98..5105c64 100644 --- a/apis_core/apis_relations/models.py +++ b/apis_core/apis_relations/models.py @@ -537,27 +537,159 @@ def get_copy_url(self): class InstitutionInstitution(AbstractRelation): + @classmethod + def get_icon(self): + return "bi bi-building-gear apis-institution" + + @classmethod + def get_second_icon(self): + return "bi bi-building-gear apis-institution" + + @classmethod + def get_color(self): + return "#1d3461" + @classmethod def get_listview_url(self): - return None + return reverse_lazy(f"apis:apis_relations:{self.__name__.lower()}") + + @classmethod + def get_createview_url(self): + return reverse_lazy(f"apis:apis_relations:{self.__name__.lower()}_create") + + def get_object_list_view(self): + list_url = self.get_listview_url() + main_id = self.get_related_entity_instancea().id + return f"{list_url}?source={main_id}&sort=-updated" + + def get_edit_url(self): + return reverse_lazy( + f"apis:apis_relations:{self.__class__.__name__.lower()}_edit", + kwargs={"pk": self.id}, + ) + + def get_copy_url(self): + return reverse_lazy( + "apis:apis_relations:copy_relation", + kwargs={"pk": self.id, "relation_class": self.__class__.__name__.lower()}, + ) class InstitutionPlace(AbstractRelation): + @classmethod + def get_icon(self): + return "bi bi-building-gear apis-institution" + + @classmethod + def get_second_icon(self): + return "bi map apis-place" + + @classmethod + def get_color(self): + return "#1d3461" + @classmethod def get_listview_url(self): - return None + return reverse_lazy(f"apis:apis_relations:{self.__name__.lower()}") + + @classmethod + def get_createview_url(self): + return reverse_lazy(f"apis:apis_relations:{self.__name__.lower()}_create") + + def get_object_list_view(self): + list_url = self.get_listview_url() + main_id = self.get_related_entity_instancea().id + return f"{list_url}?source={main_id}&sort=-updated" + + def get_edit_url(self): + return reverse_lazy( + f"apis:apis_relations:{self.__class__.__name__.lower()}_edit", + kwargs={"pk": self.id}, + ) + + def get_copy_url(self): + return reverse_lazy( + "apis:apis_relations:copy_relation", + kwargs={"pk": self.id, "relation_class": self.__class__.__name__.lower()}, + ) class InstitutionEvent(AbstractRelation): + @classmethod + def get_icon(self): + return "bi bi-building-gear apis-institution" + + @classmethod + def get_second_icon(self): + return "bi bi-calendar3 apis-event" + + @classmethod + def get_color(self): + return "#1d3461" + @classmethod def get_listview_url(self): - return None + return reverse_lazy(f"apis:apis_relations:{self.__name__.lower()}") + + @classmethod + def get_createview_url(self): + return reverse_lazy(f"apis:apis_relations:{self.__name__.lower()}_create") + + def get_object_list_view(self): + list_url = self.get_listview_url() + main_id = self.get_related_entity_instancea().id + return f"{list_url}?source={main_id}&sort=-updated" + + def get_edit_url(self): + return reverse_lazy( + f"apis:apis_relations:{self.__class__.__name__.lower()}_edit", + kwargs={"pk": self.id}, + ) + + def get_copy_url(self): + return reverse_lazy( + "apis:apis_relations:copy_relation", + kwargs={"pk": self.id, "relation_class": self.__class__.__name__.lower()}, + ) class InstitutionWork(AbstractRelation): + @classmethod + def get_icon(self): + return "bi bi-building-gear apis-institution" + + @classmethod + def get_second_icon(self): + return "bi book apis-work" + + @classmethod + def get_color(self): + return "#1d3461" + @classmethod def get_listview_url(self): - return None + return reverse_lazy(f"apis:apis_relations:{self.__name__.lower()}") + + @classmethod + def get_createview_url(self): + return reverse_lazy(f"apis:apis_relations:{self.__name__.lower()}_create") + + def get_object_list_view(self): + list_url = self.get_listview_url() + main_id = self.get_related_entity_instancea().id + return f"{list_url}?source={main_id}&sort=-updated" + + def get_edit_url(self): + return reverse_lazy( + f"apis:apis_relations:{self.__class__.__name__.lower()}_edit", + kwargs={"pk": self.id}, + ) + + def get_copy_url(self): + return reverse_lazy( + "apis:apis_relations:copy_relation", + kwargs={"pk": self.id, "relation_class": self.__class__.__name__.lower()}, + ) ####################################################################### diff --git a/apis_core/apis_relations/urls.py b/apis_core/apis_relations/urls.py index b6df6db..e84a8ee 100644 --- a/apis_core/apis_relations/urls.py +++ b/apis_core/apis_relations/urls.py @@ -9,6 +9,10 @@ from . import place_place_relation_views from . import place_event_relation_views from . import place_work_relation_views +from . import institution_institution_relation_views +from . import institution_place_relation_views +from . import institution_work_relation_views +from . import institution_event_relation_views from .views import copy_relation @@ -20,6 +24,66 @@ copy_relation, name="copy_relation", ), + path( + "institution-event/", + institution_event_relation_views.InstitutionEventListView.as_view(), + name="institutionevent", + ), + path( + "institution-event/create/", + institution_event_relation_views.InstitutionEventCreate.as_view(), + name="institutionevent_create", + ), + path( + "institution-event/edit/", + institution_event_relation_views.InstitutionEventUpdate.as_view(), + name="institutionevent_edit", + ), + path( + "institution-work/", + institution_work_relation_views.InstitutionWorkListView.as_view(), + name="institutionwork", + ), + path( + "institution-work/create/", + institution_work_relation_views.InstitutionWorkCreate.as_view(), + name="institutionwork_create", + ), + path( + "institution-work/edit/", + institution_work_relation_views.InstitutionWorkUpdate.as_view(), + name="institutionwork_edit", + ), + path( + "institution-place/", + institution_place_relation_views.InstitutionPlaceListView.as_view(), + name="institutionplace", + ), + path( + "institution-place/create/", + institution_place_relation_views.InstitutionPlaceCreate.as_view(), + name="institutionplace_create", + ), + path( + "institution-place/edit/", + institution_place_relation_views.InstitutionPlaceUpdate.as_view(), + name="institutionplace_edit", + ), + path( + "institution-institution/", + institution_institution_relation_views.InstitutionInstitutionListView.as_view(), + name="institutioninstitution", + ), + path( + "institution-institution/create/", + institution_institution_relation_views.InstitutionInstitutionCreate.as_view(), + name="institutioninstitution_create", + ), + path( + "institution-institution/edit/", + institution_institution_relation_views.InstitutionInstitutionUpdate.as_view(), + name="institutioninstitution_edit", + ), path( "place-work/", place_work_relation_views.PlaceWorkListView.as_view(), diff --git a/apis_core/apis_relations/utils.py b/apis_core/apis_relations/utils.py index 4bbed0e..9c8d727 100644 --- a/apis_core/apis_relations/utils.py +++ b/apis_core/apis_relations/utils.py @@ -232,7 +232,6 @@ def __init__(self, *args, **kwargs): "Datumsfelder", "start_date", "end_date", - "end_end_date", ), ) ) diff --git a/templates/partials/navbar.html b/templates/partials/navbar.html index 7d64a22..27bf237 100644 --- a/templates/partials/navbar.html +++ b/templates/partials/navbar.html @@ -113,6 +113,27 @@
  • + + + Institutionen und Institutionen + + + + + Institutionen und Orte + + + + + Institutionen und Werke + + + + + Institutionen und Ereignisse + + +
  • From 02dac94633b94905defba16dec0367fcae69425f Mon Sep 17 00:00:00 2001 From: csae8092 Date: Fri, 11 Oct 2024 12:17:35 +0200 Subject: [PATCH 3/5] work-x relation views added [skip ci] --- .../event_event_relation_views.py | 59 ++++++++++++++++ .../event_work_relation_views.py | 59 ++++++++++++++++ apis_core/apis_relations/models.py | 70 ++++++++++++++++++- apis_core/apis_relations/urls.py | 32 +++++++++ templates/partials/navbar.html | 11 +++ 5 files changed, 229 insertions(+), 2 deletions(-) create mode 100644 apis_core/apis_relations/event_event_relation_views.py create mode 100644 apis_core/apis_relations/event_work_relation_views.py diff --git a/apis_core/apis_relations/event_event_relation_views.py b/apis_core/apis_relations/event_event_relation_views.py new file mode 100644 index 0000000..5170a56 --- /dev/null +++ b/apis_core/apis_relations/event_event_relation_views.py @@ -0,0 +1,59 @@ +from django.contrib.auth.decorators import login_required +from django.utils.decorators import method_decorator + +from browsing.browsing_utils import GenericListView, BaseCreateView, BaseUpdateView + +from apis_core.apis_vocabularies.models import EventEventRelation +from apis_core.apis_relations.models import EventEvent +from apis_core.apis_relations.config import FIELDS_TO_EXCLUDE +from apis_core.apis_relations.utils import ( + generate_relation_form, + generate_relation_filter_formhelper, + generate_relation_filter, + generate_relation_table, +) + + +class EventEventCreate(BaseCreateView): + + model = EventEvent + form_class = generate_relation_form(EventEvent) + + def get_success_url(self): + return self.object.get_object_list_view() + + @method_decorator(login_required) + def dispatch(self, *args, **kwargs): + return super(EventEventCreate, self).dispatch(*args, **kwargs) + + +class EventEventUpdate(BaseUpdateView): + + model = EventEvent + form_class = generate_relation_form(EventEvent) + + def get_success_url(self): + return self.object.get_object_list_view() + + @method_decorator(login_required) + def dispatch(self, *args, **kwargs): + return super(EventEventUpdate, self).dispatch(*args, **kwargs) + + +class EventEventListView(GenericListView): + model = EventEvent + filter_class = generate_relation_filter(EventEvent, EventEventRelation) + formhelper_class = generate_relation_filter_formhelper() + table_class = generate_relation_table(EventEvent) + init_columns = [ + "start_date_written", + "end_date_written", + "source", + "relation_type", + "target", + "crud", + ] + verbose_name = "Ereignisse und Ereignisse" + exclude_columns = FIELDS_TO_EXCLUDE + enable_merge = False + template_name = "apis_relations/list_view.html" diff --git a/apis_core/apis_relations/event_work_relation_views.py b/apis_core/apis_relations/event_work_relation_views.py new file mode 100644 index 0000000..e33886f --- /dev/null +++ b/apis_core/apis_relations/event_work_relation_views.py @@ -0,0 +1,59 @@ +from django.contrib.auth.decorators import login_required +from django.utils.decorators import method_decorator + +from browsing.browsing_utils import GenericListView, BaseCreateView, BaseUpdateView + +from apis_core.apis_vocabularies.models import EventWorkRelation +from apis_core.apis_relations.models import EventWork +from apis_core.apis_relations.config import FIELDS_TO_EXCLUDE +from apis_core.apis_relations.utils import ( + generate_relation_form, + generate_relation_filter_formhelper, + generate_relation_filter, + generate_relation_table, +) + + +class EventWorkCreate(BaseCreateView): + + model = EventWork + form_class = generate_relation_form(EventWork) + + def get_success_url(self): + return self.object.get_object_list_view() + + @method_decorator(login_required) + def dispatch(self, *args, **kwargs): + return super(EventWorkCreate, self).dispatch(*args, **kwargs) + + +class EventWorkUpdate(BaseUpdateView): + + model = EventWork + form_class = generate_relation_form(EventWork) + + def get_success_url(self): + return self.object.get_object_list_view() + + @method_decorator(login_required) + def dispatch(self, *args, **kwargs): + return super(EventWorkUpdate, self).dispatch(*args, **kwargs) + + +class EventWorkListView(GenericListView): + model = EventWork + filter_class = generate_relation_filter(EventWork, EventWorkRelation) + formhelper_class = generate_relation_filter_formhelper() + table_class = generate_relation_table(EventWork) + init_columns = [ + "start_date_written", + "end_date_written", + "source", + "relation_type", + "target", + "crud", + ] + verbose_name = "Ereignisse und Werke" + exclude_columns = FIELDS_TO_EXCLUDE + enable_merge = False + template_name = "apis_relations/list_view.html" diff --git a/apis_core/apis_relations/models.py b/apis_core/apis_relations/models.py index 5105c64..3d015b4 100644 --- a/apis_core/apis_relations/models.py +++ b/apis_core/apis_relations/models.py @@ -820,15 +820,81 @@ def get_copy_url(self): class EventEvent(AbstractRelation): + @classmethod + def get_icon(self): + return "bi bi-calendar3 apis-event" + + @classmethod + def get_second_icon(self): + return "bi bi-calendar3 apis-event" + + @classmethod + def get_color(self): + return "#9bc53d" + @classmethod def get_listview_url(self): - return None + return reverse_lazy(f"apis:apis_relations:{self.__name__.lower()}") + + @classmethod + def get_createview_url(self): + return reverse_lazy(f"apis:apis_relations:{self.__name__.lower()}_create") + + def get_object_list_view(self): + list_url = self.get_listview_url() + main_id = self.get_related_entity_instancea().id + return f"{list_url}?source={main_id}&sort=-updated" + + def get_edit_url(self): + return reverse_lazy( + f"apis:apis_relations:{self.__class__.__name__.lower()}_edit", + kwargs={"pk": self.id}, + ) + + def get_copy_url(self): + return reverse_lazy( + "apis:apis_relations:copy_relation", + kwargs={"pk": self.id, "relation_class": self.__class__.__name__.lower()}, + ) class EventWork(AbstractRelation): + @classmethod + def get_icon(self): + return "bi bi-calendar3 apis-event" + + @classmethod + def get_second_icon(self): + return "bi bi-book apis-work" + + @classmethod + def get_color(self): + return "#9bc53d" + @classmethod def get_listview_url(self): - return None + return reverse_lazy(f"apis:apis_relations:{self.__name__.lower()}") + + @classmethod + def get_createview_url(self): + return reverse_lazy(f"apis:apis_relations:{self.__name__.lower()}_create") + + def get_object_list_view(self): + list_url = self.get_listview_url() + main_id = self.get_related_entity_instancea().id + return f"{list_url}?source={main_id}&sort=-updated" + + def get_edit_url(self): + return reverse_lazy( + f"apis:apis_relations:{self.__class__.__name__.lower()}_edit", + kwargs={"pk": self.id}, + ) + + def get_copy_url(self): + return reverse_lazy( + "apis:apis_relations:copy_relation", + kwargs={"pk": self.id, "relation_class": self.__class__.__name__.lower()}, + ) ####################################################################### diff --git a/apis_core/apis_relations/urls.py b/apis_core/apis_relations/urls.py index e84a8ee..7005064 100644 --- a/apis_core/apis_relations/urls.py +++ b/apis_core/apis_relations/urls.py @@ -13,6 +13,8 @@ from . import institution_place_relation_views from . import institution_work_relation_views from . import institution_event_relation_views +from . import event_event_relation_views +from . import event_work_relation_views from .views import copy_relation @@ -24,6 +26,36 @@ copy_relation, name="copy_relation", ), + path( + "event-work/", + event_work_relation_views.EventWorkListView.as_view(), + name="eventwork", + ), + path( + "event-work/create/", + event_work_relation_views.EventWorkCreate.as_view(), + name="eventwork_create", + ), + path( + "event-work/edit/", + event_work_relation_views.EventWorkUpdate.as_view(), + name="eventwork_edit", + ), + path( + "event-event/", + event_event_relation_views.EventEventListView.as_view(), + name="eventevent", + ), + path( + "event-event/create/", + event_event_relation_views.EventEventCreate.as_view(), + name="eventevent_create", + ), + path( + "event-event/edit/", + event_event_relation_views.EventEventUpdate.as_view(), + name="eventevent_edit", + ), path( "institution-event/", institution_event_relation_views.InstitutionEventListView.as_view(), diff --git a/templates/partials/navbar.html b/templates/partials/navbar.html index 27bf237..3381e36 100644 --- a/templates/partials/navbar.html +++ b/templates/partials/navbar.html @@ -155,6 +155,17 @@
  • +
  • + + + Ereignisse und Ereignisse + + + + + Ereignisse und Werke + + {% if user.is_authenticated %} From 4116ab79e9545db95980b5b97d37dca85a539136 Mon Sep 17 00:00:00 2001 From: csae8092 Date: Fri, 11 Oct 2024 12:21:36 +0200 Subject: [PATCH 4/5] finished with relation views --- apis_core/apis_relations/models.py | 35 ++++++++++- apis_core/apis_relations/urls.py | 16 +++++ .../work_work_relation_views.py | 59 +++++++++++++++++++ templates/partials/navbar.html | 6 ++ 4 files changed, 115 insertions(+), 1 deletion(-) create mode 100644 apis_core/apis_relations/work_work_relation_views.py diff --git a/apis_core/apis_relations/models.py b/apis_core/apis_relations/models.py index 3d015b4..18ef741 100644 --- a/apis_core/apis_relations/models.py +++ b/apis_core/apis_relations/models.py @@ -905,6 +905,39 @@ def get_copy_url(self): class WorkWork(AbstractRelation): + @classmethod + def get_icon(self): + return "bi bi-book apis-work" + + @classmethod + def get_second_icon(self): + return "bi bi-book apis-work" + + @classmethod + def get_color(self): + return "#ff8600" + @classmethod def get_listview_url(self): - return None + return reverse_lazy(f"apis:apis_relations:{self.__name__.lower()}") + + @classmethod + def get_createview_url(self): + return reverse_lazy(f"apis:apis_relations:{self.__name__.lower()}_create") + + def get_object_list_view(self): + list_url = self.get_listview_url() + main_id = self.get_related_entity_instancea().id + return f"{list_url}?source={main_id}&sort=-updated" + + def get_edit_url(self): + return reverse_lazy( + f"apis:apis_relations:{self.__class__.__name__.lower()}_edit", + kwargs={"pk": self.id}, + ) + + def get_copy_url(self): + return reverse_lazy( + "apis:apis_relations:copy_relation", + kwargs={"pk": self.id, "relation_class": self.__class__.__name__.lower()}, + ) diff --git a/apis_core/apis_relations/urls.py b/apis_core/apis_relations/urls.py index 7005064..ecae910 100644 --- a/apis_core/apis_relations/urls.py +++ b/apis_core/apis_relations/urls.py @@ -15,6 +15,7 @@ from . import institution_event_relation_views from . import event_event_relation_views from . import event_work_relation_views +from . import work_work_relation_views from .views import copy_relation @@ -26,6 +27,21 @@ copy_relation, name="copy_relation", ), + path( + "work-work/", + work_work_relation_views.WorkWorkListView.as_view(), + name="workwork", + ), + path( + "work-work/create/", + work_work_relation_views.WorkWorkCreate.as_view(), + name="workwork_create", + ), + path( + "work-work/edit/", + work_work_relation_views.WorkWorkUpdate.as_view(), + name="workwork_edit", + ), path( "event-work/", event_work_relation_views.EventWorkListView.as_view(), diff --git a/apis_core/apis_relations/work_work_relation_views.py b/apis_core/apis_relations/work_work_relation_views.py new file mode 100644 index 0000000..40dd5b8 --- /dev/null +++ b/apis_core/apis_relations/work_work_relation_views.py @@ -0,0 +1,59 @@ +from django.contrib.auth.decorators import login_required +from django.utils.decorators import method_decorator + +from browsing.browsing_utils import GenericListView, BaseCreateView, BaseUpdateView + +from apis_core.apis_vocabularies.models import WorkWorkRelation +from apis_core.apis_relations.models import WorkWork +from apis_core.apis_relations.config import FIELDS_TO_EXCLUDE +from apis_core.apis_relations.utils import ( + generate_relation_form, + generate_relation_filter_formhelper, + generate_relation_filter, + generate_relation_table, +) + + +class WorkWorkCreate(BaseCreateView): + + model = WorkWork + form_class = generate_relation_form(WorkWork) + + def get_success_url(self): + return self.object.get_object_list_view() + + @method_decorator(login_required) + def dispatch(self, *args, **kwargs): + return super(WorkWorkCreate, self).dispatch(*args, **kwargs) + + +class WorkWorkUpdate(BaseUpdateView): + + model = WorkWork + form_class = generate_relation_form(WorkWork) + + def get_success_url(self): + return self.object.get_object_list_view() + + @method_decorator(login_required) + def dispatch(self, *args, **kwargs): + return super(WorkWorkUpdate, self).dispatch(*args, **kwargs) + + +class WorkWorkListView(GenericListView): + model = WorkWork + filter_class = generate_relation_filter(WorkWork, WorkWorkRelation) + formhelper_class = generate_relation_filter_formhelper() + table_class = generate_relation_table(WorkWork) + init_columns = [ + "start_date_written", + "end_date_written", + "source", + "relation_type", + "target", + "crud", + ] + verbose_name = "Werke und Werke" + exclude_columns = FIELDS_TO_EXCLUDE + enable_merge = False + template_name = "apis_relations/list_view.html" diff --git a/templates/partials/navbar.html b/templates/partials/navbar.html index 3381e36..9913826 100644 --- a/templates/partials/navbar.html +++ b/templates/partials/navbar.html @@ -166,6 +166,12 @@ Ereignisse und Werke +
  • + + + Werke und Werke + + {% if user.is_authenticated %} From d73fdb8ef32f9e0a6a3d63bb1426e3fdd78b81c3 Mon Sep 17 00:00:00 2001 From: csae8092 Date: Fri, 11 Oct 2024 12:54:41 +0200 Subject: [PATCH 5/5] added delete methods --- apis_core/apis_relations/models.py | 90 ++++++++++++++++++++++++++++++ apis_core/apis_relations/urls.py | 7 ++- apis_core/apis_relations/utils.py | 4 +- apis_core/apis_relations/views.py | 22 ++++++++ 4 files changed, 121 insertions(+), 2 deletions(-) diff --git a/apis_core/apis_relations/models.py b/apis_core/apis_relations/models.py index 18ef741..f10a251 100644 --- a/apis_core/apis_relations/models.py +++ b/apis_core/apis_relations/models.py @@ -370,6 +370,12 @@ def get_copy_url(self): kwargs={"pk": self.id, "relation_class": self.__class__.__name__.lower()}, ) + def get_delete_url(self): + return reverse_lazy( + "apis:apis_relations:generic_delete_relation", + kwargs={"pk": self.id, "relation_class": self.__class__.__name__.lower()}, + ) + class PersonPlace(AbstractRelation): @@ -410,6 +416,12 @@ def get_copy_url(self): kwargs={"pk": self.id, "relation_class": self.__class__.__name__.lower()}, ) + def get_delete_url(self): + return reverse_lazy( + "apis:apis_relations:generic_delete_relation", + kwargs={"pk": self.id, "relation_class": self.__class__.__name__.lower()}, + ) + class PersonInstitution(AbstractRelation): @classmethod @@ -449,6 +461,12 @@ def get_copy_url(self): kwargs={"pk": self.id, "relation_class": self.__class__.__name__.lower()}, ) + def get_delete_url(self): + return reverse_lazy( + "apis:apis_relations:generic_delete_relation", + kwargs={"pk": self.id, "relation_class": self.__class__.__name__.lower()}, + ) + class PersonEvent(AbstractRelation): @classmethod @@ -488,6 +506,12 @@ def get_copy_url(self): kwargs={"pk": self.id, "relation_class": self.__class__.__name__.lower()}, ) + def get_delete_url(self): + return reverse_lazy( + "apis:apis_relations:generic_delete_relation", + kwargs={"pk": self.id, "relation_class": self.__class__.__name__.lower()}, + ) + class PersonWork(AbstractRelation): @@ -528,6 +552,12 @@ def get_copy_url(self): kwargs={"pk": self.id, "relation_class": self.__class__.__name__.lower()}, ) + def get_delete_url(self): + return reverse_lazy( + "apis:apis_relations:generic_delete_relation", + kwargs={"pk": self.id, "relation_class": self.__class__.__name__.lower()}, + ) + ####################################################################### # @@ -574,6 +604,12 @@ def get_copy_url(self): kwargs={"pk": self.id, "relation_class": self.__class__.__name__.lower()}, ) + def get_delete_url(self): + return reverse_lazy( + "apis:apis_relations:generic_delete_relation", + kwargs={"pk": self.id, "relation_class": self.__class__.__name__.lower()}, + ) + class InstitutionPlace(AbstractRelation): @classmethod @@ -613,6 +649,12 @@ def get_copy_url(self): kwargs={"pk": self.id, "relation_class": self.__class__.__name__.lower()}, ) + def get_delete_url(self): + return reverse_lazy( + "apis:apis_relations:generic_delete_relation", + kwargs={"pk": self.id, "relation_class": self.__class__.__name__.lower()}, + ) + class InstitutionEvent(AbstractRelation): @classmethod @@ -652,6 +694,12 @@ def get_copy_url(self): kwargs={"pk": self.id, "relation_class": self.__class__.__name__.lower()}, ) + def get_delete_url(self): + return reverse_lazy( + "apis:apis_relations:generic_delete_relation", + kwargs={"pk": self.id, "relation_class": self.__class__.__name__.lower()}, + ) + class InstitutionWork(AbstractRelation): @classmethod @@ -691,6 +739,12 @@ def get_copy_url(self): kwargs={"pk": self.id, "relation_class": self.__class__.__name__.lower()}, ) + def get_delete_url(self): + return reverse_lazy( + "apis:apis_relations:generic_delete_relation", + kwargs={"pk": self.id, "relation_class": self.__class__.__name__.lower()}, + ) + ####################################################################### # @@ -733,6 +787,12 @@ def get_copy_url(self): kwargs={"pk": self.id, "relation_class": self.__class__.__name__.lower()}, ) + def get_delete_url(self): + return reverse_lazy( + "apis:apis_relations:generic_delete_relation", + kwargs={"pk": self.id, "relation_class": self.__class__.__name__.lower()}, + ) + class PlaceEvent(AbstractRelation): @classmethod @@ -772,6 +832,12 @@ def get_copy_url(self): kwargs={"pk": self.id, "relation_class": self.__class__.__name__.lower()}, ) + def get_delete_url(self): + return reverse_lazy( + "apis:apis_relations:generic_delete_relation", + kwargs={"pk": self.id, "relation_class": self.__class__.__name__.lower()}, + ) + class PlaceWork(AbstractRelation): @classmethod @@ -811,6 +877,12 @@ def get_copy_url(self): kwargs={"pk": self.id, "relation_class": self.__class__.__name__.lower()}, ) + def get_delete_url(self): + return reverse_lazy( + "apis:apis_relations:generic_delete_relation", + kwargs={"pk": self.id, "relation_class": self.__class__.__name__.lower()}, + ) + ####################################################################### # @@ -857,6 +929,12 @@ def get_copy_url(self): kwargs={"pk": self.id, "relation_class": self.__class__.__name__.lower()}, ) + def get_delete_url(self): + return reverse_lazy( + "apis:apis_relations:generic_delete_relation", + kwargs={"pk": self.id, "relation_class": self.__class__.__name__.lower()}, + ) + class EventWork(AbstractRelation): @classmethod @@ -896,6 +974,12 @@ def get_copy_url(self): kwargs={"pk": self.id, "relation_class": self.__class__.__name__.lower()}, ) + def get_delete_url(self): + return reverse_lazy( + "apis:apis_relations:generic_delete_relation", + kwargs={"pk": self.id, "relation_class": self.__class__.__name__.lower()}, + ) + ####################################################################### # @@ -941,3 +1025,9 @@ def get_copy_url(self): "apis:apis_relations:copy_relation", kwargs={"pk": self.id, "relation_class": self.__class__.__name__.lower()}, ) + + def get_delete_url(self): + return reverse_lazy( + "apis:apis_relations:generic_delete_relation", + kwargs={"pk": self.id, "relation_class": self.__class__.__name__.lower()}, + ) diff --git a/apis_core/apis_relations/urls.py b/apis_core/apis_relations/urls.py index ecae910..bd45080 100644 --- a/apis_core/apis_relations/urls.py +++ b/apis_core/apis_relations/urls.py @@ -16,12 +16,17 @@ from . import event_event_relation_views from . import event_work_relation_views from . import work_work_relation_views -from .views import copy_relation +from .views import copy_relation, GenericRelationDeleteView app_name = "apis_relations" urlpatterns = [ + path( + "delete//", + GenericRelationDeleteView.as_view(), + name="generic_delete_relation", + ), path( "copy//", copy_relation, diff --git a/apis_core/apis_relations/utils.py b/apis_core/apis_relations/utils.py index 9c8d727..abd5898 100644 --- a/apis_core/apis_relations/utils.py +++ b/apis_core/apis_relations/utils.py @@ -62,7 +62,9 @@ class MyTable(tables.Table): - + + + """, verbose_name="Ändern, Kopieren oder Löschen", orderable=False, diff --git a/apis_core/apis_relations/views.py b/apis_core/apis_relations/views.py index 5ae38c8..1802b53 100644 --- a/apis_core/apis_relations/views.py +++ b/apis_core/apis_relations/views.py @@ -2,11 +2,14 @@ import re from django.apps import apps + from django.contrib.auth.decorators import login_required from django.contrib.contenttypes.models import ContentType from django.http import Http404, HttpResponse from django.shortcuts import get_object_or_404, redirect from django.template import loader +from django.views.generic.edit import DeleteView + from apis_core.apis_entities.models import ( AbstractEntity, @@ -53,6 +56,25 @@ def copy_relation(request, relation_class, pk): return redirect(original_object.get_edit_url()) +class GenericRelationDeleteView(DeleteView): + template_name = "apis_entities/confirm_delete.html" + + def get_model(self): + model_name = self.kwargs.get("relation_class") + model = apps.get_model(app_label="apis_relations", model_name=model_name) + return model + + def get_object(self): + model = self.get_model() + obj = get_object_or_404(model, pk=self.kwargs["pk"]) + return obj + + def get_success_url(self): + obj = self.get_object() + url = obj.get_listview_url() + return url + + def turn_form_modules_into_dict(form_module_list): """ Since form classes are loaded dynamically from the respective modules and it's settings-dependent which modules