From febc7315c85954a3df69c8e87fd7cb0757f6e094 Mon Sep 17 00:00:00 2001 From: Edward Ribeiro Date: Wed, 30 Sep 2015 18:43:25 -0300 Subject: [PATCH] Refactor of methods and parameters --- sessao/views.py | 28 ++++++++++--------- ...Expediente.html => orador_expediente.html} | 0 ...caOrdemDia.html => presenca_ordemdia.html} | 0 3 files changed, 15 insertions(+), 13 deletions(-) rename templates/sessao/{oradorExpediente.html => orador_expediente.html} (100%) rename templates/sessao/{presencaOrdemDia.html => presenca_ordemdia.html} (100%) diff --git a/sessao/views.py b/sessao/views.py index e0cbcde29..36e5e6b00 100644 --- a/sessao/views.py +++ b/sessao/views.py @@ -154,17 +154,20 @@ class PainelView(sessao_crud.CrudDetailView): class PresencaOrdemDiaView(FormMixin, sessao_crud.CrudDetailView): - template_name = 'sessao/presencaOrdemDia.html' + template_name = 'sessao/presenca_ordemdia.html' form_class = PresencaForm def post(self, request, *args, **kwargs): + self.object = self.get_object() form = self.get_form() + pk = kwargs['pk'] + if form.is_valid(): # Pegar os presentes salvos no banco presentes_banco = PresencaOrdemDia.objects.filter( - sessao_plenaria_id=self.object.id) + sessao_plenaria_id=pk) # Id dos parlamentares presentes marcados = request.POST.getlist('presenca') @@ -614,14 +617,15 @@ class OradorExpedienteDelete(FormMixin, sessao_crud.CrudDetailView): def post(self, request, *args, **kwargs): self.object = self.get_object() - current_url = request.get_full_path() - words = current_url.split('/') + + orador_id = kwargs['oid'] + form = OradorDeleteForm(request.POST) if form.is_valid(): orador = OradorExpediente.objects.get( sessao_plenaria_id=self.object.id, - parlamentar_id=words[-1]) + parlamentar_id=orador_id) orador.delete() return self.form_valid(form) else: @@ -641,19 +645,18 @@ class OradorExpedienteEdit(FormMixin, sessao_crud.CrudDetailView): form = OradorForm(request.POST) if form.is_valid(): - current_url = request.get_full_path() - words = current_url.split('/') + orador_id = kwargs['oid'] orador = OradorExpediente.objects.get( sessao_plenaria_id=self.object.id, - parlamentar_id=words[-1]) + parlamentar_id=orador_id) orador.delete() orador = OradorExpediente() orador.sessao_plenaria_id = self.object.id orador.numero_ordem = request.POST['numero_ordem'] orador.parlamentar = Parlamentar.objects.get( - id=words[-1]) + id=orador_id) orador.url_discurso = request.POST['url_discurso'] orador.save() @@ -665,10 +668,9 @@ class OradorExpedienteEdit(FormMixin, sessao_crud.CrudDetailView): self.object = self.get_object() context = self.get_context_data(object=self.object) - current_url = self.request.get_full_path() - words = current_url.split('/') + orador_id = kwargs['oid'] - parlamentar = Parlamentar.objects.get(id=words[-1]) + parlamentar = Parlamentar.objects.get(id=orador_id) orador = OradorExpediente.objects.get( sessao_plenaria=self.object, parlamentar=parlamentar) @@ -684,7 +686,7 @@ class OradorExpedienteEdit(FormMixin, sessao_crud.CrudDetailView): class OradorExpedienteView(FormMixin, sessao_crud.CrudDetailView): - template_name = 'sessao/oradorExpediente.html' + template_name = 'sessao/orador_expediente.html' form_class = OradorForm def get(self, request, *args, **kwargs): diff --git a/templates/sessao/oradorExpediente.html b/templates/sessao/orador_expediente.html similarity index 100% rename from templates/sessao/oradorExpediente.html rename to templates/sessao/orador_expediente.html diff --git a/templates/sessao/presencaOrdemDia.html b/templates/sessao/presenca_ordemdia.html similarity index 100% rename from templates/sessao/presencaOrdemDia.html rename to templates/sessao/presenca_ordemdia.html