From 73acc5221488ca5c8ce8eb87fe774ed2145ff523 Mon Sep 17 00:00:00 2001 From: LeandroRoberto Date: Wed, 12 Oct 2016 14:01:17 -0300 Subject: [PATCH] Alt backend de perm e pag de drf e ref layout topo --- .../{rest_pagination.py => api/pagination.py} | 1 + sapl/api/permissions.py | 17 +++++ sapl/api/urls.py | 2 +- sapl/api/views.py | 10 +-- sapl/base/forms.py | 10 ++- sapl/settings.py | 6 +- sapl/static/styles/app.scss | 74 ++++++++++++++++++- sapl/templates/base.html | 6 +- sapl/templates/base/autor_form.html | 14 +++- 9 files changed, 120 insertions(+), 20 deletions(-) rename sapl/{rest_pagination.py => api/pagination.py} (96%) create mode 100644 sapl/api/permissions.py diff --git a/sapl/rest_pagination.py b/sapl/api/pagination.py similarity index 96% rename from sapl/rest_pagination.py rename to sapl/api/pagination.py index bb7096a55..75941c1d3 100644 --- a/sapl/rest_pagination.py +++ b/sapl/api/pagination.py @@ -1,4 +1,5 @@ from django.core.paginator import EmptyPage +from django.utils.encoding import force_text from rest_framework import pagination from rest_framework.response import Response diff --git a/sapl/api/permissions.py b/sapl/api/permissions.py new file mode 100644 index 000000000..1149e8196 --- /dev/null +++ b/sapl/api/permissions.py @@ -0,0 +1,17 @@ +from rest_framework.permissions import DjangoModelPermissions + + +class DjangoModelPermissions(DjangoModelPermissions): + + perms_map = { + 'GET': ['%(app_label)s.list_%(model_name)s', + '%(app_label)s.detail_%(model_name)s'], + 'OPTIONS': ['%(app_label)s.list_%(model_name)s', + '%(app_label)s.detail_%(model_name)s'], + 'HEAD': ['%(app_label)s.list_%(model_name)s', + '%(app_label)s.detail_%(model_name)s'], + 'POST': ['%(app_label)s.list_%(model_name)s'], + 'PUT': ['%(app_label)s.change_%(model_name)s'], + 'PATCH': ['%(app_label)s.change_%(model_name)s'], + 'DELETE': ['%(app_label)s.delete_%(model_name)s'], + } diff --git a/sapl/api/urls.py b/sapl/api/urls.py index 2d6753308..3c5b6a265 100644 --- a/sapl/api/urls.py +++ b/sapl/api/urls.py @@ -10,7 +10,7 @@ app_name = AppConfig.name # router = DefaultRouter() urlpatterns = [ - url(r'^autor/possiveis/(?P[0-9]*)$', + url(r'^autor/possiveis-pelo-tipo/(?P[0-9]+)$', TipoAutorContentOfModelContentTypeView.as_view(), name='autores_possiveis_pelo_tipo'), ] diff --git a/sapl/api/views.py b/sapl/api/views.py index def65a217..3e839127c 100644 --- a/sapl/api/views.py +++ b/sapl/api/views.py @@ -15,17 +15,17 @@ class TipoAutorContentOfModelContentTypeView(ListAPIView): permission_classes = (IsAuthenticated,) queryset = TipoAutor.objects.all() model = TipoAutor - pagination_class = None def get_queryset(self): queryset = ModelViewSet.get_queryset(self) + if not self.kwargs['pk']: - return queryset + raise Http404() obj = get_object_or_404(queryset, pk=self.kwargs['pk']) if not obj.content_type: - raise Http404 + raise Http404() q = self.request.GET.get('q', '').strip() @@ -45,6 +45,6 @@ class TipoAutorContentOfModelContentTypeView(ListAPIView): for fs in fields_search: q_filter |= Q(**{'%s__icontains' % fs: q}) - return model_class.objects.filter(q_filter)[:10] + return model_class.objects.filter(q_filter) else: - return model_class.objects.all()[:10] + return model_class.objects.all() diff --git a/sapl/base/forms.py b/sapl/base/forms.py index baaa3059d..33b826131 100644 --- a/sapl/base/forms.py +++ b/sapl/base/forms.py @@ -1,4 +1,3 @@ -import django_filters from crispy_forms.bootstrap import FieldWithButtons, InlineRadios, StrictButton from crispy_forms.helper import FormHelper from crispy_forms.layout import HTML, Button, Div, Field, Fieldset, Layout, Row @@ -14,6 +13,7 @@ from django.core.exceptions import ValidationError from django.db import models, transaction from django.forms import ModelForm from django.utils.translation import ugettext_lazy as _ +import django_filters from sapl.base.models import Autor, TipoAutor from sapl.crispy_layout_mixin import (SaplFormLayout, form_actions, to_column, @@ -26,6 +26,7 @@ from sapl.utils import (RANGE_ANOS, ImageThumbnailFileInput, from .models import AppConfig, CasaLegislativa + ACTION_CREATE_USERS_AUTOR_CHOICE = [ ('C', _('Criar novo Usuário')), ('A', _('Associar um usuário existente')), @@ -135,7 +136,6 @@ class AutorForm(ModelForm): type='button')), - Field('autor_related'), css_class='hidden', data_action='create', data_application='AutorSearch', @@ -143,7 +143,11 @@ class AutorForm(ModelForm): autor_select = Row(to_column(('tipo', 4)), to_column(('nome', 8)), - to_column((autor_related, 8))) + to_column((autor_related, 8)), + to_column((Div( + Field('autor_related'), + css_class='radiogroup-autor-related hidden'), + 12))) row2 = Row(to_column((InlineRadios('action_user'), 8)), to_column(('username', 4))) diff --git a/sapl/settings.py b/sapl/settings.py index c58befa4f..59037f791 100644 --- a/sapl/settings.py +++ b/sapl/settings.py @@ -101,10 +101,14 @@ REST_FRAMEWORK = { "DEFAULT_PERMISSION_CLASSES": ( "rest_framework.permissions.IsAuthenticated", ), + "DEFAULT_PERMISSION_CLASSES": ( + # "rest_framework.permissions.IsAuthenticated", + "sapl.api.permissions.DjangoModelPermissions", + ), "DEFAULT_AUTHENTICATION_CLASSES": ( "rest_framework.authentication.SessionAuthentication", ), - "DEFAULT_PAGINATION_CLASS": "sapl.rest_pagination.StandardPagination", + "DEFAULT_PAGINATION_CLASS": "sapl.api.pagination.StandardPagination", "DEFAULT_FILTER_BACKENDS": ( "rest_framework.filters.SearchFilter", "rest_framework.filters.DjangoFilterBackend", diff --git a/sapl/static/styles/app.scss b/sapl/static/styles/app.scss index 0e569e197..573bb7ad8 100644 --- a/sapl/static/styles/app.scss +++ b/sapl/static/styles/app.scss @@ -6,16 +6,46 @@ display: inline-block; vertical-align: middle; float: none; + padding: 10px; } nav { &.navbar { - padding: 5px; border-radius: 0; font-size: 15px; } -} + .navbar-nav { + & > li { + & > a { + padding-top: 0px; + padding-bottom: 0px; + line-height: $grid-gutter-width * 2.5; + &:hover { + background-color: $link-hover-color; + } + } + &:first-child { + & > a { + padding-left: 0px; + padding-right: 0px; + } + } + &:nth-child(2) { + & > .dropdown-menu { + right: auto; + } + } + } + &:last-child { + & > li:last-child { + a { + padding-right: 0px; + } + } + } + } +} .masthead { padding: 10px; .nav { @@ -24,7 +54,9 @@ nav { .navbar-brand { color: $headings-color; font-size: 24px; - img { + img.img-responsive { + height: 95px; + width: 95px; margin-right: $navbar-padding-horizontal; } small { @@ -387,3 +419,39 @@ p { font-size: 100%; } /* FIM TEMPLATE AJUDA */ + +@media (max-width: 1199px) { + /*.nav > li > a { + padding: $grid-gutter-width $grid-gutter-width / 3; + }*/ + + .masthead { + .vcenter { + padding: 10px; + } + .nav { + margin-top: 65px; + } + .navbar-brand { + color: $headings-color; + font-size: 20px; + img.img-responsive { + height: 60px; + width: 60px; + margin-right: $navbar-padding-horizontal / 2; + } + small { + color: #93A4AA; + font-size: 75%; + line-height: 25px; + } + } + } + +} + +@media (min-width: 1092px) and (max-width: 1199px) { + .container { + width: 1070px; + } +} diff --git a/sapl/templates/base.html b/sapl/templates/base.html index a4b3db6e6..9d732de1a 100644 --- a/sapl/templates/base.html +++ b/sapl/templates/base.html @@ -42,7 +42,7 @@