Example #1
0
    def clean_texto_integral(self):
        super(NormaJuridicaForm, self).clean()

        texto_integral = self.cleaned_data.get('texto_integral', False)

        if texto_integral:
            validar_arquivo(texto_integral, "Texto Integral")

        return texto_integral
Example #2
0
    def clean(self):
        super(DocumentoAcessorioEditForm, self).clean()

        if not self.is_valid():
            return self.cleaned_data

        arquivo = self.cleaned_data.get('arquivo', False)

        if arquivo:
            validar_arquivo(arquivo, "Texto Integral")

        return self.cleaned_data
Example #3
0
File: forms.py Project: erijpc/sapl
    def clean(self):
        super(AnexoAudienciaPublicaForm, self).clean()

        if not self.is_valid():
            return self.cleaned_data

        arquivo = self.cleaned_data.get('arquivo', False)

        if arquivo:
            validar_arquivo(arquivo, "Arquivo")

        return self.cleaned_data
Example #4
0
    def clean(self):
        cleaned_data = super(AnexoNormaJuridicaForm, self).clean()
        
        if not self.is_valid():
            return cleaned_data
        
        anexo_arquivo = self.cleaned_data.get('anexo_arquivo', False)

        if anexo_arquivo:
            validar_arquivo(anexo_arquivo, "Arquivo Anexo")

        return cleaned_data
Example #5
0
    def clean(self):
        super(JustificativaAusenciaForm, self).clean()

        if not self.is_valid():
            return self.cleaned_data

        sessao_plenaria = self.instance.sessao_plenaria

        upload_anexo = self.cleaned_data.get('upload_anexo', False)

        if upload_anexo:
            validar_arquivo(upload_anexo, "Anexo de Justificativa")

        if not sessao_plenaria.finalizada or sessao_plenaria.finalizada is None:
            raise ValidationError(
                "A sessão deve estar finalizada para registrar uma Ausência")
        else:
            return self.cleaned_data
Example #6
0
    def clean(self):
        super(ReuniaoForm, self).clean()

        if not self.is_valid():
            return self.cleaned_data

        if self.cleaned_data['hora_fim']:
            if (self.cleaned_data['hora_fim'] <
                    self.cleaned_data['hora_inicio']):
                msg = _(
                    'A hora de término da reunião não pode ser menor que a de início'
                )
                self.logger.warn(
                    "A hora de término da reunião ({}) não pode ser menor que a de início ({})."
                    .format(self.cleaned_data['hora_fim'],
                            self.cleaned_data['hora_inicio']))
                raise ValidationError(msg)

        upload_pauta = self.cleaned_data.get('upload_pauta', False)
        upload_ata = self.cleaned_data.get('upload_ata', False)
        upload_anexo = self.cleaned_data.get('upload_anexo', False)

        if upload_pauta:
            validar_arquivo(upload_pauta, "Pauta da Reunião")

        if upload_ata:
            validar_arquivo(upload_ata, "Ata da Reunião")

        if upload_anexo:
            validar_arquivo(upload_anexo, "Anexo da Reunião")

        return self.cleaned_data
Example #7
0
    def clean(self):
        super(OradorOrdemDiaForm, self).clean()
        cleaned_data = self.cleaned_data

        if not self.is_valid():
            return self.cleaned_data

        sessao_id = self.initial['id_sessao']
        numero = self.initial.get('numero')
        numero_ordem = cleaned_data['numero_ordem']
        ordem = OradorOrdemDia.objects.filter(
            sessao_plenaria_id=sessao_id, numero_ordem=numero_ordem).exists()

        if ordem and numero_ordem != numero:
            raise ValidationError(
                _("Já existe orador nesta posição de ordem de pronunciamento"))

        upload_anexo = self.cleaned_data.get('upload_anexo', False)

        if upload_anexo:
            validar_arquivo(upload_anexo, "Anexo do Orador")

        return self.cleaned_data
