From 8f2ae0701bf671d607f8c6ab7ab850afdfbcdf4b Mon Sep 17 00:00:00 2001 From: Edward Ribeiro Date: Fri, 11 Sep 2015 13:26:09 -0300 Subject: [PATCH] Hack a way of delete orador expediente --- painel/models.py | 1 - painel/views.py | 1 + sessao/urls.py | 10 +++++--- sessao/views.py | 32 ++++++++++++++++++++++++-- templates/sessao/oradorExpediente.html | 10 ++++---- 5 files changed, 43 insertions(+), 11 deletions(-) diff --git a/painel/models.py b/painel/models.py index acf39338f..9f23dd2ed 100644 --- a/painel/models.py +++ b/painel/models.py @@ -33,7 +33,6 @@ class Cronometro(models.Model): verbose_name='Status do cronômetro', choices=CRONOMETRO_STATUS, default='S') - #time = models.FloatField(verbose_name='Start time', default=0) data_cronometro = models.DateField(verbose_name='Data do cronômetro') tipo = models.CharField( max_length=1, choices=CRONOMETRO_TYPES, verbose_name='Tipo Cronômetro') diff --git a/painel/views.py b/painel/views.py index d66707ff8..a715565f1 100644 --- a/painel/views.py +++ b/painel/views.py @@ -4,6 +4,7 @@ from django.core import serializers from django.http import HttpResponse, JsonResponse from django.shortcuts import render from django.utils.translation import ugettext_lazy as _ + from painel.models import Painel from parlamentares.models import Filiacao from sapl.crud import build_crud diff --git a/sessao/urls.py b/sessao/urls.py index f9369dbb8..3bb77bed4 100644 --- a/sessao/urls.py +++ b/sessao/urls.py @@ -1,8 +1,9 @@ from django.conf.urls import include, url + from sessao.views import (ExpedienteView, OradorExpedienteView, PainelView, - PresencaOrdemDiaView, PresencaView, sessao_crud, - tipo_expediente_crud, tipo_resultado_votacao_crud, - tipo_sessao_crud) + PresencaOrdemDiaView, PresencaView, orador_delete, + sessao_crud, tipo_expediente_crud, + tipo_resultado_votacao_crud, tipo_sessao_crud) urlpatterns_sessao = sessao_crud.urlpatterns + [ url(r'^(?P\d+)/expediente$', @@ -16,6 +17,9 @@ urlpatterns_sessao = sessao_crud.urlpatterns + [ name='presencaordemdia'), url(r'^(?P\d+)/oradorexpediente$', OradorExpedienteView.as_view(), name='oradorexpediente'), + url(r'^(?P\d+)/oradorexpediente/excluir/(?P\d+)$', + orador_delete, name='oradorexcluir'), + ] sessao_urls = urlpatterns_sessao, sessao_crud.namespace, sessao_crud.namespace diff --git a/sessao/views.py b/sessao/views.py index 81ed36aaf..e2b656207 100644 --- a/sessao/views.py +++ b/sessao/views.py @@ -1,9 +1,14 @@ from django import forms +from django.core.urlresolvers import reverse_lazy +from django.shortcuts import redirect from django.utils.translation import ugettext_lazy as _ +from django.views.generic.detail import DetailView from django.views.generic.edit import FormMixin from extra_views import InlineFormSetView + from parlamentares.models import Parlamentar from sapl.crud import build_crud + from .models import (ExpedienteMateria, ExpedienteSessao, OradorExpediente, OrdemDia, PresencaOrdemDia, RegistroVotacao, SessaoPlenaria, SessaoPlenariaPresenca, TipoExpediente, @@ -219,12 +224,35 @@ class OradorForm(forms.Form): url_discurso = forms.CharField(required=False, max_length=100) +def orador_delete(request, pk, oid): + + orador = OradorExpediente.objects.get( + sessao_plenaria_id=pk, parlamentar_id=oid) + orador.delete() + + # return HttpResponseRedirect( + # reverse_lazy('oradorexpediente', kwargs={'pk': int(pk)})) + # return redirect(request, reverse('sessao:oradorexpediente', + # kwargs={'pk': pk}), context) + + return redirect('/sessao/' + pk + '/oradorexpediente') + + +class OradorExpedienteDelete(DetailView): + model = OradorExpediente + success_url = reverse_lazy('sessao:oradorexpediente') + + def get(self, request, *args, **kwargs): + self.object = self.get_object() + context = self.get_context_data(object=self.object) + return self.render_to_response(context) + + class OradorExpedienteView(FormMixin, sessao_crud.CrudDetailView): template_name = 'sessao/oradorExpediente.html' form_class = OradorForm def get(self, request, *args, **kwargs): - print(request.GET) self.object = self.get_object() context = self.get_context_data(object=self.object) return self.render_to_response(context) @@ -257,7 +285,7 @@ class OradorExpedienteView(FormMixin, sessao_crud.CrudDetailView): url_discurso = orador.url_discurso parlamentar = Parlamentar.objects.get( id=orador.parlamentar_id) - yield(numero_ordem, url_discurso, parlamentar.nome_parlamentar) + yield(numero_ordem, url_discurso, parlamentar) def post(self, request, *args, **kwargs): self.object = self.get_object() diff --git a/templates/sessao/oradorExpediente.html b/templates/sessao/oradorExpediente.html index b14b59a72..872f0af00 100644 --- a/templates/sessao/oradorExpediente.html +++ b/templates/sessao/oradorExpediente.html @@ -16,12 +16,12 @@
{% csrf_token %} - {% for numero_ordem, url_discuro, parlamentar in view.get_oradores %} + {% for numero_ordem, url_discurso, parlamentar in view.get_oradores %}
  • {{numero_ordem}}
  • -
  • {{parlamentar}}
  • -
  • {% if url_discurso == null %}Orador sem discurso cadastrado{% else %}{{url_discurso}}{% endif %}
  • -
  • Excluir
  • +
  • {{parlamentar.nome_parlamentar }}
  • +
  • {% if not url_discurso %}Orador sem discurso cadastrado{% else %}{{url_discurso}}{% endif %}
  • +
  • Excluir
{% endfor %} @@ -52,4 +52,4 @@
-{% endblock detail_content %} \ No newline at end of file +{% endblock detail_content %}