Skip to content

Commit

Permalink
feat(apis_entities): adapt merge form to use new enrich view
Browse files Browse the repository at this point in the history
  • Loading branch information
b1rger committed Oct 2, 2024
1 parent c0b459d commit ba7ad4c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 19 deletions.
15 changes: 3 additions & 12 deletions apis_core/apis_entities/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,14 @@
from django.contrib.contenttypes.models import ContentType
from django.urls import reverse

from apis_core.generic.forms.fields import ModelImportChoiceField


class EntitiesMergeForm(forms.Form):
def __init__(self, *args, **kwargs):
if "instance" in kwargs:
instance = kwargs.pop("instance")
super().__init__(*args, **kwargs)
ct = ContentType.objects.get_for_model(instance)
self.fields["uri"] = ModelImportChoiceField(
self.fields["uri"] = forms.ModelChoiceField(
queryset=ct.model_class().objects.all()
)
uri = reverse("apis_core:generic:autocomplete", args=[ct])
Expand All @@ -25,15 +23,8 @@ def __init__(self, *args, **kwargs):
}
self.fields["uri"].widget = autocomplete.ModelSelect2(uri, attrs=attrs)
self.fields["uri"].widget.choices = self.fields["uri"].choices
entitytype = instance._meta.verbose_name
help_text = f"""The attributes of the source {entitytype} you
choose will be copied/moved to this one and the source
{entitytype} will then be deleted."""
self.fields["uri"].help_text = help_text
self.fields["uri"].label = "Merge with..."
self.helper = FormHelper()
self.helper.form_method = "GET"
self.helper.add_input(Submit("submit", "Submit"))
self.helper.form_action = reverse(
"apis_core:apis_entities:generic_entities_merge_view",
args=[instance.__class__.__name__.lower(), instance.pk],
)
self.helper.form_action = instance.get_enrich_url()
7 changes: 0 additions & 7 deletions apis_core/apis_entities/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,6 @@ def get_duplicate_url(self):
kwargs={"contenttype": entity, "pk": self.id},
)

def get_merge_url(self):
entity = self.__class__.__name__.lower()
return reverse(
"apis_core:apis_entities:generic_entities_merge_view",
kwargs={"contenttype": entity, "pk": self.id},
)

def merge_start_date_written(self, other):
self.start_date_written = self.start_date_written or other.start_date_written

Expand Down

0 comments on commit ba7ad4c

Please sign in to comment.