|
|
|
@ -23,7 +23,7 @@ from sessao.serializers import SessaoPlenariaSerializer |
|
|
|
|
|
|
|
from .forms import (ExpedienteForm, ListMateriaForm, MateriaOrdemDiaForm, |
|
|
|
MesaForm, PresencaForm, VotacaoEditForm, VotacaoForm, |
|
|
|
VotacaoNominalForm) |
|
|
|
VotacaoNominalForm, ExpedienteMateriaForm) |
|
|
|
from .models import (CargoMesa, ExpedienteMateria, ExpedienteSessao, |
|
|
|
IntegranteMesa, MateriaLegislativa, Orador, |
|
|
|
OradorExpediente, OrdemDia, PresencaOrdemDia, |
|
|
|
@ -32,7 +32,6 @@ from .models import (CargoMesa, ExpedienteMateria, ExpedienteSessao, |
|
|
|
VotoParlamentar) |
|
|
|
|
|
|
|
TipoSessaoCrud = Crud.build(TipoSessaoPlenaria, 'tipo_sessao_plenaria') |
|
|
|
ExpedienteMateriaCrud = Crud.build(ExpedienteMateria, '') |
|
|
|
OrdemDiaCrud = Crud.build(OrdemDia, '') |
|
|
|
TipoResultadoVotacaoCrud = Crud.build( |
|
|
|
TipoResultadoVotacao, 'tipo_resultado_votacao') |
|
|
|
@ -40,6 +39,50 @@ TipoExpedienteCrud = Crud.build(TipoExpediente, 'tipo_expediente') |
|
|
|
RegistroVotacaoCrud = Crud.build(RegistroVotacao, '') |
|
|
|
|
|
|
|
|
|
|
|
class ExpedienteMateriaCrud(MasterDetailCrud): |
|
|
|
model = ExpedienteMateria |
|
|
|
parent_field = 'sessao_plenaria' |
|
|
|
help_path = '' |
|
|
|
|
|
|
|
class BaseMixin(MasterDetailCrud.BaseMixin): |
|
|
|
list_field_names = ['numero_ordem', 'materia', |
|
|
|
'observacao', 'resultado'] |
|
|
|
|
|
|
|
class ListView(MasterDetailCrud.ListView): |
|
|
|
ordering = ['numero_ordem', 'materia', 'resultado'] |
|
|
|
# |
|
|
|
# def get_rows(self, object_list): |
|
|
|
# |
|
|
|
# btn_abrir = ''' |
|
|
|
# Matéria não votada <br /> |
|
|
|
# <a href=""> |
|
|
|
# Abrir Votação |
|
|
|
# </a>''' |
|
|
|
# for obj in object_list: |
|
|
|
# if not obj.resultado: |
|
|
|
# obj.resultado = btn_abrir |
|
|
|
# |
|
|
|
# return [self._as_row(obj) for obj in object_list] |
|
|
|
|
|
|
|
class CreateView(MasterDetailCrud.CreateView): |
|
|
|
form_class = ExpedienteMateriaForm |
|
|
|
|
|
|
|
class UpdateView(MasterDetailCrud.UpdateView): |
|
|
|
form_class = ExpedienteMateriaForm |
|
|
|
|
|
|
|
def get_initial(self): |
|
|
|
self.initial['tipo_materia'] = self.object.materia.tipo.id |
|
|
|
self.initial['numero_materia'] = self.object.materia.numero |
|
|
|
self.initial['ano_materia'] = self.object.materia.ano |
|
|
|
return self.initial |
|
|
|
|
|
|
|
class DetailView(MasterDetailCrud.DetailView): |
|
|
|
|
|
|
|
@property |
|
|
|
def layout_key(self): |
|
|
|
return 'ExpedienteMateriaDetail' |
|
|
|
|
|
|
|
|
|
|
|
class OradorCrud(MasterDetailCrud): |
|
|
|
model = '' |
|
|
|
parent_field = 'sessao_plenaria' |
|
|
|
@ -282,107 +325,6 @@ class ListMateriaOrdemDiaView(FormMixin, SessaoCrud.CrudDetailView): |
|
|
|
return self.get(self, request, args, kwargs) |
|
|
|
|
|
|
|
|
|
|
|
class ListExpedienteOrdemDiaView(FormMixin, SessaoCrud.CrudDetailView): |
|
|
|
template_name = 'sessao/expediente_ordemdia_list.html' |
|
|
|
form_class = ListMateriaForm |
|
|
|
|
|
|
|
def get(self, request, *args, **kwargs): |
|
|
|
self.object = self.get_object() |
|
|
|
context = self.get_context_data(object=self.object) |
|
|
|
|
|
|
|
pk = self.kwargs['pk'] |
|
|
|
ordem = ExpedienteMateria.objects.filter(sessao_plenaria_id=pk) |
|
|
|
|
|
|
|
materias_ordem = [] |
|
|
|
for o in ordem: |
|
|
|
ementa = o.observacao |
|
|
|
titulo = o.materia |
|
|
|
numero = o.numero_ordem |
|
|
|
|
|
|
|
autoria = Autoria.objects.filter(materia_id=o.materia_id) |
|
|
|
autor = [str(a.autor) for a in autoria] |
|
|
|
|
|
|
|
mat = {'pk': pk, |
|
|
|
'oid': o.materia_id, |
|
|
|
'ordem_id': o.id, |
|
|
|
'ementa': ementa, |
|
|
|
'titulo': titulo, |
|
|
|
'numero': numero, |
|
|
|
'resultado': o.resultado, |
|
|
|
'autor': autor, |
|
|
|
'votacao_aberta': o.votacao_aberta, |
|
|
|
'tipo_votacao': o.tipo_votacao |
|
|
|
} |
|
|
|
materias_ordem.append(mat) |
|
|
|
|
|
|
|
sorted(materias_ordem, key=lambda x: x['numero']) |
|
|
|
|
|
|
|
context.update({'materias_ordem': materias_ordem}) |
|
|
|
|
|
|
|
return self.render_to_response(context) |
|
|
|
|
|
|
|
def post(self, request, *args, **kwargs): |
|
|
|
self.object = self.get_object() |
|
|
|
pk = self.kwargs['pk'] |
|
|
|
form = ListMateriaForm(request.POST) |
|
|
|
|
|
|
|
if 'materia_reorder' in request.POST: |
|
|
|
expedientes = ExpedienteMateria.objects.filter( |
|
|
|
sessao_plenaria_id=pk) |
|
|
|
exp_num = 1 |
|
|
|
for e in expedientes: |
|
|
|
e.numero_ordem = exp_num |
|
|
|
e.save() |
|
|
|
exp_num += 1 |
|
|
|
elif 'abrir-votacao' in request.POST: |
|
|
|
existe_votacao_aberta = ExpedienteMateria.objects.filter( |
|
|
|
sessao_plenaria_id=pk, votacao_aberta=True |
|
|
|
).exists() |
|
|
|
|
|
|
|
if existe_votacao_aberta: |
|
|
|
context = self.get_context_data(object=self.object) |
|
|
|
|
|
|
|
form._errors = {'error_message': 'error_message'} |
|
|
|
context.update({'form': form}) |
|
|
|
|
|
|
|
pk = self.kwargs['pk'] |
|
|
|
ordem = ExpedienteMateria.objects.filter( |
|
|
|
sessao_plenaria_id=pk) |
|
|
|
|
|
|
|
materias_ordem = [] |
|
|
|
for o in ordem: |
|
|
|
ementa = o.observacao |
|
|
|
titulo = o.materia |
|
|
|
numero = o.numero_ordem |
|
|
|
|
|
|
|
autoria = Autoria.objects.filter(materia_id=o.materia_id) |
|
|
|
autor = [str(a.autor) for a in autoria] |
|
|
|
|
|
|
|
mat = {'pk': pk, |
|
|
|
'oid': o.materia_id, |
|
|
|
'ordem_id': o.id, |
|
|
|
'ementa': ementa, |
|
|
|
'titulo': titulo, |
|
|
|
'numero': numero, |
|
|
|
'resultado': o.resultado, |
|
|
|
'autor': autor, |
|
|
|
'votacao_aberta': o.votacao_aberta, |
|
|
|
'tipo_votacao': o.tipo_votacao |
|
|
|
} |
|
|
|
materias_ordem.append(mat) |
|
|
|
|
|
|
|
sorted(materias_ordem, key=lambda x: x['numero']) |
|
|
|
|
|
|
|
context.update({'materias_ordem': materias_ordem}) |
|
|
|
return self.render_to_response(context) |
|
|
|
else: |
|
|
|
ordem_id = request.POST['ordem_id'] |
|
|
|
ordem = ExpedienteMateria.objects.get(id=ordem_id) |
|
|
|
ordem.votacao_aberta = True |
|
|
|
ordem.save() |
|
|
|
return self.get(self, request, args, kwargs) |
|
|
|
|
|
|
|
|
|
|
|
class MateriaOrdemDiaView(FormMixin, SessaoCrud.CrudDetailView): |
|
|
|
template_name = 'sessao/materia_ordemdia.html' |
|
|
|
form_class = MateriaOrdemDiaForm |
|
|
|
@ -558,155 +500,6 @@ class EditMateriaOrdemDiaView(FormMixin, SessaoCrud.CrudDetailView): |
|
|
|
kwargs={'pk': pk}) |
|
|
|
|
|
|
|
|
|
|
|
class ExpedienteOrdemDiaView(FormMixin, SessaoCrud.CrudDetailView): |
|
|
|
template_name = 'sessao/materia_ordemdia.html' |
|
|
|
form_class = MateriaOrdemDiaForm |
|
|
|
|
|
|
|
def get(self, request, *args, **kwargs): |
|
|
|
self.object = self.get_object() |
|
|
|
context = self.get_context_data(object=self.object) |
|
|
|
|
|
|
|
now = datetime.now() |
|
|
|
|
|
|
|
tipo_materia = TipoMateriaLegislativa.objects.all() |
|
|
|
data_sessao = now |
|
|
|
tipo_sessao = TipoSessaoPlenaria.objects.all() |
|
|
|
tipo_votacao = ExpedienteMateria.TIPO_VOTACAO_CHOICES |
|
|
|
ano_materia = now.year |
|
|
|
|
|
|
|
context.update({'data_sessao': data_sessao, |
|
|
|
'tipo_sessao': tipo_sessao, |
|
|
|
'tipo_materia': tipo_materia, |
|
|
|
'tipo_votacao': tipo_votacao, |
|
|
|
'ano_materia': ano_materia, |
|
|
|
'error_message': '', }) |
|
|
|
return self.render_to_response(context) |
|
|
|
|
|
|
|
def post(self, request, *args, **kwargs): |
|
|
|
|
|
|
|
self.object = self.get_object() |
|
|
|
context = self.get_context_data(object=self.object) |
|
|
|
form = MateriaOrdemDiaForm(request.POST) |
|
|
|
|
|
|
|
if form.is_valid(): |
|
|
|
try: |
|
|
|
materia = MateriaLegislativa.objects.get( |
|
|
|
numero=request.POST['numero_materia'], |
|
|
|
tipo_id=request.POST['tipo_materia'], |
|
|
|
ano=request.POST['ano_materia']) |
|
|
|
except ObjectDoesNotExist: |
|
|
|
form._errors["error_message"] = ErrorList([u""]) |
|
|
|
context.update({'form': form}) |
|
|
|
return self.render_to_response(context) |
|
|
|
|
|
|
|
# TODO: barrar matérias não existentes |
|
|
|
# TODO: barrar criação de ordemdia para materias já incluídas |
|
|
|
|
|
|
|
ordemdia = ExpedienteMateria() |
|
|
|
ordemdia.sessao_plenaria_id = self.object.id |
|
|
|
ordemdia.materia_id = materia.id |
|
|
|
ordemdia.numero_ordem = request.POST['numero_ordem'] |
|
|
|
ordemdia.data_ordem = datetime.now() |
|
|
|
ordemdia.observacao = sub(' ', ' ', |
|
|
|
strip_tags(request.POST['observacao'])) |
|
|
|
ordemdia.tipo_votacao = request.POST['tipo_votacao'] |
|
|
|
ordemdia.save() |
|
|
|
|
|
|
|
return self.form_valid(form) |
|
|
|
else: |
|
|
|
context.update( |
|
|
|
{'error_message': _("Não foi possível salvar formulário!")}) |
|
|
|
return self.form_invalid(form) |
|
|
|
|
|
|
|
def get_success_url(self): |
|
|
|
pk = self.kwargs['pk'] |
|
|
|
return reverse('sessao:expedienteordemdia_list', |
|
|
|
kwargs={'pk': pk}) |
|
|
|
|
|
|
|
|
|
|
|
class EditExpedienteOrdemDiaView(FormMixin, SessaoCrud.CrudDetailView): |
|
|
|
template_name = 'sessao/materia_ordemdia_edit.html' |
|
|
|
form_class = MateriaOrdemDiaForm |
|
|
|
|
|
|
|
def get(self, request, *args, **kwargs): |
|
|
|
self.object = self.get_object() |
|
|
|
context = self.get_context_data(object=self.object) |
|
|
|
|
|
|
|
pk = kwargs['pk'] |
|
|
|
oid = kwargs['oid'] |
|
|
|
ordem = ExpedienteMateria.objects.get( |
|
|
|
sessao_plenaria_id=pk, materia_id=oid) |
|
|
|
|
|
|
|
materia = MateriaLegislativa.objects.get( |
|
|
|
id=ordem.materia_id) |
|
|
|
|
|
|
|
data_ordem = ordem.data_ordem |
|
|
|
tipo_votacao = ExpedienteMateria.TIPO_VOTACAO_CHOICES |
|
|
|
tipo_sessao = TipoSessaoPlenaria.objects.all() |
|
|
|
tipo_materia = TipoMateriaLegislativa.objects.all() |
|
|
|
|
|
|
|
context.update({'data_sessao': data_ordem, |
|
|
|
'tipo_sessao': tipo_sessao, |
|
|
|
'tipo_sessao_selected': self.object.tipo, |
|
|
|
'tipo_materia': tipo_materia, |
|
|
|
'tipo_materia_selected': materia.tipo, |
|
|
|
'tipo_votacao': tipo_votacao, |
|
|
|
'tipo_votacao_selected': ordem.tipo_votacao, |
|
|
|
'ano_materia': materia.ano, |
|
|
|
'numero_ordem': ordem.numero_ordem, |
|
|
|
'numero_materia': materia.numero, |
|
|
|
'ordem_id': oid, |
|
|
|
'oid': '', |
|
|
|
'observacao': sub( |
|
|
|
' ', ' ', strip_tags(ordem.observacao)), |
|
|
|
'error_message': '', }) |
|
|
|
return self.render_to_response(context) |
|
|
|
|
|
|
|
def post(self, request, *args, **kwargs): |
|
|
|
|
|
|
|
self.object = self.get_object() |
|
|
|
context = self.get_context_data(object=self.object) |
|
|
|
form = MateriaOrdemDiaForm(request.POST) |
|
|
|
|
|
|
|
pk = kwargs['pk'] |
|
|
|
oid = kwargs['oid'] |
|
|
|
ordemdia = ExpedienteMateria.objects.get( |
|
|
|
sessao_plenaria_id=pk, materia_id=oid) |
|
|
|
|
|
|
|
if 'update-ordemdia' in request.POST: |
|
|
|
if form.is_valid(): |
|
|
|
try: |
|
|
|
materia = MateriaLegislativa.objects.get( |
|
|
|
numero=request.POST['numero_materia'], |
|
|
|
tipo_id=request.POST['tipo_materia'], |
|
|
|
ano=request.POST['ano_materia']) |
|
|
|
except ObjectDoesNotExist: |
|
|
|
context.update( |
|
|
|
{'error_message': _("Matéria inexistente!")}) |
|
|
|
return self.form_invalid(form) |
|
|
|
|
|
|
|
ordemdia.materia_id = materia.id |
|
|
|
ordemdia.numero_ordem = request.POST['numero_ordem'] |
|
|
|
ordemdia.tipo_votacao = request.POST['tipo_votacao'] |
|
|
|
obs = strip_tags(request.POST['observacao']) |
|
|
|
ordemdia.observacao = sub(' ', ' ', obs) |
|
|
|
ordemdia.save() |
|
|
|
return self.form_valid(form) |
|
|
|
else: |
|
|
|
context.update( |
|
|
|
{'error_message': _( |
|
|
|
"Não foi possível salvar formulário!")}) |
|
|
|
return self.form_invalid(form) |
|
|
|
elif 'delete-ordemdia' in request.POST: |
|
|
|
ordemdia.delete() |
|
|
|
return self.form_valid(form) |
|
|
|
|
|
|
|
def get_success_url(self): |
|
|
|
pk = self.kwargs['pk'] |
|
|
|
return reverse('sessao:expedienteordemdia_list', |
|
|
|
kwargs={'pk': pk}) |
|
|
|
|
|
|
|
|
|
|
|
class MesaView(FormMixin, SessaoCrud.CrudDetailView): |
|
|
|
template_name = 'sessao/mesa.html' |
|
|
|
form_class = MesaForm |
|
|
|
|