Browse Source

Adicionando o atributo de painel aberto e a função para alterar o status pela view

pull/1499/head
João Pedro Sconetto 8 years ago
parent
commit
a1b593c505
  1. 5
      sapl/painel/urls.py
  2. 15
      sapl/painel/views.py
  3. 20
      sapl/sessao/migrations/0015_sessaoplenaria_painel_aberto.py
  4. 1
      sapl/sessao/models.py
  5. 3
      sapl/sessao/tests/test_sessao.py
  6. 3
      sapl/sessao/tests/test_sessao_view.py
  7. 25
      sapl/templates/sessao/painel.html

5
sapl/painel/urls.py

@ -3,7 +3,7 @@ from django.conf.urls import url
from .apps import AppConfig
from .views import (cronometro_painel, get_dados_painel, painel_mensagem_view,
painel_parlamentar_view, painel_view, painel_votacao_view,
votante_view)
switch_painel, votante_view)
app_name = AppConfig.name
@ -14,6 +14,8 @@ urlpatterns = [
url(r'^painel/mensagem$', painel_mensagem_view, name="painel_mensagem"),
url(r'^painel/parlamentar$', painel_parlamentar_view,
name='painel_parlamentar'),
url(r'^painel/switch-painel$', switch_painel,
name="switch_painel"),
url(r'^painel/votacao$', painel_votacao_view, name='painel_votacao'),
url(r'^painel/cronometro$', cronometro_painel, name='cronometro_painel'),
# url(r'^painel/cronometro$', include(CronometroPainelCrud.get_urls())),
@ -21,3 +23,4 @@ urlpatterns = [
url(r'^voto-individual/$', votante_view,
name='voto_individual'),
]

15
sapl/painel/views.py

@ -1,3 +1,4 @@
import json
from django.contrib import messages
from django.contrib.auth.decorators import user_passes_test
@ -223,6 +224,20 @@ def painel_view(request, pk):
return render(request, 'painel/index.html', context)
@user_passes_test(check_permission)
def switch_painel(request):
sessao = SessaoPlenaria.objects.get(id=request.POST['pk_sessao'])
switch = json.loads(request.POST['aberto'])
if switch:
sessao.painel_aberto = True
else:
sessao.painel_aberto = False
sessao.save()
return JsonResponse({})
@user_passes_test(check_permission)
def painel_mensagem_view(request):
return render(request, 'painel/mensagem.html')

20
sapl/sessao/migrations/0015_sessaoplenaria_painel_aberto.py

@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.13 on 2017-09-21 17:44
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('sessao', '0014_auto_20170905_1617'),
]
operations = [
migrations.AddField(
model_name='sessaoplenaria',
name='painel_aberto',
field=models.BooleanField(default=False, verbose_name='Painel está aberto?'),
),
]

1
sapl/sessao/models.py

@ -111,6 +111,7 @@ class SessaoPlenaria(models.Model):
# TODO analyze querying all hosted databases !
cod_andamento_sessao = models.PositiveIntegerField(blank=True, null=True)
painel_aberto = models.BooleanField(blank=True, default=False, verbose_name=_('Painel está aberto?'))
tipo = models.ForeignKey(TipoSessaoPlenaria,
on_delete=models.PROTECT,
verbose_name=_('Tipo'))

3
sapl/sessao/tests/test_sessao.py

@ -37,7 +37,8 @@ def test_sessao_plenaria_form_valido():
'tipo': str(tipo.pk),
'sessao_legislativa': str(sessao.pk),
'data_inicio': '10/11/2017',
'hora_inicio': '10:10'
'hora_inicio': '10:10',
'painel_aberto': False
})
assert form.is_valid()

3
sapl/sessao/tests/test_sessao_view.py

@ -19,7 +19,8 @@ def test_incluir_sessao_plenaria_submit(admin_client):
'tipo': str(tipo.pk),
'sessao_legislativa': str(sessao.pk),
'data_inicio': '10/11/2017',
'hora_inicio': '10:10'
'hora_inicio': '10:10',
'painel_aberto': False
}, follow=True)
assert response.status_code == 200

25
sapl/templates/sessao/painel.html

@ -14,6 +14,8 @@
<div class="row">
<div class="col-md-6"><a href="" onclick="window.open('{% url 'sapl.painel:painel_principal' pk %}','Comprovante','width=800, height=800, scrollbars=yes'); return false;" class="btn btn-primary btn-sm active">Iniciar painel completo</a></div>
<div class="col-md-3"><button onclick="switch_painel(true)" id="id_abrir_painel" class="btn btn-primary btn-sm active">Abrir Painel</button></div>
<div class="col-md-3"><button onclick="switch_painel(false)" id="id_fechar_painel" class="btn btn-primary btn-sm active">Fechar Painel</button></div>
</div>
<br />
@ -257,6 +259,29 @@ $(function() {
});
});
function switch_painel(aberto) {
var pk_sessao = {{root_pk}};
var botao_abrir = document.getElementById('id_abrir_painel');
var botao_fechar = document.getElementById('id_fechar_painel');
$.ajax({
data: {pk_sessao: pk_sessao, aberto: aberto},
type: 'POST',
url: "{% url 'sapl.painel:switch_painel' %}",
headers: {'X-CSRFToken': getCookie('csrftoken')},
});
if (aberto) {
botao_abrir.style.display = 'none';
botao_fechar.style.display = 'block';
} else {
botao_abrir.style.display = 'block';
botao_fechar.style.display = 'none';
}
}
</script>
{% endblock %}

Loading…
Cancel
Save