diff --git a/sessao/forms.py b/sessao/forms.py index 4b2367e52..d62af30c7 100644 --- a/sessao/forms.py +++ b/sessao/forms.py @@ -1,14 +1,6 @@ -from crispy_forms.helper import FormHelper -from crispy_forms.layout import Fieldset, Layout from django import forms -from django.forms import ModelForm from django.utils.translation import ugettext_lazy as _ -import crispy_layout_mixin -from crispy_layout_mixin import form_actions - -from .models import SessaoPlenaria - class PresencaForm(forms.Form): presenca = forms.CharField(required=False, initial=False) @@ -66,68 +58,3 @@ class VotacaoForm(forms.Form): class VotacaoEditForm(forms.Form): pass - - -class SessaoForm(ModelForm): - - class Meta: - model = SessaoPlenaria - fields = ['numero', - 'tipo', - 'legislatura', - 'sessao_legislativa', - 'data_inicio', - 'hora_inicio', - 'iniciada', - 'data_fim', - 'hora_fim', - 'finalizada', - 'upload_pauta', - 'upload_ata', - 'url_audio', - 'url_video'] - - widgets = { - 'hora_inicio': forms.TextInput(attrs={'class': 'hora'}), - 'hora_fim': forms.TextInput(attrs={'class': 'hora'}), - } - - def __init__(self, *args, **kwargs): - - row1 = crispy_layout_mixin.to_row( - [('numero', 3), - ('tipo', 3), - ('legislatura', 3), - ('sessao_legislativa', 3)]) - - row2 = crispy_layout_mixin.to_row( - [('data_inicio', 4), - ('hora_inicio', 4), - ('iniciada', 4)]) - - row3 = crispy_layout_mixin.to_row( - [('data_fim', 4), - ('hora_fim', 4), - ('finalizada', 4)]) - - row4 = crispy_layout_mixin.to_row( - [('upload_pauta', 6), - ('upload_ata', 6)]) - - row5 = crispy_layout_mixin.to_row( - [('url_audio', 6), - ('url_video', 6)]) - - self.helper = FormHelper() - self.helper.layout = Layout( - Fieldset( - _('Dados Básicos'), - row1, - row2, - row3, - row4, - row5, - form_actions() - ) - ) - super(SessaoForm, self).__init__(*args, **kwargs) diff --git a/sessao/urls.py b/sessao/urls.py index 0710e74b9..4a50be674 100644 --- a/sessao/urls.py +++ b/sessao/urls.py @@ -12,8 +12,7 @@ from sessao.views import (EditExpedienteOrdemDiaView, EditMateriaOrdemDiaView, PautaExpedienteDetail, PautaOrdemDetail, PautaSessaoDetailView, PautaSessaoListView, PresencaOrdemDiaView, PresencaView, ResumoView, - SessaoCadastroView, SessaoCrud, SessaoListView, - SessaoPlenariaView, TipoExpedienteCrud, + SessaoCrud, SessaoPlenariaView, TipoExpedienteCrud, TipoResultadoVotacaoCrud, TipoSessaoCrud, VotacaoEditView, VotacaoExpedienteEditView, VotacaoExpedienteView, VotacaoNominalEditView, @@ -25,7 +24,34 @@ from .apps import AppConfig app_name = AppConfig.name -urlpatterns_sessao = SessaoCrud.get_urls() + [ +sessao_rest = [ + url(r'^sessao$', SessaoPlenariaView.as_view(), name='sessao_rest') +] + +urlpatterns = [ + url(r'^sessao/', include(SessaoCrud.get_urls())), + + url(r'^media/(?P.*)$', serve, + {'document_root': settings.MEDIA_ROOT}), + url(r'^rest/', include(sessao_rest)), + url(r'^sistema/sessao-plenaria/tipo/', + include(TipoSessaoCrud.get_urls())), + url(r'^sistema/sessao-plenaria/tipo-resultado-votacao/', + include(TipoResultadoVotacaoCrud.get_urls())), + url(r'^sistema/sessao-plenaria/tipo-expediente/', + include(TipoExpedienteCrud.get_urls())), + + # PAUTA SESSÃO + url(r'^pauta-sessao$', + PautaSessaoListView.as_view(), name='list_pauta_sessao'), + url(r'^pauta-sessao/(?P\d+)$', + PautaSessaoDetailView.as_view(), name='pauta_sessao_detail'), + url(r'^pauta-sessao/(?P\d+)/expediente/$', + PautaExpedienteDetail.as_view(), name='pauta_expediente_detail'), + url(r'^pauta-sessao/(?P\d+)/ordem/$', + PautaOrdemDetail.as_view(), name='pauta_ordem_detail'), + + # Subnav sessão url(r'^(?P\d+)/expediente$', ExpedienteView.as_view(), name='expediente'), url(r'^(?P\d+)/presenca$', @@ -89,32 +115,4 @@ urlpatterns_sessao = SessaoCrud.get_urls() + [ VotacaoExpedienteView.as_view(), name='votacaosecretaexp'), url(r'^(?P\d+)/matexp/votsec/view/(?P\d+)/(?P\d+)$', VotacaoExpedienteEditView.as_view(), name='votacaosecretaexpedit'), - url(r'^sessao-list$', - SessaoListView.as_view(), name='list_sessao'), - url(r'^pauta-sessao-list$', - PautaSessaoListView.as_view(), name='list_pauta_sessao'), - url(r'^(?P\d+)/pauta-sessao-detail$', - PautaSessaoDetailView.as_view(), name='pauta_sessao_detail'), - url(r'^cadastro$', SessaoCadastroView.as_view(), name='sessao_cadastro'), - url(r'^pauta-sessao/(?P\d+)/expediente/$', - PautaExpedienteDetail.as_view(), name='pauta_expediente_detail'), - url(r'^pauta-sessao/(?P\d+)/ordem/$', - PautaOrdemDetail.as_view(), name='pauta_ordem_detail'), -] - -sessao_rest = [ - url(r'^sessao$', SessaoPlenariaView.as_view(), name='sessao_rest') -] - -urlpatterns = [ - url(r'^sessao/', include(urlpatterns_sessao)), - url(r'^media/(?P.*)$', serve, - {'document_root': settings.MEDIA_ROOT}), - url(r'^rest/', include(sessao_rest)), - url(r'^sistema/sessao-plenaria/tipo/', - include(TipoSessaoCrud.get_urls())), - url(r'^sistema/sessao-plenaria/tipo-resultado-votacao/', - include(TipoResultadoVotacaoCrud.get_urls())), - url(r'^sistema/sessao-plenaria/tipo-expediente/', - include(TipoExpedienteCrud.get_urls())) ] diff --git a/sessao/views.py b/sessao/views.py index 95be1199c..ae334ef2c 100644 --- a/sessao/views.py +++ b/sessao/views.py @@ -7,10 +7,11 @@ from django.core.urlresolvers import reverse, reverse_lazy from django.forms.utils import ErrorList from django.utils.html import strip_tags from django.utils.translation import ugettext_lazy as _ -from django.views.generic import CreateView, ListView +from django.views.generic import ListView, TemplateView from django.views.generic.edit import FormMixin from rest_framework import generics +import crud.base from crud.base import Crud, make_pagination from materia.models import (Autoria, DocumentoAcessorio, TipoMateriaLegislativa, Tramitacao) @@ -20,8 +21,7 @@ from sessao.serializers import SessaoPlenariaSerializer from .forms import (ExpedienteForm, ListMateriaForm, MateriaOrdemDiaForm, MesaForm, OradorDeleteForm, OradorForm, PresencaForm, - SessaoForm, VotacaoEditForm, VotacaoForm, - VotacaoNominalForm) + VotacaoEditForm, VotacaoForm, VotacaoNominalForm) from .models import (CargoMesa, ExpedienteMateria, ExpedienteSessao, IntegranteMesa, MateriaLegislativa, Orador, OradorExpediente, OrdemDia, PresencaOrdemDia, @@ -30,7 +30,6 @@ from .models import (CargoMesa, ExpedienteMateria, ExpedienteSessao, VotoParlamentar) TipoSessaoCrud = Crud.build(TipoSessaoPlenaria, 'tipo_sessao_plenaria') -SessaoCrud = Crud.build(SessaoPlenaria, '') ExpedienteMateriaCrud = Crud.build(ExpedienteMateria, '') OrdemDiaCrud = Crud.build(OrdemDia, '') TipoResultadoVotacaoCrud = Crud.build( @@ -39,6 +38,24 @@ TipoExpedienteCrud = Crud.build(TipoExpediente, 'tipo_expediente') RegistroVotacaoCrud = Crud.build(RegistroVotacao, '') +class SessaoCrud(Crud): + model = SessaoPlenaria + help_path = 'sessao_plenaria' + + class BaseMixin(crud.base.BaseMixin): + list_field_names = ['numero', 'tipo', 'legislatura', + 'sessao_legislativa', 'data_inicio', 'hora_inicio'] + + class CrudDetailView(crud.base.BaseMixin, crud.base.DetailView): + model = SessaoPlenaria + help_path = 'sessao_plenaria' + + class CreateView(crud.base.CrudCreateView): + + def get_success_url(self): + return reverse_lazy('sessao:sessaoplenaria_list') + + class PresencaMixin: def get_parlamentares(self): @@ -56,9 +73,10 @@ class PresencaMixin: yield (parlamentar, False) -class PresencaView(FormMixin, PresencaMixin, SessaoCrud.CrudDetailView): +class PresencaView(FormMixin, PresencaMixin, SessaoCrud.DetailView): template_name = 'sessao/presenca.html' form_class = PresencaForm + model = SessaoPlenaria def post(self, request, *args, **kwargs): self.object = self.get_object() @@ -96,7 +114,7 @@ class PresencaView(FormMixin, PresencaMixin, SessaoCrud.CrudDetailView): return reverse('sessao:presenca', kwargs={'pk': pk}) -class PainelView(SessaoCrud.CrudDetailView): +class PainelView(TemplateView): template_name = 'sessao/painel.html' @@ -2238,12 +2256,6 @@ class PautaSessaoDetailView(SessaoCrud.CrudDetailView): return self.render_to_response(context) -class SessaoCadastroView(CreateView): - template_name = "sessao/sessao_cadastro.html" - form_class = SessaoForm - success_url = reverse_lazy('sessao:list_sessao') - - class SessaoPlenariaView(generics.ListAPIView): queryset = SessaoPlenaria.objects.all() serializer_class = SessaoPlenariaSerializer diff --git a/templates/base.html b/templates/base.html index 27d96c4a7..5765bea6b 100644 --- a/templates/base.html +++ b/templates/base.html @@ -68,7 +68,7 @@