SciPost Code Repository

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

fix dup nominations when sorting by round props

parent 7d4c70b2
No related branches found
No related tags found
1 merge request!58[Fellowship Nominations] Rework the fellowship nomination system and UI
...@@ -547,9 +547,9 @@ class FellowshipNominationSearchForm(forms.Form): ...@@ -547,9 +547,9 @@ class FellowshipNominationSearchForm(forms.Form):
orderby = forms.ChoiceField( orderby = forms.ChoiceField(
label="Order by", label="Order by",
choices=( choices=(
("voting_rounds__voting_deadline", "Deadline"), ("latest_round_deadline", "Deadline"),
("voting_rounds__voting_opens", "Voting start"), ("latest_round_open", "Voting start"),
("voting_rounds__decision__outcome", "Decision"), ("latest_round_decision_outcome", "Decision"),
("profile__last_name", "Nominee"), ("profile__last_name", "Nominee"),
), ),
required=False, required=False,
...@@ -632,13 +632,32 @@ class FellowshipNominationSearchForm(forms.Form): ...@@ -632,13 +632,32 @@ class FellowshipNominationSearchForm(forms.Form):
session.save() session.save()
nominations = FellowshipNomination.objects.all() def latest_round_subquery(key):
return Subquery(
FellowshipNominationVotingRound.objects.filter(
nomination=OuterRef("pk")
)
.order_by("-voting_deadline")
.values(key)[:1]
)
nominations = (
FellowshipNomination.objects.all()
.annotate(
latest_round_deadline=latest_round_subquery("voting_deadline"),
latest_round_open=latest_round_subquery("voting_opens"),
latest_round_decision_outcome=latest_round_subquery(
"decision__outcome"
),
)
.distinct()
)
if self.cleaned_data.get("can_vote") or not self.user.has_perm( if self.cleaned_data.get("can_vote") or not self.user.has_perm(
"scipost.can_view_all_nomination_voting_rounds" "scipost.can_view_all_nomination_voting_rounds"
): ):
# Restrict rounds to those the user can vote on # Restrict rounds to those the user can vote on
nominations = nominations.with_user_votable_rounds(self.user) nominations = nominations.with_user_votable_rounds(self.user).distinct()
if nominee := self.cleaned_data.get("nominee"): if nominee := self.cleaned_data.get("nominee"):
nominations = nominations.filter( nominations = nominations.filter(
......
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