From bcae4071a8bb994bf0fe4a5eda418e36b831b1db Mon Sep 17 00:00:00 2001 From: Mario Sergio Date: Thu, 10 Oct 2024 12:03:40 -0300 Subject: [PATCH] feat(vote): Included year arg to django command --- .../management/commands/populate_election_results.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/org_eleicoes/votepeloclima/candidature/management/commands/populate_election_results.py b/app/org_eleicoes/votepeloclima/candidature/management/commands/populate_election_results.py index 7aabea24..4ceea272 100644 --- a/app/org_eleicoes/votepeloclima/candidature/management/commands/populate_election_results.py +++ b/app/org_eleicoes/votepeloclima/candidature/management/commands/populate_election_results.py @@ -16,6 +16,12 @@ def add_arguments(self, parser): type=str, help="Tipo de eleição: 'vereador' ou 'prefeito'." ) + + parser.add_argument( + 'ano', + type=int, + help="Ano da eleição." + ) def map_situacao_to_status(self, situacao, eleicao): """ @@ -40,6 +46,7 @@ def map_situacao_to_status(self, situacao, eleicao): def handle(self, *args, **kwargs): eleicao = kwargs['eleicao'] + ano = kwargs['ano'] # Define o caminho correto para o CSV com base no tipo de eleição if eleicao == 'vereador': @@ -68,7 +75,7 @@ def handle(self, *args, **kwargs): csv_data[chave_composta] = row # Carrega todas as candidaturas da base de dados - candidatures = Candidature.objects.all() + candidatures = Candidature.objects.filter(election_year=ano) # Itera pelas candidaturas e busca os resultados no CSV for candidature in candidatures: