Skip to content

Commit

Permalink
refactor(apis_entities): use mergeform templatetag
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
b1rger committed Sep 23, 2024
1 parent f7c5677 commit bf2cf94
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 25 deletions.
11 changes: 0 additions & 11 deletions apis_core/apis_entities/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
</div>
<div class="card mt-2">
<div class="card-body">
{% mergeform as mergeform %}
{% if mergeform %}
{% crispy mergeform mergeform.helper %}
{% endif %}
Expand Down
6 changes: 0 additions & 6 deletions apis_core/apis_entities/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
EntitiesAutocomplete,
EntitiesDuplicate,
EntitiesMerge,
EntitiesUpdate,
)
from apis_core.generic.views import Create, Delete, Detail, List

Expand Down Expand Up @@ -62,11 +61,6 @@ def to_url(self, value):
Detail.as_view(),
name="generic_entities_detail_view",
),
path(
"<int:pk>/edit/",
EntitiesUpdate.as_view(),
name="generic_entities_edit_view",
),
path(
"<int:pk>/delete/",
Delete.as_view(),
Expand Down
9 changes: 1 addition & 8 deletions apis_core/apis_entities/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit bf2cf94

Please sign in to comment.