From e3c1f8066ee0c283e6bf0bc7f6fb5ff7f50fbae8 Mon Sep 17 00:00:00 2001 From: Marcio Mazza Date: Wed, 15 Jul 2015 18:59:14 -0300 Subject: [PATCH] Restructure comissoes views --- .../templates/comissoes/criar_comissao.html | 1 - .../templates/comissoes/lista_comissao.html | 23 -------------- comissoes/urls.py | 6 ++-- comissoes/views.py | 31 ++++++++++++++----- requirements/requirements.txt | 1 + templates/comissoes/comissao_form.html | 22 +++++++++++++ templates/comissoes/comissao_list.html | 30 ++++++++++++++++++ 7 files changed, 80 insertions(+), 34 deletions(-) delete mode 100644 comissoes/templates/comissoes/criar_comissao.html delete mode 100644 comissoes/templates/comissoes/lista_comissao.html create mode 100644 templates/comissoes/comissao_form.html create mode 100644 templates/comissoes/comissao_list.html diff --git a/comissoes/templates/comissoes/criar_comissao.html b/comissoes/templates/comissoes/criar_comissao.html deleted file mode 100644 index 59df07ed1..000000000 --- a/comissoes/templates/comissoes/criar_comissao.html +++ /dev/null @@ -1 +0,0 @@ -

Incluir comissão

\ No newline at end of file diff --git a/comissoes/templates/comissoes/lista_comissao.html b/comissoes/templates/comissoes/lista_comissao.html deleted file mode 100644 index 725be9661..000000000 --- a/comissoes/templates/comissoes/lista_comissao.html +++ /dev/null @@ -1,23 +0,0 @@ -{% load i18n %} -{% load tz %} - -

Comissões

-Incluir Comissão - - - - - - - - - - - {% for comissao in comissoes %} - - - - - {% endfor %} - -
{% trans 'Nome' %}{% trans 'Sigla' %}{% trans 'Tipo' %}
{{ comissao.nome }}{{ comissao.sigla }}{{ comissao.tipo }}
\ No newline at end of file diff --git a/comissoes/urls.py b/comissoes/urls.py index cd27dabf5..3095fac45 100644 --- a/comissoes/urls.py +++ b/comissoes/urls.py @@ -1,9 +1,11 @@ from django.conf.urls import patterns, url -from comissoes.views import ListaComissoes +from comissoes.views import ComissaoListView, ComissaoDetailView, ComissaoUpdateView urlpatterns = patterns( 'comissoes.views', - url(r'^$', ListaComissoes.as_view(), name='ListaComissoes'), + url(r'^$', ComissaoListView.as_view(), name='comissao_list'), + url(r'^(?P\d+)$', ComissaoDetailView.as_view(), name='comissao_detail'), + url(r'^(?P\d+)/edit$', ComissaoUpdateView.as_view(), name='comissao_update'), ) diff --git a/comissoes/views.py b/comissoes/views.py index d2dfd2cdc..a75b0802f 100644 --- a/comissoes/views.py +++ b/comissoes/views.py @@ -1,20 +1,35 @@ +from braces.views import FormMessagesMixin from django.core.urlresolvers import reverse_lazy -from vanilla import CreateView, ListView +from django.views.generic import CreateView, DeleteView, ListView, UpdateView, DetailView from comissoes.models import Comissao -class ListaComissoes(ListView): +class ComissaoListView(ListView): model = Comissao - context_object_name = 'comissoes' - template_name = 'comissoes/lista_comissao.html' -class CriarComissao(CreateView): +class ComissaoDetailView(DetailView): model = Comissao - success_url = reverse_lazy('ListaComissoes') -class DetalheComissao(ListView): +class ComissaoCreateView(CreateView): model = Comissao - context_object_name = 'comissoes' + success_url = reverse_lazy('comissao_list') + + +class ComissaoUpdateView(FormMessagesMixin, UpdateView): + model = Comissao + fields = [f.name for f in Comissao._meta.fields] + + success_url = reverse_lazy('comissao_list') + + form_invalid_message = u"Something went wrong, post was not saved" + + def get_form_valid_message(self): + return u"{0} updated successfully!".format(self.object) + + +class ComissaoDeleteView(DeleteView): + model = Comissao + success_url = reverse_lazy('comissao_list') diff --git a/requirements/requirements.txt b/requirements/requirements.txt index 9834e8f27..27abca251 100644 --- a/requirements/requirements.txt +++ b/requirements/requirements.txt @@ -1,6 +1,7 @@ Django django-admin-bootstrapped django-bootstrap3 +django-braces django-vanilla-views mysqlclient psycopg2 diff --git a/templates/comissoes/comissao_form.html b/templates/comissoes/comissao_form.html new file mode 100644 index 000000000..f0e38178c --- /dev/null +++ b/templates/comissoes/comissao_form.html @@ -0,0 +1,22 @@ +{% extends "base.html" %} +{% load i18n bootstrap3 %} + +{% block title %}SAPL{% endblock %} + +{% block content %} +
+ {# Display a form #} +
+ {% csrf_token %} + + {% bootstrap_form form %} + + {% buttons %} + + {% endbuttons %} +
+
+{% endblock %} + diff --git a/templates/comissoes/comissao_list.html b/templates/comissoes/comissao_list.html new file mode 100644 index 000000000..87e2b7fed --- /dev/null +++ b/templates/comissoes/comissao_list.html @@ -0,0 +1,30 @@ +{% extends "base.html" %} +{% load i18n bootstrap3 %} + +{% block title %}SAPL{% endblock %} + +{% block content %} +
+

Comissões

+ Incluir Comissão + + + + + + + + + + + {% for comissao in object_list %} + + + + + {% endfor %} + +
{% trans 'Nome' %}{% trans 'Sigla' %}{% trans 'Tipo' %}
{{ comissao.nome }}{{ comissao.sigla }}{{ comissao.tipo }}
+
+{% endblock %} +