Browse Source

Alt backend de perm e pag de drf e ref layout topo

pull/739/head
LeandroRoberto 8 years ago
parent
commit
73acc52214
  1. 1
      sapl/api/pagination.py
  2. 17
      sapl/api/permissions.py
  3. 2
      sapl/api/urls.py
  4. 10
      sapl/api/views.py
  5. 10
      sapl/base/forms.py
  6. 6
      sapl/settings.py
  7. 74
      sapl/static/styles/app.scss
  8. 6
      sapl/templates/base.html
  9. 14
      sapl/templates/base/autor_form.html

1
sapl/rest_pagination.py → 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

17
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'],
}

2
sapl/api/urls.py

@ -10,7 +10,7 @@ app_name = AppConfig.name
# router = DefaultRouter()
urlpatterns = [
url(r'^autor/possiveis/(?P<pk>[0-9]*)$',
url(r'^autor/possiveis-pelo-tipo/(?P<pk>[0-9]+)$',
TipoAutorContentOfModelContentTypeView.as_view(),
name='autores_possiveis_pelo_tipo'),
]

10
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()

10
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)))

6
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",

74
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;
}
}

6
sapl/templates/base.html

@ -42,7 +42,7 @@
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li><a href="/" role="button" aria-haspopup="true" aria-expanded="false">Inicio<span class="caret"></span></a></li>
<li><a href="/" role="button" aria-haspopup="true" aria-expanded="false">Inicio</a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Institucional <span class="caret"></span></a>
@ -156,8 +156,8 @@
<div class="container">
<div class="navbar-header">
<a class="navbar-brand" href="/">
<img height="95" width="95" src="{% if logotipo %}{{ MEDIA_URL }}{{ logotipo }}{% else %}{% static 'img/logo.png' %}{% endif %}"
alt="Logo" class="img-responsive visible-lg-inline-block vcenter" >
<img src="{% if logotipo %}{{ MEDIA_URL }}{{ logotipo }}{% else %}{% static 'img/logo.png' %}{% endif %}"
alt="Logo" class="img-responsive visible-md-inline-block visible-lg-inline-block" >
<span class="vcenter">
{# XXX Make better use of translation tags in html blocks ie. actually use the proper blocktrans tag efficiently #}
{% if nome %}

14
sapl/templates/base/autor_form.html

@ -9,13 +9,14 @@ $(document).ready(function(){
if (str == 'nome') {
$('#id_nome, #id_q').val('');
$('#div_id_nome').removeClass('hidden');
$("[data-application='AutorSearch']").addClass('hidden');
$("#div_id_autor_related .controls").html('');
$("[data-application='AutorSearch'], .radiogroup-autor-related").addClass('hidden');
}
else {
$('#id_nome').val('');
$('#div_id_nome').addClass('hidden');
$("[data-application='AutorSearch']").removeClass('hidden');
$("#div_id_autor_related .alert").remove();
$("[data-application='AutorSearch'], .radiogroup-autor-related").removeClass('hidden');
}
}
var update_search = function(pk, atualizar=true) {
@ -31,12 +32,12 @@ $(document).ready(function(){
active('pesquisa');
if (atualizar) {
var radios = $("#div_id_autor_related .controls").html('');
data.forEach(function (val, index) {
data.models.forEach(function (val, index) {
var html_radio = '<label class="radio"><span class="icons"><span class="first-icon"></span><span class="second-icon"></span></span><input type="radio" name="autor_related" id="id_autor_related_'+index+'" value="'+val.pk+'">'+val.display+'</label>';
radios.append(html_radio);
});
if (data.length > 1) {
if (data.models.length > 1) {
$('input[name=autor_related]').change(function(event){
if (this.checked)
$('#id_q').val(event.target.parentElement.textContent);
@ -47,6 +48,11 @@ $(document).ready(function(){
$('input[name=autor_related]').prop('checked', 'checked');
$('input[name=autor_related]').closest('.radio').addClass('checked');
}
if (data.pagination.total_entries > 10)
radios.before('<div class="alert alert-info" role="alert"><strong>{% trans "Foram encontrados" %} '+data.pagination.total_entries+' {% trans "registros"%}</strong>'+'{% trans "mas será mostrado apenas os 10 primeiros resultados. Coloque mais informações no campo pesquisa para refinar sua busca."%}</div>');
else if (data.pagination.total_entries == 0)
radios.before('<div class="alert alert-info" role="alert"><strong>{% trans "Não foram encontrados registros com os termos de pesquisa informados." %}</div>');
}
else{
$('#id_nome, #id_q').val('');

Loading…
Cancel
Save