Browse Source

Add delete orador

pull/7/head
Eduardo Edson Batista Cordeiro Alves 9 years ago
parent
commit
f66fbc0a3c
  1. 12
      sessao/urls.py
  2. 40
      sessao/views.py
  3. 21
      templates/sessao/delete_orador.html
  4. 87
      templates/sessao/oradorExpediente.html

12
sessao/urls.py

@ -1,9 +1,9 @@
from django.conf.urls import include, url
from sessao.views import (ExpedienteView, OradorExpedienteView, PainelView,
PresencaOrdemDiaView, PresencaView, orador_delete,
sessao_crud, tipo_expediente_crud,
tipo_resultado_votacao_crud, tipo_sessao_crud)
from sessao.views import (ExpedienteView, OradorExpedienteDelete,
OradorExpedienteView, PainelView,
PresencaOrdemDiaView, PresencaView, sessao_crud,
tipo_expediente_crud, tipo_resultado_votacao_crud,
tipo_sessao_crud)
urlpatterns_sessao = sessao_crud.urlpatterns + [
url(r'^(?P<pk>\d+)/expediente$',
@ -18,7 +18,7 @@ urlpatterns_sessao = sessao_crud.urlpatterns + [
url(r'^(?P<pk>\d+)/oradorexpediente$',
OradorExpedienteView.as_view(), name='oradorexpediente'),
url(r'^(?P<pk>\d+)/oradorexpediente/excluir/(?P<oid>\d+)$',
orador_delete, name='oradorexcluir'),
OradorExpedienteDelete.as_view(), name='oradorexcluir'),
]
sessao_urls = urlpatterns_sessao, sessao_crud.namespace, sessao_crud.namespace

40
sessao/views.py

@ -1,8 +1,5 @@
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
@ -224,28 +221,31 @@ class OradorForm(forms.Form):
url_discurso = forms.CharField(required=False, max_length=100)
def orador_delete(request, pk, oid):
class OradorDeleteForm(forms.Form):
pass
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(FormMixin, sessao_crud.CrudDetailView):
template_name = 'sessao/delete_orador.html'
form_class = OradorDeleteForm
def post(self, request, *args, **kwargs):
self.object = self.get_object()
current_url = request.get_full_path()
words = current_url.split('/')
form = OradorDeleteForm(request.POST)
class OradorExpedienteDelete(DetailView):
model = OradorExpediente
success_url = reverse_lazy('sessao:oradorexpediente')
if form.is_valid():
orador = OradorExpediente.objects.get(
sessao_plenaria_id=self.object.id,
parlamentar_id=words[-1])
orador.delete()
return self.form_valid(form)
else:
return self.form_invalid(form)
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)
def get_success_url(self):
return self.detail_url
class OradorExpedienteView(FormMixin, sessao_crud.CrudDetailView):

21
templates/sessao/delete_orador.html

@ -0,0 +1,21 @@
{% extends "base.html" %}
{% load i18n %}
{% block base_content %}
<form action="" method="post">{% csrf_token %}
<div class="callout panel text-center radius clearfix">
<p>
{% blocktrans %}
Tem certeza que deseja apagar o orador?
{% endblocktrans %}
</p>
<div class="button-group">
<a href="{{ view.detail_url }}" class="button button radius alert">{% trans 'Cancelar' %}</a>
<input name="submit" value="{% trans 'Confirmar' %}" class="submit button button radius success" type="submit"></li>
</div>
</div>
</form>
{% endblock %}

87
templates/sessao/oradorExpediente.html

@ -4,52 +4,53 @@
{% block detail_content %}
<h2>Oradores do Expediente</h2>
<br /><br />
<ul class="small-block-grid-4 medium-block-grid-4 large-block-grid-4">
<li>Ordem de pronunciamento</li>
<li>Parlamentar</li>
<li>URL Discurso</li>
<li>Excluir</li>
</ul>
<form method="post" action="./oradorexpediente">
{% csrf_token %}
{% for numero_ordem, url_discurso, parlamentar in view.get_oradores %}
<ul class="small-block-grid-4 medium-block-grid-4 large-block-grid-4">
<li>{{numero_ordem}}</li>
<li>{{parlamentar.nome_parlamentar }}</li>
<li>{% if not url_discurso %}Orador sem discurso cadastrado{% else %}{{url_discurso}}{% endif %}</li>
<li><a id="excluir-orador" href="{% url 'sessaoplenaria:oradorexcluir' object.pk parlamentar.id %}">Excluir</a></li>
</ul>
{% endfor %}
<br />
<input type="submit" value="Atualizar" />
</form>
<form method="POST" action="{% url 'sessaoplenaria:oradorexpediente' object.pk %}">
{% csrf_token %}
<ul class="small-block-grid-3 medium-block-grid-3 large-block-grid-3">
<fieldset>
<legend>Oradores do Expediente</legend>
<ul class="small-block-grid-4 medium-block-grid-4 large-block-grid-4">
<li>Ordem de pronunciamento</li>
<li>Parlamentar</li>
<li>URL Discurso</li>
<li>Excluir</li>
</ul>
<ul class="small-block-grid-3 medium-block-grid-3 large-block-grid-3">
<li><input type="text" id="numero_ordem" name="numero_ordem"/></li>
<select name="parlamentar" id="parlamentar">
{% for parlamentar in view.get_candidatos_orador %}
<option value="{{parlamentar.id}}">{{parlamentar.nome_parlamentar}}</option>
{% endfor %}
</select>
<li><input type="text" id="url_discurso" name="url_discurso" /></li>
</ul>
<input type="submit" value="Adicionar Orador" />
</form>
<form method="post" action="./oradorexpediente">
{% csrf_token %}
{% for numero_ordem, url_discurso, parlamentar in view.get_oradores %}
<ul class="small-block-grid-4 medium-block-grid-4 large-block-grid-4">
<li><input size="2" type="text" id="numero_ordem" name="numero_ordem" value="{{numero_ordem}}" /></li>
<li>{{parlamentar.nome_parlamentar }}</li>
<li>{% if not url_discurso %}Orador sem discurso cadastrado{% else %}{{url_discurso}}{% endif %}</li>
<li><a id="excluir-orador" href="{% url 'sessaoplenaria:oradorexcluir' object.pk parlamentar.id %}">Excluir</a></li>
</ul>
{% endfor %}
<br />
<input type="submit" value="Atualizar" />
</form>
</fieldset>
<fieldset>
<legend>Adicionar Orador</legend>
<form method="POST" action="{% url 'sessaoplenaria:oradorexpediente' object.pk %}">
{% csrf_token %}
<ul class="small-block-grid-3 medium-block-grid-3 large-block-grid-3">
<li>Ordem de pronunciamento</li>
<li>Parlamentar</li>
<li>URL Discurso</li>
</ul>
<ul class="small-block-grid-3 medium-block-grid-3 large-block-grid-3">
<li><input type="text" id="numero_ordem" name="numero_ordem"/></li>
<li><select name="parlamentar" id="parlamentar">
{% for parlamentar in view.get_candidatos_orador %}
<option value="{{parlamentar.id}}">{{parlamentar.nome_parlamentar}}</option>
{% endfor %}
</select></li>
<li><input type="text" id="url_discurso" name="url_discurso" /></li>
</ul>
<input type="submit" value="Adicionar Orador" />
</form>
</fieldset>
{% endblock detail_content %}

Loading…
Cancel
Save