Skip to content

Commit

Permalink
[back] feat: display the score max in ComparisonCriteriaScore admin (#…
Browse files Browse the repository at this point in the history
…2027)


Also:
- feat: add "criteria" as a list filter in ComparisonCriteriaScoreAdmin
- perf: use `select_related` to fetch users in ComparisonAdmin
  • Loading branch information
GresilleSiffle authored Nov 14, 2024
1 parent 07973b3 commit 14431fa
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 9 deletions.
28 changes: 25 additions & 3 deletions backend/tournesol/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ class ComparisonAdmin(admin.ModelAdmin):
"entity_1",
"entity_2",
"poll",
"user",
)
raw_id_fields = (
"user",
Expand All @@ -290,13 +291,34 @@ def get_poll_name(self, obj):
return obj.poll.name


class ScoreMaxListFilter(admin.SimpleListFilter):
title = _("score max")
parameter_name = "score_max"
relevant_score_max = (2, 10)

def lookups(self, request, model_admin):
return [(score_max, score_max) for score_max in self.relevant_score_max]

def queryset(self, request, queryset):
if self.value() is None:
return queryset

try:
if int(self.value()) in self.relevant_score_max:
return queryset.filter(
score_max=int(self.value()),
)
except ValueError:
pass
return queryset


@admin.register(ComparisonCriteriaScore)
class ComparisonCriteriaScoreAdmin(admin.ModelAdmin):
list_filter = ("comparison__poll__name",)
list_display = ("id", "comparison", "criteria", "score")
list_filter = ("comparison__poll__name", ScoreMaxListFilter, "criteria")
list_display = ("id", "comparison", "criteria", "score_max", "score")
readonly_fields = ("comparison",)
search_fields = (
"criteria",
"comparison__entity_1__uid",
"comparison__entity_2__uid",
)
Expand Down
16 changes: 10 additions & 6 deletions backend/tournesol/locale/fr/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-08-06 08:43+0000\n"
"POT-Creation-Date: 2024-11-14 15:16+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
Expand All @@ -23,15 +23,19 @@ msgstr ""
msgid "Successfully refreshed the metadata of %(count)s entities."
msgstr "Les métadonnées de %(count)s entités ont été mises à jour."

#: tournesol/admin.py:372
#: tournesol/admin.py:294
msgid "score max"
msgstr "score max"

#: tournesol/admin.py:393
msgid "has text?"
msgstr "contient du texte?"

#: tournesol/admin.py:377
#: tournesol/admin.py:398
msgid "Yes"
msgstr "Oui"

#: tournesol/admin.py:378
#: tournesol/admin.py:399
msgid "No"
msgstr "Non"

Expand All @@ -49,8 +53,8 @@ msgid ""
"The absolute value of the score %(score)s given to the criterion "
"%(criterion)s can't be greater than the value of score_max %(score_max)s."
msgstr ""
"La valeur absolue du score %(score)s donnée au critère "
"%(criterion)s ne peut pas être supérieure à la valeur de score_max %(score_max)s."
"La valeur absolue du score %(score)s donnée au critère %(criterion)s ne peut "
"pas être supérieure à la valeur de score_max %(score_max)s."

#: tournesol/serializers/rate_later.py:60
msgid "The entity is already in the rate-later list of this poll."
Expand Down

0 comments on commit 14431fa

Please sign in to comment.