SciPost Code Repository

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

Add make email primary in profile card

parent d9d97ad6
No related branches found
No related tags found
No related merge requests found
...@@ -91,7 +91,8 @@ class ProfileMergeForm(forms.Form): ...@@ -91,7 +91,8 @@ class ProfileMergeForm(forms.Form):
# Model fields: # Model fields:
if profile_to_merge.expertises: if profile_to_merge.expertises:
for expertise in profile_to_merge.expertises: for expertise in profile_to_merge.expertises:
profile_to_merge_into.expertises.add(expertise) if expertise not in profile_to_merge_into.expertises:
profile_to_merge_into.expertises.append(expertise)
if profile_to_merge.orcid_id and (profile_to_merge_into.orcid_id is None): if profile_to_merge.orcid_id and (profile_to_merge_into.orcid_id is None):
profile_to_merge_into.orcid_id = profile_to_merge.orcid_id profile_to_merge_into.orcid_id = profile_to_merge.orcid_id
if profile_to_merge.webpage and (profile_to_merge_into.webpage is None): if profile_to_merge.webpage and (profile_to_merge_into.webpage is None):
......
...@@ -32,8 +32,9 @@ ...@@ -32,8 +32,9 @@
</td> </td>
<td class="d-flex"> <td class="d-flex">
<form method="post" action="{% url 'profiles:toggle_email_status' profile_mail.id %}">{% csrf_token %}<button type="submit" class="btn btn-link p-0">{{ profile_mail.still_valid|yesno:'Deprecate,Mark valid' }}</button></form> <form method="post" action="{% url 'profiles:toggle_email_status' profile_mail.id %}">{% csrf_token %}<button type="submit" class="btn btn-link">{{ profile_mail.still_valid|yesno:'Deprecate,Mark valid' }}</button></form>
<form method="post" action="{% url 'profiles:delete_profile_email' profile_mail.id %}">{% csrf_token %}<button type="submit" class="btn btn-link text-danger p-0 ml-2" onclick="return confirm('Sure you want to delete {{ profile_mail.email }}?')"><i class="fa fa-trash"></i></button></form> <form method="post" action="{% url 'profiles:email_make_primary' profile_mail.id %}">{% csrf_token %}<button type="submit" class="btn btn-link">Make primary</button></form>
<form method="post" action="{% url 'profiles:delete_profile_email' profile_mail.id %}">{% csrf_token %}<button type="submit" class="btn btn-link text-danger ml-2" onclick="return confirm('Sure you want to delete {{ profile_mail.email }}?')"><i class="fa fa-trash"></i></button></form>
</td> </td>
</tr> </tr>
{% endfor %} {% endfor %}
......
...@@ -57,6 +57,11 @@ urlpatterns = [ ...@@ -57,6 +57,11 @@ urlpatterns = [
views.add_profile_email, views.add_profile_email,
name='add_profile_email' name='add_profile_email'
), ),
url(
r'^emails/(?P<email_id>[0-9]+)/make_primary$',
views.email_make_primary,
name='email_make_primary'
),
url( url(
r'^emails/(?P<email_id>[0-9]+)/toggle$', r'^emails/(?P<email_id>[0-9]+)/toggle$',
views.toggle_email_status, views.toggle_email_status,
......
...@@ -4,6 +4,7 @@ __license__ = "AGPL v3" ...@@ -4,6 +4,7 @@ __license__ = "AGPL v3"
from django.contrib import messages from django.contrib import messages
from django.core.urlresolvers import reverse, reverse_lazy from django.core.urlresolvers import reverse, reverse_lazy
from django.db import transaction
from django.db.models import Q, Count from django.db.models import Q, Count
from django.db.models.functions import Concat from django.db.models.functions import Concat
from django.shortcuts import get_object_or_404, render, redirect from django.shortcuts import get_object_or_404, render, redirect
...@@ -249,9 +250,6 @@ class ProfileDuplicateListView(PermissionsMixin, ListView): ...@@ -249,9 +250,6 @@ class ProfileDuplicateListView(PermissionsMixin, ListView):
nr_count=Count('full_name') nr_count=Count('full_name')
).filter(nr_count__gt=1) ).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])
# duplicates = Profile.objects.values('last_name').annotate(
# nr=Count('last_name')).filter(nr__gt=1)
# queryset = Profile.objects.filter(last_name__in=[item['last_name'] for item in duplicates])
return queryset return queryset
def get_context_data(self, *args, **kwargs): def get_context_data(self, *args, **kwargs):
...@@ -260,6 +258,7 @@ class ProfileDuplicateListView(PermissionsMixin, ListView): ...@@ -260,6 +258,7 @@ class ProfileDuplicateListView(PermissionsMixin, ListView):
return context return context
@transaction.atomic
@permission_required('scipost.can_create_profiles') @permission_required('scipost.can_create_profiles')
def profile_merge(request): def profile_merge(request):
""" """
...@@ -302,6 +301,19 @@ def add_profile_email(request, profile_id): ...@@ -302,6 +301,19 @@ def add_profile_email(request, profile_id):
return redirect(reverse('profiles:profiles')) return redirect(reverse('profiles:profiles'))
@require_POST
@permission_required('scipost.can_create_profiles')
def email_make_primary(request, email_id):
"""
Make this email the primary one for this Profile.
"""
profile_email = get_object_or_404(ProfileEmail, pk=email_id)
ProfileEmail.objects.filter(profile=profile_email.profile).update(primary=False)
profile_email.primary = True
profile_email.save()
return redirect(profile_email.profile.get_absolute_url())
@require_POST @require_POST
@permission_required('scipost.can_create_profiles') @permission_required('scipost.can_create_profiles')
def toggle_email_status(request, email_id): def toggle_email_status(request, email_id):
......
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