|
|
@ -3,22 +3,24 @@ from re import sub |
|
|
|
|
|
|
|
from braces.views import PermissionRequiredMixin |
|
|
|
from django.contrib import messages |
|
|
|
from django.contrib.auth.decorators import permission_required |
|
|
|
from django.core.exceptions import ObjectDoesNotExist, ValidationError |
|
|
|
from django.core.urlresolvers import reverse |
|
|
|
from django.forms.utils import ErrorList |
|
|
|
from django.http import JsonResponse |
|
|
|
from django.http.response import HttpResponseRedirect |
|
|
|
from django.utils.datastructures import MultiValueDictKeyError |
|
|
|
from django.utils.decorators import method_decorator |
|
|
|
from django.utils.html import strip_tags |
|
|
|
from django.utils.translation import ugettext_lazy as _ |
|
|
|
from django.views.generic import ListView, TemplateView |
|
|
|
from django.views.generic.detail import DetailView |
|
|
|
from django.views.generic.edit import FormMixin |
|
|
|
from django_filters.views import FilterView |
|
|
|
from rest_framework import generics |
|
|
|
|
|
|
|
from sapl.crud.base import (Crud, CrudBaseMixin, CrudCreateView, |
|
|
|
CrudDeleteView, CrudDetailView, CrudListView, |
|
|
|
CrudUpdateView, MasterDetailCrud, make_pagination) |
|
|
|
from sapl.crud.base import (Crud, MasterDetailCrud, make_pagination, |
|
|
|
CrudAux, RP_CHANGE, RP_DETAIL, RP_LIST,) |
|
|
|
from sapl.materia.forms import pega_ultima_tramitacao |
|
|
|
from sapl.materia.models import (Autoria, DocumentoAcessorio, |
|
|
|
TipoMateriaLegislativa, Tramitacao) |
|
|
@ -26,6 +28,7 @@ from sapl.materia.views import MateriaLegislativaPesquisaView |
|
|
|
from sapl.norma.models import NormaJuridica |
|
|
|
from sapl.parlamentares.models import (Parlamentar, SessaoLegislativa, |
|
|
|
Legislatura) |
|
|
|
from sapl.sessao.apps import AppConfig |
|
|
|
from sapl.sessao.serializers import SessaoPlenariaSerializer |
|
|
|
from sapl.utils import permissao_tb_aux, permissoes_painel, permissoes_sessao |
|
|
|
|
|
|
@ -42,9 +45,23 @@ from .models import (Bancada, Bloco, CargoBancada, CargoMesa, |
|
|
|
SessaoPlenariaPresenca, TipoExpediente, |
|
|
|
TipoResultadoVotacao, TipoSessaoPlenaria, VotoParlamentar) |
|
|
|
|
|
|
|
|
|
|
|
OrdemDiaCrud = Crud.build(OrdemDia, '') |
|
|
|
RegistroVotacaoCrud = Crud.build(RegistroVotacao, '') |
|
|
|
|
|
|
|
TipoSessaoCrud = CrudAux.build(TipoSessaoPlenaria, 'tipo_sessao_plenaria') |
|
|
|
TipoExpedienteCrud = CrudAux.build(TipoExpediente, 'tipo_expediente') |
|
|
|
CargoBancadaCrud = CrudAux.build(CargoBancada, '') |
|
|
|
TipoSessaoCrud = CrudAux.build(TipoSessaoPlenaria, 'tipo_sessao_plenaria') |
|
|
|
TipoSessaoCrud = CrudAux.build(TipoSessaoPlenaria, 'tipo_sessao_plenaria') |
|
|
|
|
|
|
|
BlocoCrud = CrudAux.build( |
|
|
|
Bloco, '', list_field_names=['nome', 'data_criacao', 'partidos']) |
|
|
|
BancadaCrud = CrudAux.build( |
|
|
|
Bancada, '', list_field_names=['nome', 'legislatura']) |
|
|
|
TipoResultadoVotacaoCrud = CrudAux.build( |
|
|
|
TipoResultadoVotacao, 'tipo_resultado_votacao') |
|
|
|
|
|
|
|
|
|
|
|
def reordernar_materias_expediente(request, pk): |
|
|
|
expedientes = ExpedienteMateria.objects.filter( |
|
|
@ -72,77 +89,6 @@ def reordernar_materias_ordem(request, pk): |
|
|
|
reverse('sapl.sessao:ordemdia_list', kwargs={'pk': pk})) |
|
|
|
|
|
|
|
|
|
|
|
class BlocoCrud(Crud): |
|
|
|
model = Bloco |
|
|
|
help_path = '' |
|
|
|
|
|
|
|
class BaseMixin(CrudBaseMixin): |
|
|
|
list_field_names = ['nome', 'data_criacao', 'partidos'] |
|
|
|
|
|
|
|
def has_permission(self): |
|
|
|
return permissao_tb_aux(self) |
|
|
|
|
|
|
|
|
|
|
|
class BancadaCrud(Crud): |
|
|
|
model = Bancada |
|
|
|
help_path = '' |
|
|
|
|
|
|
|
class BaseMixin(CrudBaseMixin): |
|
|
|
list_field_names = ['nome', 'legislatura'] |
|
|
|
|
|
|
|
def has_permission(self): |
|
|
|
return permissao_tb_aux(self) |
|
|
|
|
|
|
|
class ListView(CrudListView): |
|
|
|
ordering = 'legislatura' |
|
|
|
|
|
|
|
class CreateView(CrudCreateView): |
|
|
|
form_class = BancadaForm |
|
|
|
|
|
|
|
class UpdateView(CrudUpdateView): |
|
|
|
form_class = BancadaForm |
|
|
|
|
|
|
|
|
|
|
|
class TipoSessaoCrud(Crud): |
|
|
|
model = TipoSessaoPlenaria |
|
|
|
help_path = 'tipo_sessao_plenaria' |
|
|
|
|
|
|
|
class BaseMixin(CrudBaseMixin): |
|
|
|
|
|
|
|
def has_permission(self): |
|
|
|
return permissao_tb_aux(self) |
|
|
|
|
|
|
|
|
|
|
|
class TipoResultadoVotacaoCrud(Crud): |
|
|
|
model = TipoResultadoVotacao |
|
|
|
help_path = 'tipo_resultado_votacao' |
|
|
|
|
|
|
|
class BaseMixin(CrudBaseMixin): |
|
|
|
|
|
|
|
def has_permission(self): |
|
|
|
return permissao_tb_aux(self) |
|
|
|
|
|
|
|
|
|
|
|
class TipoExpedienteCrud(Crud): |
|
|
|
model = TipoExpediente |
|
|
|
help_path = 'tipo_expediente' |
|
|
|
|
|
|
|
class BaseMixin(CrudBaseMixin): |
|
|
|
|
|
|
|
def has_permission(self): |
|
|
|
return permissao_tb_aux(self) |
|
|
|
|
|
|
|
|
|
|
|
class CargoBancadaCrud(Crud): |
|
|
|
model = CargoBancada |
|
|
|
help_path = '' |
|
|
|
|
|
|
|
class BaseMixin(CrudBaseMixin): |
|
|
|
|
|
|
|
def has_permission(self): |
|
|
|
return permissao_tb_aux(self) |
|
|
|
|
|
|
|
|
|
|
|
def abrir_votacao_expediente_view(request, pk, spk): |
|
|
|
existe_votacao_aberta = ExpedienteMateria.objects.filter( |
|
|
|
sessao_plenaria_id=spk, votacao_aberta=True |
|
|
@ -245,7 +191,7 @@ class MateriaOrdemDiaCrud(MasterDetailCrud): |
|
|
|
url = reverse('sapl.sessao:abrir_votacao', kwargs={ |
|
|
|
'pk': obj.pk, 'spk': obj.sessao_plenaria_id}) |
|
|
|
|
|
|
|
if self.request.user.has_perms(permissoes_sessao()): |
|
|
|
if self.request.user.has_module_perms(AppConfig.label): |
|
|
|
btn_abrir = ''' |
|
|
|
Matéria não votada<br /> |
|
|
|
<a href="%s" |
|
|
@ -255,7 +201,7 @@ class MateriaOrdemDiaCrud(MasterDetailCrud): |
|
|
|
else: |
|
|
|
obj.resultado = '''Não há resultado''' |
|
|
|
else: |
|
|
|
if self.request.user.has_perms(permissoes_sessao()): |
|
|
|
if self.request.user.has_module_perms(AppConfig.label): |
|
|
|
url = '' |
|
|
|
if obj.tipo_votacao == 1: |
|
|
|
url = reverse('sapl.sessao:votacaosimbolicaedit', |
|
|
@ -309,7 +255,7 @@ class ExpedienteMateriaCrud(MasterDetailCrud): |
|
|
|
list_field_names = ['numero_ordem', 'materia', |
|
|
|
'observacao', 'resultado'] |
|
|
|
|
|
|
|
class ListView(MasterDetailCrud.ListView): |
|
|
|
class ListView(Crud.PublicMixin, MasterDetailCrud.ListView): |
|
|
|
ordering = ['numero_ordem', 'materia', 'resultado'] |
|
|
|
|
|
|
|
def get_rows(self, object_list): |
|
|
@ -349,6 +295,7 @@ class ExpedienteMateriaCrud(MasterDetailCrud): |
|
|
|
<a href="%s" |
|
|
|
class="btn btn-primary" |
|
|
|
role="button">Abrir Votação</a>''' % (url) |
|
|
|
|
|
|
|
obj.resultado = btn_abrir |
|
|
|
else: |
|
|
|
url = '' |
|
|
@ -376,7 +323,6 @@ class ExpedienteMateriaCrud(MasterDetailCrud): |
|
|
|
|
|
|
|
class CreateView(MasterDetailCrud.CreateView): |
|
|
|
form_class = ExpedienteMateriaForm |
|
|
|
permission_required = permissoes_sessao() |
|
|
|
|
|
|
|
def get_success_url(self): |
|
|
|
return reverse('sapl.sessao:expedientemateria_list', |
|
|
@ -384,7 +330,6 @@ class ExpedienteMateriaCrud(MasterDetailCrud): |
|
|
|
|
|
|
|
class UpdateView(MasterDetailCrud.UpdateView): |
|
|
|
form_class = ExpedienteMateriaForm |
|
|
|
permission_required = permissoes_sessao() |
|
|
|
|
|
|
|
def get_initial(self): |
|
|
|
self.initial['tipo_materia'] = self.object.materia.tipo.id |
|
|
@ -392,9 +337,6 @@ class ExpedienteMateriaCrud(MasterDetailCrud): |
|
|
|
self.initial['ano_materia'] = self.object.materia.ano |
|
|
|
return self.initial |
|
|
|
|
|
|
|
class DeleteView(PermissionRequiredMixin, MasterDetailCrud.DeleteView): |
|
|
|
permission_required = permissoes_sessao() |
|
|
|
|
|
|
|
class DetailView(MasterDetailCrud.DetailView): |
|
|
|
|
|
|
|
@property |
|
|
@ -406,25 +348,16 @@ class OradorCrud(MasterDetailCrud): |
|
|
|
model = '' |
|
|
|
parent_field = 'sessao_plenaria' |
|
|
|
help_path = '' |
|
|
|
public = [RP_LIST, RP_DETAIL] |
|
|
|
|
|
|
|
class ListView(MasterDetailCrud.ListView): |
|
|
|
ordering = ['numero_ordem', 'parlamentar'] |
|
|
|
|
|
|
|
class CreateView(MasterDetailCrud.CreateView): |
|
|
|
permission_required = permissoes_sessao() |
|
|
|
|
|
|
|
class UpdateView(MasterDetailCrud.UpdateView): |
|
|
|
permission_required = permissoes_sessao() |
|
|
|
|
|
|
|
class DeleteView(MasterDetailCrud.DeleteView): |
|
|
|
permission_required = permissoes_sessao() |
|
|
|
|
|
|
|
|
|
|
|
class OradorExpedienteCrud(OradorCrud): |
|
|
|
model = OradorExpediente |
|
|
|
|
|
|
|
class CreateView(MasterDetailCrud.CreateView): |
|
|
|
permission_required = permissoes_sessao() |
|
|
|
form_class = OradorExpedienteForm |
|
|
|
|
|
|
|
def get_success_url(self): |
|
|
@ -432,18 +365,13 @@ class OradorExpedienteCrud(OradorCrud): |
|
|
|
kwargs={'pk': self.kwargs['pk']}) |
|
|
|
|
|
|
|
class UpdateView(MasterDetailCrud.UpdateView): |
|
|
|
permission_required = permissoes_sessao() |
|
|
|
form_class = OradorExpedienteForm |
|
|
|
|
|
|
|
class DeleteView(MasterDetailCrud.DeleteView): |
|
|
|
permission_required = permissoes_sessao() |
|
|
|
|
|
|
|
|
|
|
|
class OradorCrud(OradorCrud): |
|
|
|
model = Orador |
|
|
|
|
|
|
|
class CreateView(MasterDetailCrud.CreateView): |
|
|
|
permission_required = permissoes_sessao() |
|
|
|
form_class = OradorForm |
|
|
|
|
|
|
|
def get_success_url(self): |
|
|
@ -451,12 +379,8 @@ class OradorCrud(OradorCrud): |
|
|
|
kwargs={'pk': self.kwargs['pk']}) |
|
|
|
|
|
|
|
class UpdateView(MasterDetailCrud.UpdateView): |
|
|
|
permission_required = permissoes_sessao() |
|
|
|
form_class = OradorForm |
|
|
|
|
|
|
|
class DeleteView(MasterDetailCrud.DeleteView): |
|
|
|
permission_required = permissoes_sessao() |
|
|
|
|
|
|
|
|
|
|
|
def recuperar_numero_sessao(request): |
|
|
|
try: |
|
|
@ -473,22 +397,19 @@ def recuperar_numero_sessao(request): |
|
|
|
class SessaoCrud(Crud): |
|
|
|
model = SessaoPlenaria |
|
|
|
help_path = 'sessao_plenaria' |
|
|
|
public = [RP_DETAIL] |
|
|
|
|
|
|
|
class BaseMixin(CrudBaseMixin): |
|
|
|
class BaseMixin(Crud.BaseMixin): |
|
|
|
list_field_names = ['data_inicio', 'legislatura', 'sessao_legislativa', |
|
|
|
'tipo'] |
|
|
|
|
|
|
|
# FIXME!!!! corrigir referencias no codigo e remover isso!!!!! |
|
|
|
# fazer com #230 |
|
|
|
class CrudDetailView(CrudDetailView): |
|
|
|
class CrudDetailView(DetailView): |
|
|
|
model = SessaoPlenaria |
|
|
|
help_path = 'sessao_plenaria' |
|
|
|
|
|
|
|
class ListView(CrudListView): |
|
|
|
class ListView(Crud.ListView): |
|
|
|
ordering = ['-data_inicio'] |
|
|
|
|
|
|
|
class CreateView(CrudCreateView): |
|
|
|
permission_required = permissoes_sessao() |
|
|
|
class CreateView(Crud.CreateView): |
|
|
|
|
|
|
|
def get_initial(self): |
|
|
|
legislatura = Legislatura.objects.order_by('-numero')[0] |
|
|
@ -497,12 +418,6 @@ class SessaoCrud(Crud): |
|
|
|
return {'legislatura': legislatura, |
|
|
|
'sessao_legislativa': sessao_legislativa} |
|
|
|
|
|
|
|
class UpdateView(CrudUpdateView): |
|
|
|
permission_required = permissoes_sessao() |
|
|
|
|
|
|
|
class DeleteView(CrudDeleteView): |
|
|
|
permission_required = permissoes_sessao() |
|
|
|
|
|
|
|
|
|
|
|
class PresencaMixin: |
|
|
|
|
|
|
@ -535,18 +450,24 @@ class PresencaMixin: |
|
|
|
yield (parlamentar, False) |
|
|
|
|
|
|
|
|
|
|
|
class PresencaView(FormMixin, |
|
|
|
PresencaMixin, |
|
|
|
SessaoCrud.CrudDetailView): |
|
|
|
class PresencaView(FormMixin, PresencaMixin, DetailView): |
|
|
|
template_name = 'sessao/presenca.html' |
|
|
|
form_class = PresencaForm |
|
|
|
model = SessaoPlenaria |
|
|
|
|
|
|
|
@method_decorator(permission_required(( |
|
|
|
'%s.add_%s' % ( |
|
|
|
AppConfig.label, SessaoPlenariaPresenca._meta.model_name), |
|
|
|
'%s.change_%s' % ( |
|
|
|
AppConfig.label, SessaoPlenariaPresenca._meta.model_name), |
|
|
|
'%s.delete_%s' % ( |
|
|
|
AppConfig.label, SessaoPlenariaPresenca._meta.model_name), |
|
|
|
))) |
|
|
|
def post(self, request, *args, **kwargs): |
|
|
|
self.object = self.get_object() |
|
|
|
form = self.get_form() |
|
|
|
|
|
|
|
if not self.request.user.has_perms(permissoes_sessao()): |
|
|
|
if not self.request.user.has_module_perms(AppConfig.label): |
|
|
|
return self.form_invalid(form) |
|
|
|
|
|
|
|
if form.is_valid(): |
|
|
@ -586,12 +507,16 @@ class PainelView(PermissionRequiredMixin, TemplateView): |
|
|
|
permission_required = permissoes_painel() |
|
|
|
|
|
|
|
|
|
|
|
class PresencaOrdemDiaView(FormMixin, |
|
|
|
PresencaMixin, |
|
|
|
SessaoCrud.CrudDetailView): |
|
|
|
class PresencaOrdemDiaView(FormMixin, PresencaMixin, DetailView): |
|
|
|
template_name = 'sessao/presenca_ordemdia.html' |
|
|
|
form_class = PresencaForm |
|
|
|
model = SessaoPlenaria |
|
|
|
|
|
|
|
@method_decorator(permission_required(( |
|
|
|
'%s.add_%s' % (AppConfig.label, PresencaOrdemDia._meta.model_name), |
|
|
|
'%s.change_%s' % (AppConfig.label, PresencaOrdemDia._meta.model_name), |
|
|
|
'%s.delete_%s' % (AppConfig.label, PresencaOrdemDia._meta.model_name), |
|
|
|
))) |
|
|
|
def post(self, request, *args, **kwargs): |
|
|
|
|
|
|
|
self.object = self.get_object() |
|
|
@ -634,9 +559,10 @@ class PresencaOrdemDiaView(FormMixin, |
|
|
|
return reverse('sapl.sessao:presencaordemdia', kwargs={'pk': pk}) |
|
|
|
|
|
|
|
|
|
|
|
class ListMateriaOrdemDiaView(FormMixin, SessaoCrud.CrudDetailView): |
|
|
|
class ListMateriaOrdemDiaView(FormMixin, DetailView): |
|
|
|
template_name = 'sessao/materia_ordemdia_list.html' |
|
|
|
form_class = ListMateriaForm |
|
|
|
model = SessaoPlenaria |
|
|
|
|
|
|
|
def get(self, request, *args, **kwargs): |
|
|
|
self.object = self.get_object() |
|
|
@ -673,6 +599,11 @@ class ListMateriaOrdemDiaView(FormMixin, SessaoCrud.CrudDetailView): |
|
|
|
|
|
|
|
return self.render_to_response(context) |
|
|
|
|
|
|
|
@method_decorator(permission_required(( |
|
|
|
'%s.add_%s' % (AppConfig.label, OrdemDia._meta.model_name), |
|
|
|
'%s.change_%s' % (AppConfig.label, OrdemDia._meta.model_name), |
|
|
|
'%s.delete_%s' % (AppConfig.label, OrdemDia._meta.model_name), |
|
|
|
))) |
|
|
|
def post(self, request, *args, **kwargs): |
|
|
|
self.object = self.get_object() |
|
|
|
context = self.get_context_data(object=self.object) |
|
|
@ -737,12 +668,13 @@ class ListMateriaOrdemDiaView(FormMixin, SessaoCrud.CrudDetailView): |
|
|
|
return self.get(self, request, args, kwargs) |
|
|
|
|
|
|
|
|
|
|
|
class MesaView(PermissionRequiredMixin, FormMixin, SessaoCrud.CrudDetailView): |
|
|
|
class MesaView(FormMixin, DetailView): |
|
|
|
template_name = 'sessao/mesa.html' |
|
|
|
form_class = MesaForm |
|
|
|
permission_required = permissoes_sessao() |
|
|
|
model = SessaoPlenaria |
|
|
|
|
|
|
|
def get(self, request, *args, **kwargs): |
|
|
|
|
|
|
|
self.object = self.get_object() |
|
|
|
context = self.get_context_data(object=self.object) |
|
|
|
|
|
|
@ -762,6 +694,11 @@ class MesaView(PermissionRequiredMixin, FormMixin, SessaoCrud.CrudDetailView): |
|
|
|
|
|
|
|
return self.render_to_response(context) |
|
|
|
|
|
|
|
@method_decorator(permission_required(( |
|
|
|
'%s.add_integrantemesa' % AppConfig.label, |
|
|
|
'%s.change_integrantemesa' % AppConfig.label, |
|
|
|
'%s.delete_integrantemesa' % AppConfig.label, |
|
|
|
))) |
|
|
|
def post(self, request, *args, **kwargs): |
|
|
|
self.object = self.get_object() |
|
|
|
form = MesaForm(request.POST) |
|
|
|