|
@ -1,45 +1,163 @@ |
|
|
|
|
|
|
|
|
import logging |
|
|
import logging |
|
|
|
|
|
|
|
|
from django import apps |
|
|
|
|
|
from django.conf import settings |
|
|
|
|
|
from django.contrib.contenttypes.models import ContentType |
|
|
from django.contrib.contenttypes.models import ContentType |
|
|
from django.db.models import Q |
|
|
from django.db.models import Q |
|
|
from django.db.models.fields.files import FileField |
|
|
|
|
|
from django.http import Http404 |
|
|
from django.http import Http404 |
|
|
from django.utils.decorators import classonlymethod |
|
|
|
|
|
from django.utils.text import capfirst |
|
|
|
|
|
from django.utils.translation import ugettext_lazy as _ |
|
|
from django.utils.translation import ugettext_lazy as _ |
|
|
import django_filters |
|
|
|
|
|
from django_filters.rest_framework.backends import DjangoFilterBackend |
|
|
from django_filters.rest_framework.backends import DjangoFilterBackend |
|
|
from django_filters.rest_framework.filterset import FilterSet |
|
|
from rest_framework import serializers |
|
|
from django_filters.utils import resolve_field |
|
|
|
|
|
from rest_framework import serializers as rest_serializers |
|
|
|
|
|
from rest_framework.decorators import list_route, detail_route,\ |
|
|
|
|
|
permission_classes |
|
|
|
|
|
from rest_framework.generics import ListAPIView |
|
|
from rest_framework.generics import ListAPIView |
|
|
from rest_framework.mixins import ListModelMixin, RetrieveModelMixin |
|
|
from rest_framework.mixins import ListModelMixin, RetrieveModelMixin |
|
|
from rest_framework.permissions import (IsAuthenticated, |
|
|
from rest_framework.permissions import (IsAuthenticated, |
|
|
IsAuthenticatedOrReadOnly, AllowAny) |
|
|
IsAuthenticatedOrReadOnly, AllowAny) |
|
|
from rest_framework.response import Response |
|
|
from rest_framework.viewsets import GenericViewSet |
|
|
from rest_framework.viewsets import GenericViewSet, ModelViewSet |
|
|
|
|
|
|
|
|
|
|
|
from sapl.api.forms import (AutorChoiceFilterSet, AutoresPossiveisFilterSet, |
|
|
from sapl.api.forms import (AutorChoiceFilterSet, AutoresPossiveisFilterSet, |
|
|
AutorSearchForFieldFilterSet) |
|
|
AutorSearchForFieldFilterSet) |
|
|
from sapl.api.permissions import SaplModelPermissions |
|
|
from sapl.api.serializers import ModelChoiceSerializer, AutorSerializer,\ |
|
|
from sapl.api.serializers import (AutorChoiceSerializer, AutorSerializer, |
|
|
ChoiceSerializer |
|
|
ChoiceSerializer, |
|
|
from sapl.base.models import TipoAutor, Autor, CasaLegislativa |
|
|
ModelChoiceSerializer, |
|
|
from sapl.materia.models import MateriaLegislativa |
|
|
SessaoPlenariaOldSerializer, |
|
|
from sapl.sessao.models import SessaoPlenaria, OrdemDia |
|
|
MateriaLegislativaOldSerializer) |
|
|
|
|
|
from sapl.base.models import TipoAutor, Autor |
|
|
|
|
|
from sapl.comissoes.models import Comissao |
|
|
|
|
|
from sapl.materia.models import MateriaLegislativa, Proposicao |
|
|
|
|
|
from sapl.parlamentares.models import Parlamentar |
|
|
|
|
|
from sapl.sessao.models import SessaoPlenaria |
|
|
|
|
|
from sapl.utils import SaplGenericRelation |
|
|
from sapl.utils import SaplGenericRelation |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class AutorChoiceSerializer(ModelChoiceSerializer): |
|
|
|
|
|
|
|
|
|
|
|
def get_text(self, obj): |
|
|
|
|
|
return obj.nome |
|
|
|
|
|
|
|
|
|
|
|
class Meta: |
|
|
|
|
|
model = Autor |
|
|
|
|
|
fields = ['id', 'nome'] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class MateriaLegislativaOldSerializer(serializers.ModelSerializer): |
|
|
|
|
|
|
|
|
|
|
|
class Meta: |
|
|
|
|
|
model = MateriaLegislativa |
|
|
|
|
|
fields = '__all__' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class SessaoPlenariaOldSerializer(serializers.ModelSerializer): |
|
|
|
|
|
|
|
|
|
|
|
codReuniao = serializers.SerializerMethodField('get_pk_sessao') |
|
|
|
|
|
codReuniaoPrincipal = serializers.SerializerMethodField('get_pk_sessao') |
|
|
|
|
|
txtTituloReuniao = serializers.SerializerMethodField('get_name') |
|
|
|
|
|
txtSiglaOrgao = serializers.SerializerMethodField('get_sigla_orgao') |
|
|
|
|
|
txtApelido = serializers.SerializerMethodField('get_name') |
|
|
|
|
|
txtNomeOrgao = serializers.SerializerMethodField('get_nome_orgao') |
|
|
|
|
|
codEstadoReuniao = serializers.SerializerMethodField( |
|
|
|
|
|
'get_estadoSessaoPlenaria') |
|
|
|
|
|
txtTipoReuniao = serializers.SerializerMethodField('get_tipo_sessao') |
|
|
|
|
|
txtObjeto = serializers.SerializerMethodField('get_assunto_sessao') |
|
|
|
|
|
txtLocal = serializers.SerializerMethodField('get_endereco_orgao') |
|
|
|
|
|
bolReuniaoConjunta = serializers.SerializerMethodField( |
|
|
|
|
|
'get_reuniao_conjunta') |
|
|
|
|
|
bolHabilitarEventoInterativo = serializers.SerializerMethodField( |
|
|
|
|
|
'get_iterativo') |
|
|
|
|
|
idYoutube = serializers.SerializerMethodField('get_url') |
|
|
|
|
|
codEstadoTransmissaoYoutube = serializers.SerializerMethodField( |
|
|
|
|
|
'get_estadoTransmissaoYoutube') |
|
|
|
|
|
datReuniaoString = serializers.SerializerMethodField('get_date') |
|
|
|
|
|
|
|
|
|
|
|
# Constantes SessaoPlenaria (de 1-9) (apenas 3 serão usados) |
|
|
|
|
|
SESSAO_FINALIZADA = 4 |
|
|
|
|
|
SESSAO_EM_ANDAMENTO = 3 |
|
|
|
|
|
SESSAO_CONVOCADA = 2 |
|
|
|
|
|
|
|
|
|
|
|
# Constantes EstadoTranmissaoYoutube (de 0 a 2) |
|
|
|
|
|
TRANSMISSAO_ENCERRADA = 2 |
|
|
|
|
|
TRANSMISSAO_EM_ANDAMENTO = 1 |
|
|
|
|
|
SEM_TRANSMISSAO = 0 |
|
|
|
|
|
|
|
|
|
|
|
class Meta: |
|
|
|
|
|
model = SessaoPlenaria |
|
|
|
|
|
fields = ( |
|
|
|
|
|
'codReuniao', |
|
|
|
|
|
'codReuniaoPrincipal', |
|
|
|
|
|
'txtTituloReuniao', |
|
|
|
|
|
'txtSiglaOrgao', |
|
|
|
|
|
'txtApelido', |
|
|
|
|
|
'txtNomeOrgao', |
|
|
|
|
|
'codEstadoReuniao', |
|
|
|
|
|
'txtTipoReuniao', |
|
|
|
|
|
'txtObjeto', |
|
|
|
|
|
'txtLocal', |
|
|
|
|
|
'bolReuniaoConjunta', |
|
|
|
|
|
'bolHabilitarEventoInterativo', |
|
|
|
|
|
'idYoutube', |
|
|
|
|
|
'codEstadoTransmissaoYoutube', |
|
|
|
|
|
'datReuniaoString' |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs): |
|
|
|
|
|
super(SessaoPlenariaOldSerializer, self).__init__(args, kwargs) |
|
|
|
|
|
|
|
|
|
|
|
def get_pk_sessao(self, obj): |
|
|
|
|
|
return obj.pk |
|
|
|
|
|
|
|
|
|
|
|
def get_name(self, obj): |
|
|
|
|
|
return obj.__str__() |
|
|
|
|
|
|
|
|
|
|
|
def get_estadoSessaoPlenaria(self, obj): |
|
|
|
|
|
if obj.finalizada: |
|
|
|
|
|
return self.SESSAO_FINALIZADA |
|
|
|
|
|
elif obj.iniciada: |
|
|
|
|
|
return self.SESSAO_EM_ANDAMENTO |
|
|
|
|
|
else: |
|
|
|
|
|
return self.SESSAO_CONVOCADA |
|
|
|
|
|
|
|
|
|
|
|
def get_tipo_sessao(self, obj): |
|
|
|
|
|
return obj.tipo.__str__() |
|
|
|
|
|
|
|
|
|
|
|
def get_url(self, obj): |
|
|
|
|
|
return obj.url_video if obj.url_video else None |
|
|
|
|
|
|
|
|
|
|
|
def get_iterativo(self, obj): |
|
|
|
|
|
return obj.interativa if obj.interativa else False |
|
|
|
|
|
|
|
|
|
|
|
def get_date(self, obj): |
|
|
|
|
|
return "{} {}{}".format( |
|
|
|
|
|
obj.data_inicio.strftime("%d/%m/%Y"), |
|
|
|
|
|
obj.hora_inicio, |
|
|
|
|
|
":00" |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
def get_estadoTransmissaoYoutube(self, obj): |
|
|
|
|
|
if obj.url_video: |
|
|
|
|
|
if obj.finalizada: |
|
|
|
|
|
return self.TRANSMISSAO_ENCERRADA |
|
|
|
|
|
else: |
|
|
|
|
|
return self.TRANSMISSAO_EM_ANDAMENTO |
|
|
|
|
|
else: |
|
|
|
|
|
return self.SEM_TRANSMISSAO |
|
|
|
|
|
|
|
|
|
|
|
def get_assunto_sessao(self, obj): |
|
|
|
|
|
pauta_sessao = '' |
|
|
|
|
|
ordem_dia = OrdemDia.objects.filter(sessao_plenaria=obj.pk) |
|
|
|
|
|
pauta_sessao = ', '.join([i.materia.__str__() for i in ordem_dia]) |
|
|
|
|
|
|
|
|
|
|
|
return str(pauta_sessao) |
|
|
|
|
|
|
|
|
|
|
|
def get_endereco_orgao(self, obj): |
|
|
|
|
|
return self.casa().endereco |
|
|
|
|
|
|
|
|
|
|
|
def get_reuniao_conjunta(self, obj): |
|
|
|
|
|
return False |
|
|
|
|
|
|
|
|
|
|
|
def get_sigla_orgao(self, obj): |
|
|
|
|
|
return self.casa().sigla |
|
|
|
|
|
|
|
|
|
|
|
def get_nome_orgao(self, obj): |
|
|
|
|
|
return self.casa().nome |
|
|
|
|
|
|
|
|
|
|
|
def casa(self): |
|
|
|
|
|
casa = CasaLegislativa.objects.first() |
|
|
|
|
|
return casa |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ModelChoiceView(ListAPIView): |
|
|
class ModelChoiceView(ListAPIView): |
|
|
""" |
|
|
""" |
|
|
Deprecated |
|
|
Deprecated |
|
|