Example #8
0
File: forms.py Project: erijpc/sapl
    def clean(self):
        cleaned_data = super(AudienciaForm, self).clean()
        if not self.is_valid():
            return cleaned_data

        materia = cleaned_data['numero_materia']
        ano_materia = cleaned_data['ano_materia']
        tipo_materia = cleaned_data['tipo_materia']
        parlamentar_autor = cleaned_data["parlamentar_autor"]
        requerimento = cleaned_data["requerimento"]

        if materia and ano_materia and tipo_materia:
            try:
                self.logger.debug("Tentando obter MateriaLegislativa %s nº %s/%s." % (tipo_materia, materia, ano_materia))
                materia = MateriaLegislativa.objects.get(
                    numero=materia,
                    ano=ano_materia,
                    tipo=tipo_materia)
            except ObjectDoesNotExist:
                msg = _('A matéria %s nº %s/%s não existe no cadastro'
                        ' de matérias legislativas.' % (tipo_materia, materia, ano_materia))
                self.logger.error('A MateriaLegislativa %s nº %s/%s não existe no cadastro'
                        ' de matérias legislativas.' % (tipo_materia, materia, ano_materia))
                raise ValidationError(msg)
            else:
                self.logger.info("MateriaLegislativa %s nº %s/%s obtida com sucesso." % (tipo_materia, materia, ano_materia))
                cleaned_data['materia'] = materia

        else:
            campos = [materia, tipo_materia, ano_materia]
            if campos.count(None) + campos.count('') < len(campos):
                msg = _('Preencha todos os campos relacionados à Matéria Legislativa')
                self.logger.error('Algum campo relacionado à MatériaLegislativa %s nº %s/%s \
                                não foi preenchido.' % (tipo_materia, materia, ano_materia))
                raise ValidationError(msg)

        if not cleaned_data['numero']:

            ultima_audiencia = AudienciaPublica.objects.all().order_by('numero').last()
            if ultima_audiencia:
                cleaned_data['numero'] = ultima_audiencia.numero + 1
            else:
                cleaned_data['numero'] = 1

        if self.cleaned_data['hora_inicio'] and self.cleaned_data['hora_fim']:
            if self.cleaned_data['hora_fim'] < self.cleaned_data['hora_inicio']:
                msg = _('A hora de fim ({}) não pode ser anterior a hora de início({})'
                        .format(self.cleaned_data['hora_fim'], self.cleaned_data['hora_inicio']))
                self.logger.error('Hora de fim anterior à hora de início.')
                raise ValidationError(msg)

        if parlamentar_autor.autor.first() not in requerimento.autores.all():
            raise ValidationError("Parlamentar Autor selecionado não faz parte da autoria do Requerimento selecionado.")

        upload_pauta = self.cleaned_data.get('upload_pauta', False)
        upload_ata = self.cleaned_data.get('upload_ata', False)
        upload_anexo = self.cleaned_data.get('upload_anexo', False)

        if upload_pauta:
            validar_arquivo(upload_pauta, "Pauta da Audiência Pública")

        if upload_ata:
            validar_arquivo(upload_ata, "Ata da Audiência Pública")

        if upload_anexo:
            validar_arquivo(upload_anexo, "Anexo da Audiência Pública")

        return cleaned_data
