SciPost Code Repository

Skip to content
Snippets Groups Projects
Commit 6f5731d0 authored by George Katsikas's avatar George Katsikas :goat:
Browse files

add default vote outcome to nomination decision

parent 804eae5a
No related branches found
No related tags found
1 merge request!58[Fellowship Nominations] Rework the fellowship nomination system and UI
......@@ -552,6 +552,7 @@ class FellowshipNominationDecisionForm(forms.ModelForm):
]
def __init__(self, *args, **kwargs):
voting_round = kwargs.pop("voting_round", None)
super().__init__(*args, **kwargs)
self.helper = FormHelper()
self.helper.layout = Layout(
......@@ -568,6 +569,9 @@ class FellowshipNominationDecisionForm(forms.ModelForm):
),
)
if voting_round:
self.fields["outcome"].initial = voting_round.vote_outcome
class FellowshipInvitationResponseForm(forms.ModelForm):
class Meta:
......
......@@ -218,6 +218,28 @@ class FellowshipNominationVotingRound(models.Model):
def is_open(self):
return self.voting_opens <= timezone.now() <= self.voting_deadline
@property
def vote_outcome(self):
"""The outcome as determined by the votes."""
if self.votes.veto():
return FellowshipNominationDecision.OUTCOME_NOT_ELECTED
nr_votes_agree = self.votes.agree().count()
nr_votes_disagree = self.votes.disagree().count()
nr_non_abstaining_votes = nr_votes_agree + nr_votes_disagree
# Guard division by zero
if nr_non_abstaining_votes == 0:
return FellowshipNominationDecision.OUTCOME_NOT_ELECTED
# By-laws 1.3.4 grand fellowship if there is a majority of non-abstaining votes.
# Agree is counted as +1, disagree as -1
agree_ratio = (nr_votes_agree - nr_votes_disagree) / nr_non_abstaining_votes
if agree_ratio >= 0.5:
return FellowshipNominationDecision.OUTCOME_ELECTED
else:
return FellowshipNominationDecision.OUTCOME_NOT_ELECTED
class FellowshipNominationVote(models.Model):
VOTE_AGREE = "agree"
......
......@@ -961,7 +961,9 @@ def _hx_nomination_vote(request, voting_round_id):
def _hx_nomination_decision_form(request, round_id):
voting_round = get_object_or_404(FellowshipNominationVotingRound, pk=round_id)
nomination = voting_round.nomination
decision_form = FellowshipNominationDecisionForm(request.POST or None)
decision_form = FellowshipNominationDecisionForm(
request.POST or None, voting_round=voting_round
)
if decision_form.is_valid():
decision = decision_form.save()
nomination.add_event(description="Decision fixed", by=request.user.contributor)
......@@ -974,8 +976,6 @@ def _hx_nomination_decision_form(request, round_id):
nomination.add_event(
description="Invitation created", by=request.user.contributor
)
else:
decision_form.fields["voting_round"].initial = voting_round
context = {
"voting_round": voting_round,
"decision_form": decision_form,
......
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