diff --git a/scipost_django/profiles/templates/profiles/profile_duplicates.html b/scipost_django/profiles/templates/profiles/profile_duplicates.html index 10e72204a2a5182823ef0e3dee8d6c5b01d47374..40468916dae0b4ac947a3d045d8d2552358a6b96 100644 --- a/scipost_django/profiles/templates/profiles/profile_duplicates.html +++ b/scipost_django/profiles/templates/profiles/profile_duplicates.html @@ -20,7 +20,13 @@ <div id="merge-form" hx-trigger="intersect once" - hx-get="{% url 'profiles:_hx_profile_merge' to_merge=0 to_merge_into=0 %}"></div> + {% if to_merge and to_merge_into %} + hx-get="{% url 'profiles:_hx_profile_merge' to_merge to_merge_into %}" + {% else %} + hx-get="{% url 'profiles:_hx_profile_merge' %}" + {% endif %} + > + </div> </div> </div> {% endblock content %} diff --git a/scipost_django/profiles/urls.py b/scipost_django/profiles/urls.py index 69fa6aa98e21e921e1baf5bb8f23ac92d5490743..c7eaf73da8b3a5f08f609474fa378dcb61835124 100644 --- a/scipost_django/profiles/urls.py +++ b/scipost_django/profiles/urls.py @@ -67,6 +67,11 @@ urlpatterns = [ ), ), # Duplicates and merging + path( + "duplicates/<int:to_merge>/<int:to_merge_into>", + views.profile_duplicates, + name="duplicates", + ), path("duplicates/", views.profile_duplicates, name="duplicates"), path( "_hx_profile_comparison", @@ -78,6 +83,11 @@ urlpatterns = [ views._hx_profile_merge, name="_hx_profile_merge", ), + path( + "_hx_profile_merge/", + views._hx_profile_merge, + name="_hx_profile_merge", + ), path( "_hx_profile_mark_non_duplicate/<int:profile1>/<int:profile2>", views._hx_profile_mark_non_duplicate, diff --git a/scipost_django/profiles/views.py b/scipost_django/profiles/views.py index 642674456f4e9df76b2339c4494bdbe41f57ae50..1f1222e99488d7411a354ca9ffdc5802beac0c93 100644 --- a/scipost_django/profiles/views.py +++ b/scipost_django/profiles/views.py @@ -332,7 +332,9 @@ class ProfileListView(PermissionsMixin, PaginationMixin, ListView): @login_required @permission_required("scipost.can_merge_profiles") -def profile_duplicates(request): +def profile_duplicates( + request, to_merge: int | None = None, to_merge_into: int | None = None +): """ List Profiles with potential duplicates; allow to merge if necessary. """ @@ -340,7 +342,14 @@ def profile_duplicates(request): # context = { # "profile_duplicates": profile_duplicates, # } - return render(request, "profiles/profile_duplicates.html") + return render( + request, + "profiles/profile_duplicates.html", + { + "to_merge": to_merge, + "to_merge_into": to_merge_into, + }, + ) @transaction.atomic @@ -365,7 +374,9 @@ def _hx_profile_mark_non_duplicate(request, profile1: int, profile2: int): "scipost.can_merge_profiles", "You do not have permission to create profiles.", ) -def _hx_profile_merge(request, to_merge: int, to_merge_into: int): +def _hx_profile_merge( + request, to_merge: int | None = None, to_merge_into: int | None = None +): # Update the post data with the profiles to merge duplicate_profiles = Profile.objects.potential_duplicates() @@ -379,7 +390,13 @@ def _hx_profile_merge(request, to_merge: int, to_merge_into: int): if merge_form.is_valid(): profile = merge_form.save() messages.success(request, "Profiles merged successfully.") - + elif to_merge and to_merge_into: + # A specific pair of profiles to merge was provided, + # fetch the profiles even if they are not duplicates + merge_form = ProfileMergeForm( + queryset=Profile.objects.filter(id__in=[to_merge, to_merge_into]), + initial={"to_merge": to_merge, "to_merge_into": to_merge_into}, + ) else: merge_form = ProfileMergeForm( queryset=duplicate_profiles,