Example #9
0
    def clean(self):
        super(SessaoPlenariaForm, self).clean()

        if not self.is_valid():
            return self.cleaned_data

        instance = self.instance

        num = self.cleaned_data['numero']
        sl = self.cleaned_data['sessao_legislativa']
        leg = self.cleaned_data['legislatura']
        tipo = self.cleaned_data['tipo']
        abertura = self.cleaned_data['data_inicio']
        encerramento = self.cleaned_data['data_fim']

        error = ValidationError(
            "Número de Sessão Plenária já existente "
            "para a Legislatura, Sessão Legislativa e Tipo informados. "
            "Favor escolher um número distinto.")

        qs = tipo.queryset_tipo_numeracao(leg, sl, abertura)
        qs &= Q(numero=num)

        if SessaoPlenaria.objects.filter(qs).exclude(pk=instance.pk).exists():
            raise error

        # Condições da verificação
        abertura_entre_leg = leg.data_inicio <= abertura <= leg.data_fim
        abertura_entre_sl = sl.data_inicio <= abertura <= sl.data_fim
        if encerramento is not None:
            # Verifica se a data de encerramento é anterior a data de abertura
            if encerramento < abertura:
                raise ValidationError("A data de encerramento não pode ser "
                                      "anterior a data de abertura.")
            encerramento_entre_leg = leg.data_inicio <= encerramento <= leg.data_fim
            encerramento_entre_sl = sl.data_inicio <= encerramento <= sl.data_fim
        else:
            encerramento_entre_leg = True
            encerramento_entre_sl = True

        ## Sessões Extraordinárias podem estar fora da sessão legislativa
        descricao_tipo = tipo.nome.lower()
        if "extraordinária" in descricao_tipo or "especial" in descricao_tipo:
            # Ignora checagem de limites para Sessão Legislativa
            abertura_entre_sl = True
            encerramento_entre_sl = True

        if not (abertura_entre_leg and encerramento_entre_leg):
            raise ValidationError(
                "A data de abertura e encerramento da Sessão "
                "Plenária deve estar compreendida entre a "
                "data de abertura e encerramento da Legislatura")

        if not (abertura_entre_sl and encerramento_entre_sl):
            raise ValidationError(
                "A data de abertura e encerramento da Sessão "
                "Plenária deve estar compreendida entre a "
                "data de abertura e encerramento da Sessão Legislativa")

        upload_pauta = self.cleaned_data.get('upload_pauta', False)
        upload_ata = self.cleaned_data.get('upload_ata', False)
        upload_anexo = self.cleaned_data.get('upload_anexo', False)

        if upload_pauta:
            validar_arquivo(upload_pauta, "Pauta da Sessão")

        if upload_ata:
            validar_arquivo(upload_ata, "Ata da Sessão")

        if upload_anexo:
            validar_arquivo(upload_anexo, "Anexo da Sessão")

        return self.cleaned_data
