diff --git a/sapl/comissoes/forms.py b/sapl/comissoes/forms.py index 2b2081432..480619350 100644 --- a/sapl/comissoes/forms.py +++ b/sapl/comissoes/forms.py @@ -486,6 +486,9 @@ class PautaReuniaoForm(forms.ModelForm): model = PautaReuniao exclude = ['reuniao'] +class PresencaReuniaoComissaoForm(forms.Form): + presenca = forms.CharField(required=False, initial=False) + parlamentar = forms.CharField(required=False, max_length=20) class DocumentoAcessorioCreateForm(FileFieldCheckMixin, forms.ModelForm): diff --git a/sapl/comissoes/migrations/0026_presencareuniaocomissao.py b/sapl/comissoes/migrations/0026_presencareuniaocomissao.py new file mode 100644 index 000000000..2e96f18f6 --- /dev/null +++ b/sapl/comissoes/migrations/0026_presencareuniaocomissao.py @@ -0,0 +1,29 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.29 on 2020-08-12 23:59 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('parlamentares', '0031_auto_20200407_1406'), + ('comissoes', '0025_auto_20200605_1051'), + ] + + operations = [ + migrations.CreateModel( + name='PresencaReuniaoComissao', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('parlamentar', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='parlamentares.Parlamentar')), + ('reuniao', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='presencareuniaocomissao_set', to='comissoes.Reuniao')), + ], + options={ + 'verbose_name': 'Presença em Reunião de Comissão', + 'verbose_name_plural': 'Presenças em Reuniões de Comissão', + }, + ), + ] diff --git a/sapl/comissoes/models.py b/sapl/comissoes/models.py index bd46582ed..4bc4567c1 100644 --- a/sapl/comissoes/models.py +++ b/sapl/comissoes/models.py @@ -374,3 +374,14 @@ class DocumentoAcessorio(models.Model): force_update=force_update, using=using, update_fields=update_fields) + +@reversion.register() +class PresencaReuniaoComissao(models.Model): + reuniao = models.ForeignKey(Reuniao, + related_name='presencareuniaocomissao_set', + on_delete=models.CASCADE) + parlamentar = models.ForeignKey(Parlamentar, on_delete=models.PROTECT) + + class Meta: + verbose_name = _('Presença em Reunião de Comissão') + verbose_name_plural = _('Presenças em Reuniões de Comissão') diff --git a/sapl/comissoes/urls.py b/sapl/comissoes/urls.py index 932feaf22..d3caaeed8 100644 --- a/sapl/comissoes/urls.py +++ b/sapl/comissoes/urls.py @@ -3,7 +3,7 @@ from sapl.comissoes.views import (AdicionaPautaView, CargoComissaoCrud, Comissao ComposicaoCrud, DocumentoAcessorioCrud, MateriasTramitacaoListView, ParticipacaoCrud, get_participacoes_comissao, PeriodoComposicaoCrud, - RemovePautaView, ReuniaoCrud, TipoComissaoCrud) + RemovePautaView, ReuniaoCrud, TipoComissaoCrud,PresencaReuniaoComissaoView) from .apps import AppConfig @@ -27,4 +27,6 @@ urlpatterns = [ include(PeriodoComposicaoCrud.get_urls())), url(r'^sistema/comissao/tipo/', include(TipoComissaoCrud.get_urls())), url(r'^sistema/comissao/recupera-participacoes', get_participacoes_comissao), + url(r'^comissao/(?P\d+)/presenca$', + PresencaReuniaoComissaoView.as_view(), name='presenca'), ] diff --git a/sapl/comissoes/views.py b/sapl/comissoes/views.py index 019cca739..0436f0bd1 100644 --- a/sapl/comissoes/views.py +++ b/sapl/comissoes/views.py @@ -22,7 +22,7 @@ from sapl.comissoes.forms import (ComissaoForm, ComposicaoForm, ParticipacaoCreateForm, ParticipacaoEditForm, PautaReuniaoFilterSet, PautaReuniaoForm, - PeriodoForm, ReuniaoForm) + PeriodoForm, ReuniaoForm, PresencaReuniaoComissaoForm) from sapl.crud.base import (Crud, CrudAux, MasterDetailCrud, PermissionRequiredForAppCrudMixin, RP_DETAIL, RP_LIST) @@ -31,8 +31,9 @@ from sapl.materia.models import (MateriaEmTramitacao, MateriaLegislativa, from sapl.utils import show_results_filter_set from .models import (CargoComissao, Comissao, Composicao, DocumentoAcessorio, - Participacao, Periodo, Reuniao, TipoComissao) + Participacao, Periodo, Reuniao, TipoComissao, PresencaReuniaoComissao) +from sapl.parlamentares.models import Parlamentar def pegar_url_composicao(pk): participacao = Participacao.objects.get(id=pk) @@ -224,6 +225,11 @@ class ReuniaoCrud(MasterDetailCrud): documentos = DocumentoAcessorio.objects.filter(reuniao=self.kwargs['pk']).order_by('nome') docs.extend(documentos) + presenca = [] + presenca_reuniao = PresencaReuniaoComissao.objects.filter(reuniao=self.kwargs['pk']) + presenca.extend(presenca_reuniao) + context['presenca'] = presenca + context['docs'] = docs context['num_docs'] = len(docs) @@ -421,6 +427,75 @@ class DocumentoAcessorioCrud(MasterDetailCrud): kwargs={'pk': obj.reuniao.pk})) +class PresencaReuniaoComissaoView(FormMixin, DetailView): + template_name = 'comissoes/presenca.html' + form_class = PresencaReuniaoComissaoForm + model = Reuniao + logger = logging.getLogger(__name__) + + def get_presencas(self): + + pk = self.kwargs['pk'] + + presencas = PresencaReuniaoComissao.objects.filter(reuniao=pk) + presentes = [p.parlamentar for p in presencas] + + periodo = Reuniao.objects.get(pk=pk).periodo + participacao = Reuniao.objects.get(pk=pk).comissao.composicao_set.get(periodo=periodo).participacao_set.all() + + for p in participacao: + parlamentar = p.parlamentar + if parlamentar in presentes: + yield (parlamentar, True) + else: + yield (parlamentar, False) + + + def get_context_data(self, **kwargs): + context = FormMixin.get_context_data(self, **kwargs) + context['title'] = '%s (%s)' % ( + _('Presença em Reunião de Comissão'), self.object) + return context + + def post(self, request, *args, **kwargs): + self.object = self.get_object() + form = self.get_form() + + if form.is_valid(): + # Pegar os presentes salvos no banco + presentes_banco = PresencaReuniaoComissao.objects.filter( + reuniao_id=self.object.id).values_list( + 'parlamentar_id', flat=True).distinct() + + # Id dos parlamentares presentes + marcados = request.POST.getlist('presenca_ativos') \ + + request.POST.getlist('presenca_inativos') + + # Deletar os que foram desmarcados + deletar = set(presentes_banco) - set(marcados) + PresencaReuniaoComissao.objects.filter( + parlamentar_id__in=deletar, + reuniao_id=self.object.id).delete() + + for p in marcados: + presenca_reuniao = PresencaReuniaoComissao() + presenca_reuniao.reuniao = Reuniao.objects.get(pk=self.kwargs['pk']) + presenca_reuniao.parlamentar = Parlamentar.objects.get(id=p) + presenca_reuniao.save() + username = request.user.username + self.logger.info( + "user=" + username + ". PresencaReuniaoComissao salva com sucesso (parlamentar_id={})!".format(p)) + msg = _('Presença em Reuniao de Comissão salva com sucesso!') + messages.add_message(request, messages.SUCCESS, msg) + + return self.form_valid(form) + else: + return self.form_invalid(form) + + def get_success_url(self): + pk = self.kwargs['pk'] + return reverse('sapl.comissoes:reuniao_detail', kwargs={'pk': pk}) + def get_participacoes_comissao(request): parlamentares = [] diff --git a/sapl/rules/map_rules.py b/sapl/rules/map_rules.py index 316ce8ce3..5dee7570c 100644 --- a/sapl/rules/map_rules.py +++ b/sapl/rules/map_rules.py @@ -110,6 +110,7 @@ rules_group_comissoes = { (materia.Relatoria, __base__, __perms_publicas__), (comissoes.Reuniao, __base__, __perms_publicas__), (comissoes.DocumentoAcessorio, __base__, __perms_publicas__), + (comissoes.PresencaReuniaoComissao, __base__, __perms_publicas__), ] } diff --git a/sapl/templates/comissoes/presenca.html b/sapl/templates/comissoes/presenca.html new file mode 100644 index 000000000..5394ef68b --- /dev/null +++ b/sapl/templates/comissoes/presenca.html @@ -0,0 +1,85 @@ +{% extends "crud/detail.html" %} +{% load i18n %} +{% load common_tags %} + +{% block actions %}{% endblock %} + +{% block detail_content %} + {% if perms|get_add_perm:view %} +
+ {% csrf_token %} +
+
+ +
+
+
+
+ {% for parlamentar, check in view.get_presencas %} + {% if parlamentar.ativo %} +
+ +
+ {% else %} + + {% endif %} + {% endfor %} +
+
+ +
+ + {% else %} + +
+
+

Parlamentares presentes +

+
+
+ + {% for parlamentar, check in view.get_presencas %} + {% if check %} +
+
+ +
+
+ {% endif %} + {% endfor %} + {% endif %} +{% endblock detail_content %} + +{% block extra_js %} + +{% endblock %} \ No newline at end of file diff --git a/sapl/templates/comissoes/reuniao_detail.html b/sapl/templates/comissoes/reuniao_detail.html index bb6e19491..34074ad82 100644 --- a/sapl/templates/comissoes/reuniao_detail.html +++ b/sapl/templates/comissoes/reuniao_detail.html @@ -56,4 +56,17 @@ {% endif %} {% endif %}

+

Presença em Reunião

+ {% if presenca %} + + + + {% for presente in presenca %} + + {% endfor %} + +
Parlamentares presentes

{{ presente.parlamentar }}

+ {% endif %} + {% trans 'Editar Presenças' %} +

{% endblock detail_content %}