From eb7ddd3f3f0223878b1092ec9aaff553f3a0ecc6 Mon Sep 17 00:00:00 2001 From: Edward Ribeiro Date: Wed, 6 Jan 2016 18:19:23 -0200 Subject: [PATCH] Initial REST framework experience --- requirements/requirements.txt | 1 + sapl/settings.py | 2 ++ sessao/serializers.py | 8 ++++++++ sessao/urls.py | 8 ++++++-- sessao/views.py | 9 +++++++++ 5 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 sessao/serializers.py diff --git a/requirements/requirements.txt b/requirements/requirements.txt index 451623c54..28c4d7f43 100644 --- a/requirements/requirements.txt +++ b/requirements/requirements.txt @@ -1,5 +1,6 @@ crispy-forms-foundation Django<1.9 +djangorestframework django-admin-bootstrapped django-bootstrap3 django-bower diff --git a/sapl/settings.py b/sapl/settings.py index 52d0b2b53..0ad6e5adf 100644 --- a/sapl/settings.py +++ b/sapl/settings.py @@ -39,6 +39,8 @@ INSTALLED_APPS = ( 'django.contrib.messages', 'django.contrib.staticfiles', + 'rest_framework', + # sapl modules 'base', 'parlamentares', diff --git a/sessao/serializers.py b/sessao/serializers.py new file mode 100644 index 000000000..cf3fedadd --- /dev/null +++ b/sessao/serializers.py @@ -0,0 +1,8 @@ +from rest_framework import serializers +from .models import SessaoPlenaria + +class SessaoPlenariaSerializer(serializers.ModelSerializer): + + class Meta: + model = SessaoPlenaria + fields = ('tipo', 'legislatura', 'sessao_legislativa') \ No newline at end of file diff --git a/sessao/urls.py b/sessao/urls.py index 88e727dbe..9f9dc4fe5 100644 --- a/sessao/urls.py +++ b/sessao/urls.py @@ -9,7 +9,7 @@ from sessao.views import (EditExpedienteOrdemDiaView, EditMateriaOrdemDiaView, OradorExpedienteView, PainelView, PautaSessaoDetailView, PautaSessaoListView, PresencaOrdemDiaView, PresencaView, ResumoView, - SessaoListView, VotacaoEditView, + SessaoListView, SessaoPlenariaView, VotacaoEditView, VotacaoExpedienteEditView, VotacaoExpedienteView, VotacaoNominalEditView, VotacaoNominalExpedienteEditView, @@ -88,13 +88,17 @@ urlpatterns_sessao = sessao_crud.urlpatterns + [ 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'^cadastro$', SessaoCadastroView.as_view(), name='sessao_cadastro'), ] + sessao_urls = urlpatterns_sessao, sessao_crud.namespace, sessao_crud.namespace +sessao_rest = [url(r'^sessao$', SessaoPlenariaView.as_view(), name='sessao_rest'),] + urlpatterns = [ url(r'^sessao/', include(urlpatterns_sessao, sessao_crud.namespace, sessao_crud.namespace)), + url(r'^rest/', include(sessao_rest)), url(r'^sistema/sessao-plenaria/tipo/', include(tipo_sessao_crud.urls)), url(r'^sistema/sessao-plenaria/tipo-resultado-votacao/', include(tipo_resultado_votacao_crud.urls)), diff --git a/sessao/views.py b/sessao/views.py index 52c9d0b4d..52f3ef9aa 100644 --- a/sessao/views.py +++ b/sessao/views.py @@ -12,6 +12,10 @@ from django.utils.html import strip_tags from django.utils.translation import ugettext_lazy as _ from django.views.generic import ListView from django.views.generic.edit import FormMixin + +from sessao.serializers import SessaoPlenariaSerializer +from rest_framework import generics + import sapl from materia.models import Autoria, TipoMateriaLegislativa from parlamentares.models import Parlamentar @@ -2423,3 +2427,8 @@ class SessaoCadastroView(FormMixin, sessao_crud.CrudDetailView): def get_success_url(self): return reverse('sessaoplenaria:list_sessao') + + +class SessaoPlenariaView(generics.ListAPIView): + queryset = SessaoPlenaria.objects.select_related('sessao_legislativa').all() + serializer_class = SessaoPlenariaSerializer \ No newline at end of file