Browse Source

Adicina filtros para eventos. Gertiq #167714

pull/167/head
Sesóstris Vieira 1 year ago
parent
commit
0b3334c67e
  1. 31
      sigi/apps/eventos/admin.py

31
sigi/apps/eventos/admin.py

@ -1,9 +1,9 @@
import datetime import datetime
import time import time
from typing import Any
from django.db.models.query import QuerySet
from moodle import Moodle from moodle import Moodle
from django.db.models import Q, OuterRef, Subquery from typing import Any
from django.db import models
from django.db.models import F, OuterRef, Subquery
from django.conf import settings from django.conf import settings
from django.contrib import admin, messages from django.contrib import admin, messages
from django.core.exceptions import ValidationError from django.core.exceptions import ValidationError
@ -53,7 +53,7 @@ class ActVigenteFilter(admin.SimpleListFilter):
def lookups(self, request, model_admin): def lookups(self, request, model_admin):
return ( return (
(("yes"), _("Yes")), ("yes", _("Yes")),
("no", _("No")), ("no", _("No")),
) )
@ -64,6 +64,28 @@ class ActVigenteFilter(admin.SimpleListFilter):
return queryset.filter(act_id=None) return queryset.filter(act_id=None)
class NumeroParticipantesFilter(admin.SimpleListFilter):
title = _("Inscritos x Aprovados")
parameter_name = "inscritos_x_aprovados"
def lookups(self, request, model_admin):
return (
("sem_inscritos", _("Sem inscritos")),
("sem_aprovados", _("Sem aprovados")),
("diferenca_10", _("Diferença >= dez")),
)
def queryset(self, request, queryset):
if self.value() == "sem_inscritos":
return queryset.filter(inscritos_saberes=0)
if self.value() == "sem_aprovados":
return queryset.filter(aprovados_saberes=0)
if self.value() == "diferenca_10":
return queryset.annotate(
diferenca=F("inscritos_saberes") - F("aprovados_saberes")
).filter(diferenca__gte=10)
class SolicitacaoResource(LabeledResourse): class SolicitacaoResource(LabeledResourse):
oficinas = Field(column_name="oficinas solicitadas") oficinas = Field(column_name="oficinas solicitadas")
oficinas_uf = Field(column_name="número de oficinas realizadas na UF") oficinas_uf = Field(column_name="número de oficinas realizadas na UF")
@ -717,6 +739,7 @@ class EventoAdmin(CartExportMixin, admin.ModelAdmin):
"virtual", "virtual",
"solicitante", "solicitante",
("moodle_courseid", admin.EmptyFieldListFilter), ("moodle_courseid", admin.EmptyFieldListFilter),
NumeroParticipantesFilter,
) )
date_hierarchy = "data_inicio" date_hierarchy = "data_inicio"
autocomplete_fields = ( autocomplete_fields = (

Loading…
Cancel
Save