SciPost Code Repository

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

Improvements

parent 7660dbc5
No related branches found
No related tags found
No related merge requests found
......@@ -16,7 +16,10 @@
<div class="row">
<div class="col-12">
<p>
View Profiles <a href="{% add_get_parameters contributor=True %}">with</a> or <a href="{% add_get_parameters contributor=False %}">without</a> an associated Contributor
<ul>
<li>View only Profiles <a href="{% add_get_parameters contributor=True %}">with</a> or <a href="{% add_get_parameters contributor=False %}">without</a> an associated Contributor</li>
<li><a href="{% url 'profiles:profile_create' from_type='contributor' pk=next_contributor_wo_profile.id %}">Create a Profile</a> for Contributors without one ({{ nr_contributors_wo_profile }} to handle)</li>
</ul>
<ul class="list-inline">
<li class="list-inline-item">
<a href="{% url 'profiles:profiles' %}">View all</a> or view by discipline/subject area:
......
......@@ -8,7 +8,12 @@ from . import views
urlpatterns = [
url(
r'^add/((?P<from_type>[a-z]+)/(?P<pk>[0-9]+))?$',
r"^add/(?P<from_type>[a-z]+)/(?P<pk>[0-9]+)$",
views.ProfileCreateView.as_view(),
name='profile_create'
),
url(
r"^add/$",
views.ProfileCreateView.as_view(),
name='profile_create'
),
......
......@@ -2,6 +2,8 @@ __copyright__ = "Copyright 2016-2018, Stichting SciPost (SciPost Foundation)"
__license__ = "AGPL v3"
import random
from django.core.urlresolvers import reverse_lazy
from django.shortcuts import get_object_or_404, render
from django.views.generic.edit import CreateView, UpdateView, DeleteView
......@@ -32,6 +34,8 @@ class ProfileCreateView(PermissionsMixin, CreateView):
initial = super().get_initial()
from_type = self.kwargs.get('from_type', None)
pk = self.kwargs.get('pk', None)
print(from_type)
print(pk)
if pk:
pk = int(pk)
if from_type == 'contributor':
......@@ -94,4 +98,7 @@ class ProfileListView(PermissionsMixin, ListView):
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['subject_areas'] = SCIPOST_SUBJECT_AREAS
contributors_wo_profile = Contributor.objects.filter(profile=None)
context['nr_contributors_wo_profile'] = contributors_wo_profile.count()
context['next_contributor_wo_profile'] = random.choice(contributors_wo_profile)
return context
......@@ -72,6 +72,10 @@ class Command(BaseCommand):
content_type=content_type)
# Registration and invitations
can_manage_contributors, created = Permission.objects.get_or_create(
codename='can_manage_contributors',
name='Can manage Contributors',
content_type=content_type)
can_vet_registration_requests, created = Permission.objects.get_or_create(
codename='can_vet_registration_requests',
name='Can vet registration requests',
......
......@@ -14,8 +14,16 @@ from .models import Contributor
@receiver(post_save, sender=Profile)
def link_created_profile_to_contributor(sender, instance, created, **kwargs):
"""
When a new Profile is created, it is linked to the corresponding
existing Contributor object.
When a new Profile is created, it is linked to a corresponding
existing Contributor object, provided it is unique (as defined by the email).
If it is not unique, no action is taken.
"""
if created:
Contributor.objects.filter(user__email=instance.email).update(profile=instance)
try:
contributor = Contributor.objects.get(user__email=instance.email)
contributor.profile = instance
contributor.save()
except Contributor.DoesNotExist:
pass
except Contributor.MultipleObjectsReturned:
pass
......@@ -73,6 +73,10 @@ urlpatterns = [
# Contributors:
################
# Contributor info (public view)
url(r'^contributor/(?P<contributor_id>[0-9]+)$', views.contributor_info,
name="contributor_info"),
# Registration
url(r'^register$', views.register, name='register'),
url(r'^thanks_for_registering$',
......@@ -130,10 +134,6 @@ urlpatterns = [
url(r'^unavailable_period/(?P<period_id>[0-9]+)/delete$', views.delete_unavailable_period,
name='delete_unavailable_period'),
# Contributor info
url(r'^contributor/(?P<contributor_id>[0-9]+)$', views.contributor_info,
name="contributor_info"),
# Authorship claims
url(r'^claim_authorships$', views.claim_authorships, name="claim_authorships"),
url(r'^claim_pub_authorship/(?P<publication_id>[0-9]+)/(?P<claim>[0-1])$',
......
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