From 768b2d364ccaec3eaa1512d93d72cdc53a31a6de Mon Sep 17 00:00:00 2001 From: Obada Haddad Date: Wed, 27 Aug 2025 14:26:02 +0200 Subject: [PATCH 1/5] Added custom filter that shows competitions with more than 10 participants and 25 submissions that are private --- src/apps/competitions/admin.py | 37 +++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/src/apps/competitions/admin.py b/src/apps/competitions/admin.py index b991555da..7496f53fe 100644 --- a/src/apps/competitions/admin.py +++ b/src/apps/competitions/admin.py @@ -1,12 +1,47 @@ from django.contrib import admin +from django.utils.translation import gettext_lazy as _ from . import models +class privateCompetitionsFilter(admin.SimpleListFilter): + # Human-readable title which will be displayed in the + # right admin sidebar just above the filter options. + title = _("Private non-test") + + # Parameter for the filter that will be used in the URL query. + parameter_name = "private" + + def lookups(self, request, model_admin): + """ + Returns a list of tuples. The first element in each + tuple is the coded value for the option that will + appear in the URL query. The second element is the + human-readable name for the option that will appear + in the right sidebar. + """ + return [ + ("privateSmall", _("Submission >= 25 & Participants >= 10")), + ] + + def queryset(self, request, queryset): + """ + Returns the filtered queryset based on the value + provided in the query string and retrievable via + `self.value()`. + """ + # Only show private competitions with >= 25 submissions and >=10 participants + print(request.__dict__) + if self.value() == "privateSmall": + return queryset.filter( + published=False, + submissions_count__gte=25, + participants_count__gte=10 + ) class CompetitionAdmin(admin.ModelAdmin): search_fields = ['title', 'docker_image', 'created_by__username'] list_display = ['id', 'title', 'created_by', 'is_featured'] - list_filter = ['is_featured'] + list_filter = ['is_featured', privateCompetitionsFilter] admin.site.register(models.Competition, CompetitionAdmin) From e99cf545948bfdc592b5ba9f76eaf0730ea8ddaa Mon Sep 17 00:00:00 2001 From: Obada Haddad Date: Wed, 27 Aug 2025 14:37:23 +0200 Subject: [PATCH 2/5] Removed useless print --- src/apps/competitions/admin.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/apps/competitions/admin.py b/src/apps/competitions/admin.py index 7496f53fe..4f2e8fb93 100644 --- a/src/apps/competitions/admin.py +++ b/src/apps/competitions/admin.py @@ -30,7 +30,6 @@ def queryset(self, request, queryset): `self.value()`. """ # Only show private competitions with >= 25 submissions and >=10 participants - print(request.__dict__) if self.value() == "privateSmall": return queryset.filter( published=False, From 1627d1e9e6437e713966696b547355b15a151321 Mon Sep 17 00:00:00 2001 From: Obada Haddad Date: Mon, 1 Sep 2025 15:51:55 +0200 Subject: [PATCH 3/5] Flake8 fixes --- src/apps/competitions/admin.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/apps/competitions/admin.py b/src/apps/competitions/admin.py index 4f2e8fb93..dc6d43eb1 100644 --- a/src/apps/competitions/admin.py +++ b/src/apps/competitions/admin.py @@ -3,6 +3,7 @@ from . import models + class privateCompetitionsFilter(admin.SimpleListFilter): # Human-readable title which will be displayed in the # right admin sidebar just above the filter options. @@ -31,11 +32,12 @@ def queryset(self, request, queryset): """ # Only show private competitions with >= 25 submissions and >=10 participants if self.value() == "privateSmall": - return queryset.filter( - published=False, - submissions_count__gte=25, - participants_count__gte=10 - ) + return queryset.filter( + published=False, + submissions_count__gte=25, + participants_count__gte=10 + ) + class CompetitionAdmin(admin.ModelAdmin): search_fields = ['title', 'docker_image', 'created_by__username'] From 8bae83e009c07b51c9043affaeafb2e9a5aae066 Mon Sep 17 00:00:00 2001 From: Obada Haddad Date: Tue, 2 Sep 2025 17:32:05 +0200 Subject: [PATCH 4/5] Reduced Submissions and Participants --- src/apps/competitions/admin.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/apps/competitions/admin.py b/src/apps/competitions/admin.py index dc6d43eb1..090014ad4 100644 --- a/src/apps/competitions/admin.py +++ b/src/apps/competitions/admin.py @@ -34,8 +34,8 @@ def queryset(self, request, queryset): if self.value() == "privateSmall": return queryset.filter( published=False, - submissions_count__gte=25, - participants_count__gte=10 + submissions_count__gte=10, + participants_count__gte=5 ) From 1b424c6da86c089cdde1e4a2b7ff9c938cfcac25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20Pav=C3=A3o?= Date: Fri, 12 Sep 2025 14:30:30 +0200 Subject: [PATCH 5/5] Update admin.py --- src/apps/competitions/admin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/apps/competitions/admin.py b/src/apps/competitions/admin.py index 090014ad4..942133b4b 100644 --- a/src/apps/competitions/admin.py +++ b/src/apps/competitions/admin.py @@ -21,7 +21,7 @@ def lookups(self, request, model_admin): in the right sidebar. """ return [ - ("privateSmall", _("Submission >= 25 & Participants >= 10")), + ("privateSmall", _("Submissions >= 25 and Participants >= 10")), ] def queryset(self, request, queryset):