From 55beb5d3f243f7e7f043841b135a6e6d8866b1cd Mon Sep 17 00:00:00 2001 From: "J.-S. Caux" <J.S.Caux@uva.nl> Date: Sat, 3 Nov 2018 21:45:48 +0100 Subject: [PATCH] Auto prefill merge form; paginate --- .../templates/profiles/profile_duplicate_list.html | 6 ++++++ profiles/templates/profiles/profile_merge.html | 12 ++++++------ profiles/views.py | 10 +++++++--- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/profiles/templates/profiles/profile_duplicate_list.html b/profiles/templates/profiles/profile_duplicate_list.html index 92a3ff558..db8a6d585 100644 --- a/profiles/templates/profiles/profile_duplicate_list.html +++ b/profiles/templates/profiles/profile_duplicate_list.html @@ -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> diff --git a/profiles/templates/profiles/profile_merge.html b/profiles/templates/profiles/profile_merge.html index 5f7bb741d..15e253efb 100644 --- a/profiles/templates/profiles/profile_merge.html +++ b/profiles/templates/profiles/profile_merge.html @@ -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 }} diff --git a/profiles/views.py b/profiles/views.py index 49ef5a114..efdff0069 100644 --- a/profiles/views.py +++ b/profiles/views.py @@ -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 -- GitLab