SciPost Code Repository

Skip to content
Snippets Groups Projects
Commit 55beb5d3 authored by Jean-Sébastien Caux's avatar Jean-Sébastien Caux
Browse files

Auto prefill merge form; paginate

parent 63ee4319
No related branches found
No related tags found
No related merge requests found
......@@ -28,6 +28,12 @@
{% endfor %}
</ul>
{% if is_paginated %}
<div class="col-12">
{% include 'partials/pagination.html' with page_obj=page_obj %}
</div>
{% endif %}
</div>
</div>
......
......@@ -15,15 +15,15 @@
{% block content %}
<div class="row">
<div class="col-12">
<h3>Merge Profiles</h3>
<h2>Merge Profiles</h2>
<h4 class="highlight">Profile {{ profile_to_merge.id }}</h4>
<h3 class="highlight">Profile {{ profile_to_merge.id }}</h3>
{% include 'profiles/_profile_card.html' with profile=profile_to_merge %}
<h4 class="highlight">Profile {{ profile_to_merge_into.id }}</h4>
<hr/>
<h3 class="highlight">Profile {{ profile_to_merge_into.id }}</h3>
{% include 'profiles/_profile_card.html' with profile=profile_to_merge_into %}
<h4 class="highlight">Merge:</h4>
<hr/>
<h3 class="highlight">Merge:</h3>
<form action="{% url 'profiles:merge' %}" method="post">
{% csrf_token %}
{{ merge_form }}
......
......@@ -236,25 +236,29 @@ class ProfileListView(PermissionsMixin, PaginationMixin, ListView):
return context
class ProfileDuplicateListView(PermissionsMixin, ListView):
class ProfileDuplicateListView(PermissionsMixin, PaginationMixin, ListView):
"""
List Profiles with potential duplicates; allow to merge if necessary.
"""
permission_required = 'scipost.can_create_profiles'
model = Profile
template_name = 'profiles/profile_duplicate_list.html'
paginate_by = 16
def get_queryset(self):
profiles = Profile.objects.annotate(full_name=Concat('last_name', 'first_name'))
duplicates = profiles.values('full_name').annotate(
nr_count=Count('full_name')
).filter(nr_count__gt=1)
queryset = profiles.filter(full_name__in=[item['full_name'] for item in duplicates])
queryset = profiles.filter(full_name__in=[item['full_name'] for item in duplicates]
).order_by('last_name', '-id')
return queryset
def get_context_data(self, *args, **kwargs):
context = super().get_context_data(*args, **kwargs)
context['merge_form'] = ProfileMergeForm()
initial = {'to_merge': self.object_list[0].id,
'to_merge_into': self.object_list[1].id}
context['merge_form'] = ProfileMergeForm(initial=initial)
return context
......
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