From 035f6d9d882c4125c1334d46a10416ed1da23cfb Mon Sep 17 00:00:00 2001 From: Eduardo Edson Batista Cordeiro Alves Date: Thu, 17 Sep 2015 16:34:30 -0300 Subject: [PATCH] Remake Expediente View --- sessao/views.py | 72 +++++++++++++++++++++++++------- templates/sessao/expediente.html | 15 +++++-- 2 files changed, 69 insertions(+), 18 deletions(-) diff --git a/sessao/views.py b/sessao/views.py index 8852b95f6..ef6dd2e41 100644 --- a/sessao/views.py +++ b/sessao/views.py @@ -92,19 +92,6 @@ registro_votacao_crud = build_crud( ]) -class ExpedienteView(InlineFormSetView): - model = SessaoPlenaria - inline_model = ExpedienteSessao - template_name = 'sessao/expediente.html' - fields = ('tipo', 'conteudo') - can_delete = True - extra = 1 - - def get_success_url(self): - pk = self.kwargs['pk'] - return reverse('sessaoplenaria:expediente', kwargs={'pk': pk}) - - class PresencaForm(forms.Form): presenca = forms.CharField(required=False, initial=False) parlamentar = forms.CharField(required=False, max_length=20) @@ -273,7 +260,7 @@ class MateriaOrdemDiaView(FormMixin, sessao_crud.CrudDetailView): context = self.get_context_data(object=self.object) form = MateriaOrdemDiaForm(request.POST) - print(form) + # print(form) if form.is_valid(): @@ -607,7 +594,8 @@ class ResumoView(FormMixin, sessao_crud.CrudDetailView): for e in expediente: tipo = TipoExpediente.objects.get( id=e.tipo_id) - conteudo = e.conteudo + conteudo = sub( + ' ', ' ', strip_tags(e.conteudo)) ex = {'tipo': tipo, 'conteudo': conteudo} expedientes.append(ex) @@ -721,3 +709,57 @@ class ResumoView(FormMixin, sessao_crud.CrudDetailView): context.update({'materias_ordem': materias_ordem}) return self.render_to_response(context) + + +class ExpedienteForm(forms.Form): + conteudo = forms.CharField(required=False, widget=forms.Textarea) + + +class ExpedienteView(FormMixin, sessao_crud.CrudDetailView): + template_name = 'sessao/expediente.html' + form_class = ExpedienteForm + + def post(self, request, *args, **kwargs): + self.object = self.get_object() + form = ExpedienteForm(request.POST) + + if form.is_valid(): + list_tipo = request.POST.getlist('tipo') + list_conteudo = request.POST.getlist('conteudo') + + for i in range(len(list_tipo)): + tipo = list_tipo[i] + conteudo = list_conteudo[i] + + ExpedienteSessao.objects.get( + sessao_plenaria_id=self.object.id, + tip_oid=tipo + ).delete() + + expediente = ExpedienteSessao() + expediente.sessao_plenaria_id = self.object.id + expediente.tipo_id = tipo + expediente.conteudo = conteudo + expediente.save() + return self.form_valid(form) + else: + return self.form_valid(form) + + def get(self, request, *args, **kwargs): + self.object = self.get_object() + context = self.get_context_data(object=self.object) + + expedientes_sessao = ExpedienteSessao.objects.filter( + sessao_plenaria_id=self.object.id) + + expedientes = [] + for e in expedientes_sessao: + expedientes.append({'tipo': e.tipo, + 'conteudo': e.conteudo + }) + context.update({'expedientes': expedientes}) + return self.render_to_response(context) + + def get_success_url(self): + pk = self.kwargs['pk'] + return reverse('sessaoplenaria:expediente', kwargs={'pk': pk}) diff --git a/templates/sessao/expediente.html b/templates/sessao/expediente.html index e52279f5f..32bff775c 100644 --- a/templates/sessao/expediente.html +++ b/templates/sessao/expediente.html @@ -6,10 +6,19 @@
{% csrf_token %} - {{formset}} -
- + {% for e in expedientes %} +
+ {{e.tipo}} + + + + +
+ {% endfor %} + +
+
{% endblock detail_content %}