From e4b7891693277758d2b2c47e30f4ca47a43369e0 Mon Sep 17 00:00:00 2001 From: "J.-S. Caux" <J.S.Caux@uva.nl> Date: Thu, 17 Jan 2019 19:42:41 +0100 Subject: [PATCH] Add more PotFel events stuff --- colleges/constants.py | 6 +++++ colleges/forms.py | 17 ++++++++++---- .../migrations/0013_auto_20190117_1935.py | 20 +++++++++++++++++ .../colleges/_potentialfellowship_card.html | 5 +++-- colleges/views.py | 22 ++++++++++++++----- 5 files changed, 58 insertions(+), 12 deletions(-) create mode 100644 colleges/migrations/0013_auto_20190117_1935.py diff --git a/colleges/constants.py b/colleges/constants.py index f0411a340..46625c019 100644 --- a/colleges/constants.py +++ b/colleges/constants.py @@ -41,6 +41,9 @@ potential_fellowship_statuses_dict = dict(POTENTIAL_FELLOWSHIP_STATUSES) POTENTIAL_FELLOWSHIP_EVENT_DEFINED = 'defined' +POTENTIAL_FELLOWSHIP_EVENT_NOMINATED = 'nominated' +POTENTIAL_FELLOWSHIP_EVENT_VOTED_ON = 'votedon' +POTENTIAL_FELLOWSHIP_EVENT_ELECTED = 'elected' POTENTIAL_FELLOWSHIP_EVENT_EMAILED = 'emailed' POTENTIAL_FELLOWSHIP_EVENT_RESPONDED = 'responded' POTENTIAL_FELLOWSHIP_EVENT_STATUSUPDATED = 'statusupdated' @@ -49,6 +52,9 @@ POTENTIAL_FELLOWSHIP_EVENT_DEACTIVATION = 'deactivation' POTENTIAL_FELLOWSHIP_EVENTS = ( (POTENTIAL_FELLOWSHIP_EVENT_DEFINED, 'Defined in database'), + (POTENTIAL_FELLOWSHIP_EVENT_NOMINATED, 'Nominated'), + (POTENTIAL_FELLOWSHIP_EVENT_VOTED_ON, 'Voted on'), + (POTENTIAL_FELLOWSHIP_EVENT_ELECTED, 'Elected'), (POTENTIAL_FELLOWSHIP_EVENT_EMAILED, 'Emailed with invitation'), (POTENTIAL_FELLOWSHIP_EVENT_RESPONDED, 'Response received'), (POTENTIAL_FELLOWSHIP_EVENT_STATUSUPDATED, 'Status updated'), diff --git a/colleges/forms.py b/colleges/forms.py index 302d050a7..a09f430ab 100644 --- a/colleges/forms.py +++ b/colleges/forms.py @@ -14,7 +14,8 @@ from scipost.forms import RequestFormMixin from scipost.models import Contributor from .models import Fellowship, PotentialFellowship, PotentialFellowshipEvent -from .constants import POTENTIAL_FELLOWSHIP_NOMINATED +from .constants import POTENTIAL_FELLOWSHIP_IDENTIFIED, POTENTIAL_FELLOWSHIP_NOMINATED,\ + POTENTIAL_FELLOWSHIP_EVENT_DEFINED, POTENTIAL_FELLOWSHIP_EVENT_NOMINATED class AddFellowshipForm(forms.ModelForm): @@ -235,18 +236,26 @@ class PotentialFellowshipForm(RequestFormMixin, forms.ModelForm): def save(self): """ - The default status is IDENTIFIED, which is appropriate if the + The default status is IDENTIFIED, which is appropriate if the PotentialFellow was added directly by SciPost Admin. But if the PotFel is nominated by somebody on the Advisory Board or by an existing Fellow, the status is set to NOMINATED and the person nominating is added to the list of in_agreement with election. """ potfel = super().save() - if self.request.user.groups.filter(name__in=[ - 'Advisory Board', 'Editorial College']).exists(): + nominated = self.request.user.groups.filter(name__in=[ + 'Advisory Board', 'Editorial College']).exists() + if nominated: potfel.status = POTENTIAL_FELLOWSHIP_NOMINATED potfel.in_agreement.add(self.request.user.contributor) + event = POTENTIAL_FELLOWSHIP_EVENT_NOMINATED + else: + potfel.status = POTENTIAL_FELLOWSHIP_IDENTIFIED + event = POTENTIAL_FELLOWSHIP_EVENT_DEFINED potfel.save() + newevent = PotentialFellowshipEvent( + potfel=potfel, event=event, noted_by=self.request.user.contributor) + newevent.save() return potfel diff --git a/colleges/migrations/0013_auto_20190117_1935.py b/colleges/migrations/0013_auto_20190117_1935.py new file mode 100644 index 000000000..d6cd8ee25 --- /dev/null +++ b/colleges/migrations/0013_auto_20190117_1935.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.4 on 2019-01-17 18:35 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('colleges', '0012_auto_20190114_0550'), + ] + + operations = [ + migrations.AlterField( + model_name='potentialfellowshipevent', + name='event', + field=models.CharField(choices=[('defined', 'Defined in database'), ('nominated', 'Nominated'), ('votedon', 'Voted on'), ('elected', 'Elected'), ('emailed', 'Emailed with invitation'), ('responded', 'Response received'), ('statusupdated', 'Status updated'), ('comment', 'Comment'), ('deactivation', 'Deactivation: not considered anymore')], max_length=32), + ), + ] diff --git a/colleges/templates/colleges/_potentialfellowship_card.html b/colleges/templates/colleges/_potentialfellowship_card.html index 6ef9fa580..9225b7042 100644 --- a/colleges/templates/colleges/_potentialfellowship_card.html +++ b/colleges/templates/colleges/_potentialfellowship_card.html @@ -108,6 +108,7 @@ </div> {% endif %} + {% if perms.scipost.can_manage_college_composition %} <h3 class="highlight">Events</h3> <div class="row"> <div class="col-md-6"> @@ -119,7 +120,7 @@ {% endfor %} </ul> </div> - {% if perms.scipost.can_manage_college_composition %} + <div class="col-md-6"> <h3>Add an event for this Potential Fellowship</h3> <form class="d-block mt-2 mb-3" action="{% url 'colleges:potential_fellowship_event_create' pk=potfel.id %}" method="post"> @@ -128,6 +129,6 @@ <input type="submit" name="submit" value="Submit" class="btn btn-outline-secondary"> </form> </div> - {% endif %} </div> + {% endif %} </div> diff --git a/colleges/views.py b/colleges/views.py index 56111c960..7f076cf1c 100644 --- a/colleges/views.py +++ b/colleges/views.py @@ -4,9 +4,10 @@ __license__ = "AGPL v3" from django.contrib import messages from django.contrib.auth.decorators import login_required, permission_required +from django.core.urlresolvers import reverse, reverse_lazy from django.db.models import Count +from django.http import Http404 from django.shortcuts import get_object_or_404, render, redirect -from django.core.urlresolvers import reverse, reverse_lazy from django.utils import timezone from django.utils.decorators import method_decorator from django.views.generic.detail import DetailView @@ -15,10 +16,10 @@ from django.views.generic.list import ListView from submissions.models import Submission -from .constants import POTENTIAL_FELLOWSHIP_INVITED, potential_fellowship_statuses_dict,\ - POTENTIAL_FELLOWSHIP_EVENT_EMAILED, POTENTIAL_FELLOWSHIP_EVENT_STATUSUPDATED,\ - POTENTIAL_FELLOWSHIP_EVENT_COMMENT,\ - POTENTIAL_FELLOWSHIP_STATUSES +from .constants import POTENTIAL_FELLOWSHIP_STATUSES,\ + POTENTIAL_FELLOWSHIP_INVITED, potential_fellowship_statuses_dict,\ + POTENTIAL_FELLOWSHIP_EVENT_VOTED_ON, POTENTIAL_FELLOWSHIP_EVENT_EMAILED,\ + POTENTIAL_FELLOWSHIP_EVENT_STATUSUPDATED, POTENTIAL_FELLOWSHIP_EVENT_COMMENT from .forms import FellowshipForm, FellowshipTerminateForm, FellowshipRemoveSubmissionForm,\ FellowshipAddSubmissionForm, AddFellowshipForm, SubmissionAddFellowshipForm,\ FellowshipRemoveProceedingsForm, FellowshipAddProceedingsForm, SubmissionAddVotingFellowForm,\ @@ -314,7 +315,7 @@ class PotentialFellowshipCreateView(PermissionsMixin, RequestViewMixin, CreateVi success_url = reverse_lazy('colleges:potential_fellowships') -class PotentialFellowshipUpdateView(PermissionsMixin, UpdateView): +class PotentialFellowshipUpdateView(PermissionsMixin, RequestViewMixin, UpdateView): """ Formview to update a Potential Fellowship. """ @@ -409,10 +410,19 @@ def vote_on_potential_fellowship(request, potfel_id, vote): potfel.in_disagreement.remove(request.user.contributor) if vote == 'A': potfel.in_agreement.add(request.user.contributor) + comments = 'Voted Agree' elif vote == 'N': potfel.in_abstain.add(request.user.contributor) + comments = 'Voted Abstain' elif vote == 'D': potfel.in_disagreement.add(request.user.contributor) + comments = 'Voted Disagree' + else: + raise Http404 + newevent = PotentialFellowshipEvent( + potfel=potfel, event=POTENTIAL_FELLOWSHIP_EVENT_VOTED_ON, + comments=comments, noted_by=request.user.contributor) + newevent.save() return redirect(reverse('colleges:potential_fellowships')) -- GitLab