SciPost Code Repository

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

add ordering by latest event in nominations

fixes #238
parent a93ca214
No related branches found
No related tags found
No related merge requests found
...@@ -631,15 +631,15 @@ class FellowshipNominationSearchForm(forms.Form): ...@@ -631,15 +631,15 @@ class FellowshipNominationSearchForm(forms.Form):
("latest_round_decision_outcome", "Decision"), ("latest_round_decision_outcome", "Decision"),
("profile__last_name", "Nominee"), ("profile__last_name", "Nominee"),
("nominated_on", "Nominated date"), ("nominated_on", "Nominated date"),
("latest_event_on", "Last event date"),
), ),
required=False, required=False,
) )
ordering = forms.ChoiceField( ordering = forms.ChoiceField(
label="Ordering", label="Ordering",
choices=( choices=(
# FIXME: Emperically, the ordering appers to be reversed for dates? ("+", "Ascending"),
("-", "Ascending"), ("-", "Descending"),
("+", "Descending"),
), ),
required=False, required=False,
) )
...@@ -734,6 +734,13 @@ class FellowshipNominationSearchForm(forms.Form): ...@@ -734,6 +734,13 @@ class FellowshipNominationSearchForm(forms.Form):
.values(key)[:1] .values(key)[:1]
) )
def latest_event_subquery(key):
return Subquery(
FellowshipNominationEvent.objects.filter(nomination=OuterRef("pk"))
.order_by("-on")
.values(key)[:1]
)
nominations = ( nominations = (
FellowshipNomination.objects.all() FellowshipNomination.objects.all()
.annotate( .annotate(
...@@ -742,6 +749,8 @@ class FellowshipNominationSearchForm(forms.Form): ...@@ -742,6 +749,8 @@ class FellowshipNominationSearchForm(forms.Form):
latest_round_decision_outcome=latest_round_subquery( latest_round_decision_outcome=latest_round_subquery(
"decision__outcome" "decision__outcome"
), ),
latest_event_on=latest_event_subquery("on"),
latest_event_description=latest_event_subquery("description"),
) )
.distinct() .distinct()
) )
......
...@@ -48,9 +48,9 @@ ...@@ -48,9 +48,9 @@
<div class="col text-truncate "> <div class="col text-truncate ">
<small class="text-muted">Last event</small> <small class="text-muted">Last event</small>
<br /> <br />
<time>{{ nomination.events.latest.on|date:'Y-m-d' }}</time> <time>{{ nomination.latest_event_on|date:'Y-m-d' }}</time>
- -
<span>{{ nomination.events.latest.description|truncatechars:40 }}</span> <span>{{ nomination.latest_event_description|truncatechars:40 }}</span>
</div> </div>
{% endif %} {% endif %}
......
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