From bf2cf9449ed386c3aa1eeb7a00c2cb1546b8b987 Mon Sep 17 00:00:00 2001 From: Birger Schacht Date: Fri, 20 Sep 2024 09:15:36 +0200 Subject: [PATCH] refactor(apis_entities): use mergeform templatetag The new mergeform templatetag allows us to simply include the merge form in the abstractentity_form.html template using the templatetag. This means we don't have to override the view anymore and we can therefore drop the custom EntitiesUpdate view, which was only there to inject the mergeform into the context. Dropping the EntitiesUpdate view also means dropping the custom route pointing to it as well as dropping the `get_edit_url` override of the AbstractEntity. --- apis_core/apis_entities/models.py | 11 ----------- .../apis_core/apis_entities/abstractentity_form.html | 1 + apis_core/apis_entities/urls.py | 6 ------ apis_core/apis_entities/views.py | 9 +-------- 4 files changed, 2 insertions(+), 25 deletions(-) diff --git a/apis_core/apis_entities/models.py b/apis_core/apis_entities/models.py index 1768d8faa..b88d1303b 100644 --- a/apis_core/apis_entities/models.py +++ b/apis_core/apis_entities/models.py @@ -50,17 +50,6 @@ def get_or_create_uri(cls, uri): def get_entity_list_filter(cls): return None - def get_edit_url(self): - """ - We override the edit url, because entities have a - custom view that includes the relations - """ - ct = ContentType.objects.get_for_model(self) - return reverse( - "apis_core:apis_entities:generic_entities_edit_view", - args=[ct.model, self.id], - ) - @functools.cached_property def get_prev_id(self): if NEXT_PREV: diff --git a/apis_core/apis_entities/templates/apis_core/apis_entities/abstractentity_form.html b/apis_core/apis_entities/templates/apis_core/apis_entities/abstractentity_form.html index fb564fda5..19b9f3c57 100644 --- a/apis_core/apis_entities/templates/apis_core/apis_entities/abstractentity_form.html +++ b/apis_core/apis_entities/templates/apis_core/apis_entities/abstractentity_form.html @@ -16,6 +16,7 @@
+ {% mergeform as mergeform %} {% if mergeform %} {% crispy mergeform mergeform.helper %} {% endif %} diff --git a/apis_core/apis_entities/urls.py b/apis_core/apis_entities/urls.py index b1d21ad38..f93b0f67c 100644 --- a/apis_core/apis_entities/urls.py +++ b/apis_core/apis_entities/urls.py @@ -9,7 +9,6 @@ EntitiesAutocomplete, EntitiesDuplicate, EntitiesMerge, - EntitiesUpdate, ) from apis_core.generic.views import Create, Delete, Detail, List @@ -62,11 +61,6 @@ def to_url(self, value): Detail.as_view(), name="generic_entities_detail_view", ), - path( - "/edit/", - EntitiesUpdate.as_view(), - name="generic_entities_edit_view", - ), path( "/delete/", Delete.as_view(), diff --git a/apis_core/apis_entities/views.py b/apis_core/apis_entities/views.py index e6c341af3..e33821868 100644 --- a/apis_core/apis_entities/views.py +++ b/apis_core/apis_entities/views.py @@ -11,14 +11,7 @@ from apis_core.apis_entities.forms import EntitiesMergeForm from apis_core.apis_metainfo.models import RootObject from apis_core.generic.helpers import generate_search_filter -from apis_core.generic.views import GenericModelMixin, Update - - -class EntitiesUpdate(Update): - def get_context_data(self, *args, **kwargs): - context = super().get_context_data(*args, **kwargs) - context["mergeform"] = EntitiesMergeForm(instance=self.get_object()) - return context +from apis_core.generic.views import GenericModelMixin class EntitiesDuplicate(GenericModelMixin, PermissionRequiredMixin, View):