Example #10
0
File: forms.py Project: alunix/sapl
    def clean(self):
        super(SessaoPlenariaForm, self).clean()

        if not self.is_valid():
            return self.cleaned_data

        instance = self.instance

        num = self.cleaned_data['numero']
        sl = self.cleaned_data['sessao_legislativa']
        leg = self.cleaned_data['legislatura']
        tipo = self.cleaned_data['tipo']
        abertura = self.cleaned_data['data_inicio']
        encerramento = self.cleaned_data['data_fim']

        error = ValidationError(
            "Número de Sessão Plenária já existente "
            "para a Legislatura, Sessão Legislativa e Tipo informados. "
            "Favor escolher um número distinto.")

        qs = tipo.queryset_tipo_numeracao(leg, sl, abertura)
        qs &= Q(numero=num)

        if SessaoPlenaria.objects.filter(qs).exclude(pk=instance.pk).exists():
            raise error

        # Condições da verificação
        abertura_entre_leg = leg.data_inicio <= abertura <= leg.data_fim
        abertura_entre_sl = sl.data_inicio <= abertura <= sl.data_fim
        if encerramento is not None:
            encerramento_entre_leg = leg.data_inicio <= encerramento <= leg.data_fim
            encerramento_entre_sl = sl.data_inicio <= encerramento <= sl.data_fim
        # Verificação das datas de abertura e encerramento da Sessão
        # Verificações com a data de encerramento preenchidas
        if encerramento is not None:
            # Verifica se a data de encerramento é anterior a data de abertura
            if encerramento < abertura:
                raise ValidationError("A data de encerramento não pode ser "
                                      "anterior a data de abertura.")
            # Verifica se a data de abertura está entre a data de início e fim
            # da legislatura
            if abertura_entre_leg and encerramento_entre_leg:
                if abertura_entre_sl and encerramento_entre_sl:
                    pass
                elif abertura_entre_sl and not encerramento_entre_sl:
                    raise ValidationError(
                        "A data de encerramento deve estar entre "
                        "as datas de início e fim da Sessão Legislativa.")
                elif not abertura_entre_sl and encerramento_entre_sl:
                    raise ValidationError(
                        "A data de abertura deve estar entre as "
                        "datas de início e fim da Sessão Legislativa.")
                elif not abertura_entre_sl and not encerramento_entre_sl:
                    raise ValidationError(
                        "A data de abertura e de encerramento devem estar "
                        "entre as datas de início e fim da Sessão Legislativa."
                    )
            elif abertura_entre_leg and not encerramento_entre_leg:
                if abertura_entre_sl and encerramento_entre_sl:
                    raise ValidationError(
                        "A data de encerramento deve estar entre "
                        "as datas de início e fim da Legislatura.")
                elif abertura_entre_sl and not encerramento_entre_sl:
                    raise ValidationError(
                        "A data de encerramento deve estar entre "
                        "as datas de início e fim tanto da "
                        "Legislatura quanto da Sessão Legislativa.")
                elif not abertura_entre_sl and encerramento_entre_sl:
                    raise ValidationError(
                        "As datas de abertura e encerramento devem "
                        "estar entre as "
                        "datas de início e fim tanto Legislatura "
                        "quanto da Sessão Legislativa.")
                elif not abertura_entre_sl and not encerramento_entre_sl:
                    raise ValidationError(
                        "As datas de abertura e encerramento devem "
                        "estar entre as "
                        "datas de início e fim tanto Legislatura "
                        "quanto da Sessão Legislativa.")
            elif not abertura_entre_leg and not encerramento_entre_leg:
                if abertura_entre_sl and encerramento_entre_sl:
                    raise ValidationError(
                        "As datas de abertura e encerramento devem "
                        "estar entre as "
                        "datas de início e fim da Legislatura.")
                elif abertura_entre_sl and not encerramento_entre_sl:
                    raise ValidationError(
                        "As datas de abertura e encerramento devem "
                        "estar entre as "
                        "datas de início e fim tanto Legislatura "
                        "quanto da Sessão Legislativa.")
                elif not abertura_entre_sl and encerramento_entre_sl:
                    raise ValidationError(
                        "As datas de abertura e encerramento devem "
                        "estar entre as "
                        "datas de início e fim tanto Legislatura "
                        "quanto da Sessão Legislativa.")
                elif not abertura_entre_sl and not encerramento_entre_sl:
                    raise ValidationError(
                        "As datas de abertura e encerramento devem "
                        "estar entre as "
                        "datas de início e fim tanto Legislatura "
                        "quanto da Sessão Legislativa.")

        # Verificações com a data de encerramento vazia
        else:
            if abertura_entre_leg:
                if abertura_entre_sl:
                    pass
                else:
                    raise ValidationError(
                        "A data de abertura da sessão deve estar "
                        "entre a data de início e fim da Sessão Legislativa.")
            else:
                if abertura_entre_sl:
                    raise ValidationError(
                        "A data de abertura da sessão deve estar "
                        "entre a data de início e fim da Legislatura.")
                else:
                    raise ValidationError(
                        "A data de abertura da sessão deve estar "
                        "entre a data de início e fim tanto da "
                        "Legislatura quanto da Sessão Legislativa.")

        upload_pauta = self.cleaned_data.get('upload_pauta', False)
        upload_ata = self.cleaned_data.get('upload_ata', False)
        upload_anexo = self.cleaned_data.get('upload_anexo', False)

        if upload_pauta:
            validar_arquivo(upload_pauta, "Pauta da Sessão")

        if upload_ata:
            validar_arquivo(upload_ata, "Ata da Sessão")

        if upload_anexo:
            validar_arquivo(upload_anexo, "Anexo da Sessão")

        return self.cleaned_data