SciPost Code Repository

Skip to content
Snippets Groups Projects
Commit a6d74210 authored by George Katsikas's avatar George Katsikas :goat:
Browse files

feat: :sparkles: specify optional merge profile duplicate ids

parent ec52839c
No related branches found
No related tags found
No related merge requests found
......@@ -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 %}
......
......@@ -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,
......
......@@ -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,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment