Skip to content

Commit

Permalink
feat(vote): Included filters on sidebar
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiomario committed Oct 8, 2024
1 parent ecad1eb commit e9d6675
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
1 change: 1 addition & 0 deletions app/org_eleicoes/votepeloclima/candidature/choices.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ class Education(models.TextChoices):
doutorado_completo = "doutorado_completo", "Doutorado Completo"

class ElectionStatus(models.TextChoices):
empty = "", "Selecione uma opção"
eleita = "eleita", "Eleita/o"
segundo_turno = "segundo_turno", "Segundo Turno"
nao_eleita = "nao_eleito", "Não Eleita/o"
15 changes: 13 additions & 2 deletions app/org_eleicoes/votepeloclima/candidature/forms/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# from django_select2.forms import Select2Widget

from ..layout import NoCrispyField
from ..choices import Gender, Color, Sexuality
from ..choices import Gender, Color, Sexuality, ElectionStatus
from ..fields import CepField, ButtonCheckboxSelectMultiple, ButtonRadioSelect
from ..locations_utils import get_states, get_choices
from ..models import Candidature
Expand Down Expand Up @@ -68,6 +68,16 @@ def __init__(self, *args, **kwargs):


class FilterFormSidebar(RemoveRequiredMixin, forms.ModelForm):
election_status = forms.ChoiceField(
label="Filtrar por",
choices=[
("second_round", "Candidaturas no 2º turno"),
("all", "Todas as candidaturas"),
("elected", "Candidaturas eleitas")
],
widget=ButtonRadioSelect,
initial="second_round" # Define o filtro de 2º turno como padrão
)
proposes = forms.MultipleChoiceField(
label="Propostas", widget=ButtonCheckboxSelectMultiple
)
Expand All @@ -88,14 +98,15 @@ class FilterFormSidebar(RemoveRequiredMixin, forms.ModelForm):

class Meta:
model = Candidature
fields = ["proposes", "mandate_type", "gender", "color", "sexuality"]
fields = ["election_status", "proposes", "mandate_type", "gender", "color", "sexuality"]

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

self.fields["proposes"].choices = self.get_proposes_choices()

self.helper.layout = Layout(
NoCrispyField("election_status"),
NoCrispyField("proposes"),
NoCrispyField("mandate_type"),
NoCrispyField("gender"),
Expand Down
13 changes: 13 additions & 0 deletions app/org_eleicoes/votepeloclima/candidature/views/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from ..models import CandidatureFlowStatus, Candidature
from ..forms.filters import FilterFactoryForm
from ..choices import ElectionStatus


class CandidatureSearchView(ListView):
Expand Down Expand Up @@ -77,6 +78,18 @@ def get_queryset(self):
)
)

election_status = cleaned_data.get("election_status", "second_round")
else:
election_status = "second_round"

# Filtra com base no status da eleição
if election_status == "second_round":
# Filtra candidaturas que foram para o 2º turno
queryset = queryset.filter(election_results__status=ElectionStatus.segundo_turno)
elif election_status == "elected":
# Filtra candidaturas eleitas
queryset = queryset.filter(election_results__status=ElectionStatus.eleita)

return queryset

def get_context_data(self, **kwargs):
Expand Down

0 comments on commit e9d6675

Please sign in to comment.