From 32ee9220c98ac88945f52d74b2b31c88aee6a9ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rog=C3=A9rio=20Fr=C3=A1?= Date: Mon, 22 May 2017 14:03:18 -0300 Subject: [PATCH 01/17] Fix 1104 (#1110) --- sapl/materia/forms.py | 12 ------------ sapl/materia/views.py | 4 ---- sapl/templates/materia/documentoacessorio_form.html | 2 +- 3 files changed, 1 insertion(+), 17 deletions(-) diff --git a/sapl/materia/forms.py b/sapl/materia/forms.py index 7c0b6d8c8..978fce522 100644 --- a/sapl/materia/forms.py +++ b/sapl/materia/forms.py @@ -164,18 +164,6 @@ class DocumentoAcessorioForm(ModelForm): class Meta: model = DocumentoAcessorio fields = ['tipo', 'nome', 'data', 'autor', 'ementa', 'arquivo'] - widgets = {'autor': forms.HiddenInput()} - - def clean_autor(self): - autor_field = self.cleaned_data['autor'] - try: - int(autor_field) - except ValueError: - return autor_field - else: - if autor_field: - return str(Autor.objects.get(id=autor_field)) - class RelatoriaForm(ModelForm): diff --git a/sapl/materia/views.py b/sapl/materia/views.py index 4ff498cec..c3ad9f9e4 100644 --- a/sapl/materia/views.py +++ b/sapl/materia/views.py @@ -963,25 +963,21 @@ class DocumentoAcessorioCrud(MasterDetailCrud): form_class = DocumentoAcessorioForm def __init__(self, **kwargs): - montar_helper_documento_acessorio(self) super(MasterDetailCrud.CreateView, self).__init__(**kwargs) def get_context_data(self, **kwargs): context = super( MasterDetailCrud.CreateView, self).get_context_data(**kwargs) - context['helper'] = self.helper return context class UpdateView(MasterDetailCrud.UpdateView): form_class = DocumentoAcessorioForm def __init__(self, **kwargs): - montar_helper_documento_acessorio(self) super(MasterDetailCrud.UpdateView, self).__init__(**kwargs) def get_context_data(self, **kwargs): context = super(UpdateView, self).get_context_data(**kwargs) - context['helper'] = self.helper return context diff --git a/sapl/templates/materia/documentoacessorio_form.html b/sapl/templates/materia/documentoacessorio_form.html index fb5810653..e25d5d3ab 100644 --- a/sapl/templates/materia/documentoacessorio_form.html +++ b/sapl/templates/materia/documentoacessorio_form.html @@ -2,5 +2,5 @@ {% load i18n crispy_forms_tags %} {% block base_content %} - {% crispy form helper %} + {% crispy form %} {% endblock %} From 0813a7061872db028f98b5067ca9599ff33258b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rog=C3=A9rio=20Fr=C3=A1?= Date: Mon, 22 May 2017 14:21:22 -0300 Subject: [PATCH 02/17] adiciona poppler-utils (#1113) --- docs/instacao31.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/instacao31.rst b/docs/instacao31.rst index 3d6a8b3eb..9a42573ac 100644 --- a/docs/instacao31.rst +++ b/docs/instacao31.rst @@ -28,7 +28,7 @@ Instalar as seguintes dependências do sistema:: pkg-config postgresql postgresql-contrib pgadmin3 python-psycopg2 \ software-properties-common build-essential libxml2-dev libjpeg-dev \ libmysqlclient-dev libssl-dev libffi-dev libxslt1-dev python3-setuptools \ - python3-pip curl + python3-pip curl poppler-utils sudo -i curl -sL https://deb.nodesource.com/setup_5.x | bash - From acb467bfa243ec05b039103da5765fb7b9635445 Mon Sep 17 00:00:00 2001 From: Edward Ribeiro Date: Mon, 22 May 2017 14:26:41 -0300 Subject: [PATCH 03/17] =?UTF-8?q?Adiciona=20poppler-utils,=20onde=20est?= =?UTF-8?q?=C3=A1=20pdftotext=20que=20=C3=A9=20usado=20por=20indexador.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index d35746703..85724ca11 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,7 +2,7 @@ FROM alpine:3.5 ENV BUILD_PACKAGES postgresql-dev graphviz-dev graphviz build-base git pkgconfig \ python3-dev libxml2-dev jpeg-dev libressl-dev libffi-dev libxslt-dev nodejs py3-lxml \ -py3-magic postgresql-client vim +py3-magic postgresql-client poppler-utils vim RUN apk add --no-cache python3 nginx && \ python3 -m ensurepip && \ From 3746b59f0aac97c8c50db2c7671105c15c090f9d Mon Sep 17 00:00:00 2001 From: cristian-longhi Date: Mon, 22 May 2017 14:33:49 -0300 Subject: [PATCH 04/17] =?UTF-8?q?redesenha=20a=20exibi=C3=A7=C3=A3o=20dos?= =?UTF-8?q?=20votos=20na=20tela=20de=20vota=C3=A7=C3=A3o=20nominal=20#1100?= =?UTF-8?q?=20(#1101)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * resultado de votação nominal * Update nominal_detail.html * Update nominal_edit.html --- sapl/templates/sessao/votacao/nominal_detail.html | 9 +++++++-- sapl/templates/sessao/votacao/nominal_edit.html | 11 +++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/sapl/templates/sessao/votacao/nominal_detail.html b/sapl/templates/sessao/votacao/nominal_detail.html index e27fd3c53..53d41084b 100644 --- a/sapl/templates/sessao/votacao/nominal_detail.html +++ b/sapl/templates/sessao/votacao/nominal_detail.html @@ -18,8 +18,13 @@ Votos
{% for v in votos %} -
{{v.parlamentar}}
-
{{v.voto}}
+
{{v.parlamentar}} - + {% if v.voto == '-1'%} + Voto não Registrado + {% else %} + {{v.voto}} + {% endif %} +
{% endfor %}
diff --git a/sapl/templates/sessao/votacao/nominal_edit.html b/sapl/templates/sessao/votacao/nominal_edit.html index 83d584a33..35297e36c 100644 --- a/sapl/templates/sessao/votacao/nominal_edit.html +++ b/sapl/templates/sessao/votacao/nominal_edit.html @@ -18,8 +18,15 @@ Votos
{% for v in votos %} -
{{v.parlamentar}}
-
{{v.voto}}
+ +
{{v.parlamentar}} - + {% if v.voto == '-1'%} + Voto não Registrado + {% else %} + {{v.voto}} + {% endif %} +
+ {% endfor %}
From 0484f475e00a5a7ca04744545b5256ac7a815ef1 Mon Sep 17 00:00:00 2001 From: Edward Ribeiro Date: Mon, 22 May 2017 14:54:52 -0300 Subject: [PATCH 05/17] =?UTF-8?q?Adiciona=20URL=20do=20Interlegis=20ao=20r?= =?UTF-8?q?odap=C3=A9=20da=20p=C3=A1gina.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sapl/templates/base.html | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/sapl/templates/base.html b/sapl/templates/base.html index 51351e7a0..5348ee291 100644 --- a/sapl/templates/base.html +++ b/sapl/templates/base.html @@ -157,11 +157,13 @@
+ {% trans 'Logo do Interlegis' %} +

- Desenvolvido pelo Interlegis em software livre e aberto. + Desenvolvido pelo Interlegis em software livre e aberto.

From 10839b1d9de53f89ea02f87f0f3d1071f4a73991 Mon Sep 17 00:00:00 2001 From: Edward Ribeiro Date: Mon, 22 May 2017 15:58:05 -0300 Subject: [PATCH 06/17] Somente mostra interessado se Doc Adm e mostra Autor em listagem de pesquisa --- sapl/templates/protocoloadm/protocolo_filter.html | 10 ++++++++-- sapl/templates/protocoloadm/protocolo_list.html | 4 ++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/sapl/templates/protocoloadm/protocolo_filter.html b/sapl/templates/protocoloadm/protocolo_filter.html index dc00317cd..afd9f61a3 100644 --- a/sapl/templates/protocoloadm/protocolo_filter.html +++ b/sapl/templates/protocoloadm/protocolo_filter.html @@ -44,9 +44,15 @@
Assunto: {{ p.assunto_ementa|default_if_none:"Não Informado"}}
Data Protocolo: {{ p.data|date:"d/m/Y"|default_if_none:"Não Informado" }} - Horário: {{ p.hora|date:"G:i:s" }}
- Interessado: {{ p.interessado }}
+ Autor: {{protocolo.autor.nome}}
Natureza do Processo: - {% if p.tipo_processo == 0 %} Administrativo {% elif p.tipo_processo == 1 %} Matéria Legislativa {% endif %}
+ {% if p.tipo_processo == 0 %} + Administrativo
+ Interessado: {{ p.interessado }} + {% elif p.tipo_processo == 1 %} + Matéria Legislativa + {% endif %} +
Classificação: {{ p.tipo_documento|default_if_none:p.tipo_materia }}
{% if p.anulado %} Anulado por: {{ p.user_anulacao }} - IP {{ p.ip_anulacao }}
diff --git a/sapl/templates/protocoloadm/protocolo_list.html b/sapl/templates/protocoloadm/protocolo_list.html index d5f3b9a8c..4ae55baf0 100644 --- a/sapl/templates/protocoloadm/protocolo_list.html +++ b/sapl/templates/protocoloadm/protocolo_list.html @@ -21,10 +21,10 @@
Assunto: {{ p.assunto_ementa }}
Data Protocolo: {{ p.data|date:"d/m/Y" }} - Horário: {{ p.timestamp|date:"H:m:s" }}
- Interessado: {{ p.interessado }}
Natureza do Processo: {% if p.tipo_processo == 0 %} - Administrativo + Administrativo
+ Interessado: {{ p.interessado }}
{% elif p.tipo_processo == 1 %} Matéria Legislativa {% endif %}
From d68f5256480c6842bcde40042269c21cda05fd05 Mon Sep 17 00:00:00 2001 From: Edward Ribeiro Date: Mon, 22 May 2017 16:08:03 -0300 Subject: [PATCH 07/17] HOT-FIX: identificador de protocolo errado --- sapl/templates/protocoloadm/protocolo_filter.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sapl/templates/protocoloadm/protocolo_filter.html b/sapl/templates/protocoloadm/protocolo_filter.html index afd9f61a3..36fbf092a 100644 --- a/sapl/templates/protocoloadm/protocolo_filter.html +++ b/sapl/templates/protocoloadm/protocolo_filter.html @@ -44,7 +44,7 @@
Assunto: {{ p.assunto_ementa|default_if_none:"Não Informado"}}
Data Protocolo: {{ p.data|date:"d/m/Y"|default_if_none:"Não Informado" }} - Horário: {{ p.hora|date:"G:i:s" }}
- Autor: {{protocolo.autor.nome}}
+ Autor: {{p.autor.nome}}
Natureza do Processo: {% if p.tipo_processo == 0 %} Administrativo
From 29e30da6202c25f1e280c5b562bf003caef2defb Mon Sep 17 00:00:00 2001 From: LeandroRoberto Date: Mon, 22 May 2017 16:52:05 -0300 Subject: [PATCH 08/17] =?UTF-8?q?Atualiza=20c=C3=B3digo=20devido=20a=20dep?= =?UTF-8?q?recated=20na=20drf?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sapl/api/serializers.py | 1 + 1 file changed, 1 insertion(+) diff --git a/sapl/api/serializers.py b/sapl/api/serializers.py index 21a48a848..60ea6692a 100644 --- a/sapl/api/serializers.py +++ b/sapl/api/serializers.py @@ -46,6 +46,7 @@ class AutorSerializer(serializers.ModelSerializer): class Meta: model = Autor + fields = '__all__' class MateriaLegislativaSerializer(serializers.ModelSerializer): From fa724cffb70352cef5b6e15185042ed4254a12d6 Mon Sep 17 00:00:00 2001 From: Edward Ribeiro Date: Mon, 22 May 2017 17:01:13 -0300 Subject: [PATCH 09/17] =?UTF-8?q?HOT-FIX:=20poss=C3=ADvel=20fix=20para=20e?= =?UTF-8?q?rro=20de=20render=20no=20search=20index?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sapl/base/search_indexes.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sapl/base/search_indexes.py b/sapl/base/search_indexes.py index e41dac3bf..58e1688c4 100644 --- a/sapl/base/search_indexes.py +++ b/sapl/base/search_indexes.py @@ -54,8 +54,8 @@ class DocumentoAcessorioIndex(indexes.SearchIndex, indexes.Indexable): # text field with *all* of our metadata visible for templating: t = loader.select_template(( 'search/indexes/' + self.template_name, )) - data['text'] = t.render(Context({'object': obj, - 'extracted': extracted_data})) + data['text'] = t.render({'object': obj, + 'extracted': extracted_data}) return data From fe5a28ccdc9eaec40202927186daa73bab52e2b5 Mon Sep 17 00:00:00 2001 From: LeandroRoberto Date: Mon, 22 May 2017 18:03:34 -0300 Subject: [PATCH 10/17] Add pesquisa em Autor pelo campo ativo de parlamentar --- sapl/api/forms.py | 11 ++++++----- sapl/parlamentares/models.py | 12 +++++++++++- sapl/utils.py | 24 +++++++++++++----------- 3 files changed, 30 insertions(+), 17 deletions(-) diff --git a/sapl/api/forms.py b/sapl/api/forms.py index c220c01b2..4609273e4 100644 --- a/sapl/api/forms.py +++ b/sapl/api/forms.py @@ -35,10 +35,11 @@ class SaplGenericRelationSearchFilterSet(FilterSet): item.related_query_name(), field[0]) ) - q_fs = q_fs | Q(**{'%s__%s%s' % ( - item.related_query_name(), - field[0], - field[1]): qtext}) + if len(field) == 3 and field[2](qtext) is not None: + q_fs = q_fs | Q(**{'%s__%s%s' % ( + item.related_query_name(), + field[0], + field[1]): qtext if len(field) == 2 else field[2](qtext)}) q = q & q_fs @@ -60,4 +61,4 @@ class AutorChoiceFilterSet(SaplGenericRelationSearchFilterSet): def filter_q(self, queryset, value): return SaplGenericRelationSearchFilterSet.filter_q( - self, queryset, value).order_by('nome') + self, queryset, value).distinct('nome').order_by('nome') diff --git a/sapl/parlamentares/models.py b/sapl/parlamentares/models.py index 4d15ab6fd..2f1284fbf 100644 --- a/sapl/parlamentares/models.py +++ b/sapl/parlamentares/models.py @@ -1,9 +1,9 @@ from datetime import datetime -import reversion from django.db import models from django.utils.translation import ugettext_lazy as _ from model_utils import Choices +import reversion from sapl.base.models import Autor from sapl.utils import (INDICADOR_AFASTAMENTO, UF, YES_NO_CHOICES, @@ -206,6 +206,15 @@ def foto_upload_path(instance, filename): return texto_upload_path(instance, filename, subpath='') +def true_false_none(x): + if x == 'True': + return True + elif x == 'False': + return False + else: + return None + + @reversion.register() class Parlamentar(models.Model): FEMININO = 'F' @@ -303,6 +312,7 @@ class Parlamentar(models.Model): ('nome_completo', '__icontains'), ('nome_parlamentar', '__icontains'), ('filiacao__partido__sigla', '__icontains'), + ('ativo', '', true_false_none), )) class Meta: diff --git a/sapl/utils.py b/sapl/utils.py index 7429a7e4c..4873d3519 100644 --- a/sapl/utils.py +++ b/sapl/utils.py @@ -1,15 +1,13 @@ -import hashlib -import logging -import os -import re from datetime import date from functools import wraps -from unicodedata import normalize as unicodedata_normalize from subprocess import PIPE, call from threading import Thread +from unicodedata import normalize as unicodedata_normalize +import hashlib +import logging +import os +import re -import django_filters -import magic from crispy_forms.helper import FormHelper from crispy_forms.layout import HTML, Button from django import forms @@ -22,10 +20,13 @@ from django.core.exceptions import ValidationError from django.utils.translation import ugettext_lazy as _ from floppyforms import ClearableFileInput from reversion.admin import VersionAdmin +import django_filters +import magic from sapl.crispy_layout_mixin import SaplFormLayout, form_actions, to_row from sapl.settings import BASE_DIR, PROJECT_DIR + sapl_logger = logging.getLogger(BASE_DIR.name) @@ -159,8 +160,8 @@ class SaplGenericRelation(GenericRelation): assert isinstance(field, (tuple, list)), _( 'fields_search deve ser um array de tuplas ou listas.') - assert len(field) == 2, _( - 'cada tupla de fields_search deve possuir duas strins') + assert len(field) <= 3, _( + 'cada tupla de fields_search deve possuir até 3 strings') # TODO implementar assert para validar campos do Model e lookups @@ -368,8 +369,8 @@ def fabrica_validador_de_tipos_de_arquivo(lista, nome): def restringe_tipos_de_arquivo(value): if not os.path.splitext(value.path)[1][:1]: - raise ValidationError(_( - 'Não é possível fazer upload de arquivos sem extensão.')) + raise ValidationError(_( + 'Não é possível fazer upload de arquivos sem extensão.')) mime = magic.from_buffer(value.read(), mime=True) if mime not in lista: @@ -637,6 +638,7 @@ def texto_upload_path(instance, filename, subpath=''): class UpdateIndexCommand(Thread): + def run(self): call([PROJECT_DIR.child('manage.py'), 'update_index'], stdout=PIPE) From d03946b1c0b3143b9f7a99704c4e9b349066e2bd Mon Sep 17 00:00:00 2001 From: Eliseu Egewarth Date: Mon, 22 May 2017 19:09:48 -0300 Subject: [PATCH 11/17] =?UTF-8?q?Gera=20migra=C3=A7=C3=A3o=20referente=20a?= =?UTF-8?q?o=20commit=20#285d32e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Eliseu Egewarth --- .../migrations/0005_auto_20170522_1904.py | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 sapl/materia/migrations/0005_auto_20170522_1904.py diff --git a/sapl/materia/migrations/0005_auto_20170522_1904.py b/sapl/materia/migrations/0005_auto_20170522_1904.py new file mode 100644 index 000000000..7789aec96 --- /dev/null +++ b/sapl/materia/migrations/0005_auto_20170522_1904.py @@ -0,0 +1,32 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.12 on 2017-05-22 19:04 +from __future__ import unicode_literals + +from django.db import migrations, models +import sapl.materia.models +import sapl.utils + + +class Migration(migrations.Migration): + + dependencies = [ + ('materia', '0004_auto_20170504_1751'), + ] + + operations = [ + migrations.AlterField( + model_name='documentoacessorio', + name='arquivo', + field=models.FileField(blank=True, null=True, upload_to=sapl.materia.models.anexo_upload_path, validators=[sapl.utils.restringe_tipos_de_arquivo_txt], verbose_name='Texto Integral'), + ), + migrations.AlterField( + model_name='materialegislativa', + name='texto_original', + field=models.FileField(blank=True, null=True, upload_to=sapl.materia.models.materia_upload_path, validators=[sapl.utils.restringe_tipos_de_arquivo_txt], verbose_name='Texto Original'), + ), + migrations.AlterField( + model_name='proposicao', + name='texto_original', + field=models.FileField(blank=True, null=True, upload_to=sapl.materia.models.materia_upload_path, validators=[sapl.utils.restringe_tipos_de_arquivo_txt], verbose_name='Texto Original'), + ), + ] From d0640b06c88bab30d326a4e84f37d0d7f022f1e3 Mon Sep 17 00:00:00 2001 From: LeandroRoberto Date: Tue, 23 May 2017 11:17:30 -0300 Subject: [PATCH 12/17] Add bsc param de Autor nos Models lig via GR a Autor --- sapl/api/forms.py | 53 +++++++++++++++++++++++++++++ sapl/api/views.py | 58 ++++++++++++++++++++++++++++++-- sapl/utils.py | 86 ----------------------------------------------- 3 files changed, 109 insertions(+), 88 deletions(-) diff --git a/sapl/api/forms.py b/sapl/api/forms.py index 4609273e4..afa9190f4 100644 --- a/sapl/api/forms.py +++ b/sapl/api/forms.py @@ -1,5 +1,8 @@ from django.db.models import Q +from django.forms.fields import MultiValueField, CharField +from django.forms.widgets import TextInput, MultiWidget from django_filters.filters import MethodFilter, ModelChoiceFilter +from rest_framework.compat import django_filters from rest_framework.filters import FilterSet from sapl.base.models import Autor, TipoAutor @@ -49,6 +52,37 @@ class SaplGenericRelationSearchFilterSet(FilterSet): return queryset +class SearchForFieldWidget(MultiWidget): + + def decompress(self, value): + if value is None: + return [None, None] + return value + + def __init__(self, attrs=None): + widgets = (TextInput, TextInput) + MultiWidget.__init__(self, widgets, attrs) + + +class SearchForFieldField(MultiValueField): + widget = SearchForFieldWidget + + def __init__(self, *args, **kwargs): + fields = ( + CharField(), + CharField()) + super(SearchForFieldField, self).__init__(fields, *args, **kwargs) + + def compress(self, parameters): + if parameters: + return parameters + return None + + +class SearchForFieldFilter(django_filters.filters.MethodFilter): + field_class = SearchForFieldField + + class AutorChoiceFilterSet(SaplGenericRelationSearchFilterSet): q = MethodFilter() tipo = ModelChoiceFilter(queryset=TipoAutor.objects.all()) @@ -62,3 +96,22 @@ class AutorChoiceFilterSet(SaplGenericRelationSearchFilterSet): def filter_q(self, queryset, value): return SaplGenericRelationSearchFilterSet.filter_q( self, queryset, value).distinct('nome').order_by('nome') + + +class AutorSearchForFieldFilterSet(AutorChoiceFilterSet): + q = SearchForFieldFilter() + + class Meta(AutorChoiceFilterSet.Meta): + pass + + def filter_q(self, queryset, value): + + value[0] = value[0].split(',') + value[1] = value[1].split(',') + + params = {} + for key, v in list(zip(value[0], value[1])): + if v in ['True', 'False']: + v = '1' if v == 'True' else '0' + params[key] = v + return queryset.filter(**params).distinct('nome').order_by('nome') diff --git a/sapl/api/views.py b/sapl/api/views.py index 4a8341c52..eb1364bf7 100644 --- a/sapl/api/views.py +++ b/sapl/api/views.py @@ -10,7 +10,7 @@ from rest_framework.permissions import (IsAuthenticated, AllowAny) from rest_framework.viewsets import GenericViewSet, ModelViewSet -from sapl.api.forms import AutorChoiceFilterSet +from sapl.api.forms import AutorChoiceFilterSet, AutorSearchForFieldFilterSet from sapl.api.serializers import (AutorChoiceSerializer, AutorSerializer, ChoiceSerializer, MateriaLegislativaSerializer, @@ -79,7 +79,57 @@ class AutorListView(ListAPIView): o django-filter é desativado e a busca é feita no model do ContentType associado ao tipo. - Outros campos + - q_0 / q_1 - q_0 faz o código ignorar "q"... + + q_0 -> campos lookup a serem filtrados em qualquer Model + que implemente SaplGenericRelation + q_1 -> o valor que será pesquisado no lookup de q_0 + + q_0 e q_1 podem ser separados por ","... isso dará a + possibilidade de filtrar mais de um campo. + + + http://localhost:8000 + /api/autor?tr=1&q_0=parlamentar_set__ativo&q_1=False + /api/autor?tr=1&q_0=parlamentar_set__ativo&q_1=True + /api/autor?tr=3&q_0=parlamentar_set__ativo&q_1=False + /api/autor?tr=3&q_0=parlamentar_set__ativo&q_1=True + + http://localhost:8000 + /api/autor?tr=1 + &q_0=parlamentar_set__nome_completo__icontains, + parlamentar_set__ativo + &q_1=Carvalho,False + /api/autor?tr=1 + &q_0=parlamentar_set__nome_completo__icontains, + parlamentar_set__ativo + &q_1=Carvalho,True + /api/autor?tr=3 + &q_0=parlamentar_set__nome_completo__icontains, + parlamentar_set__ativo + &q_1=Carvalho,False + /api/autor?tr=3 + &q_0=parlamentar_set__nome_completo__icontains, + parlamentar_set__ativo + &q_1=Carvalho,True + + + não importa o campo que vc passe de qualquer dos Models + ligados... é possível ver que models são esses, + na ocasião do commit deste texto, executando: + In [6]: from sapl.utils import models_with_gr_for_model + + In [7]: models_with_gr_for_model(Autor) + Out[7]: + [sapl.parlamentares.models.Parlamentar, + sapl.parlamentares.models.Frente, + sapl.comissoes.models.Comissao, + sapl.materia.models.Orgao, + sapl.sessao.models.Bancada, + sapl.sessao.models.Bloco] + + qualquer atributo destes models podem ser passados + para busca """ TR_AUTOR_CHOICE_SERIALIZER = 1 @@ -125,6 +175,9 @@ class AutorListView(ListAPIView): self.serializer_class = AutorSerializer self.permission_classes = (IsAuthenticated,) + if self.filter_class and 'q_0' in request.GET: + self.filter_class = AutorSearchForFieldFilterSet + return ListAPIView.get(self, request, *args, **kwargs) def get_queryset(self): @@ -207,6 +260,7 @@ class MateriaLegislativaViewSet(ListModelMixin, filter_backends = (DjangoFilterBackend,) filter_fields = ('numero', 'ano', 'tipo', ) + class SessaoPlenariaViewSet(ListModelMixin, RetrieveModelMixin, GenericViewSet): diff --git a/sapl/utils.py b/sapl/utils.py index 4873d3519..618a3f4f8 100644 --- a/sapl/utils.py +++ b/sapl/utils.py @@ -392,92 +392,6 @@ def intervalos_tem_intersecao(a_inicio, a_fim, b_inicio, b_fim): return maior_inicio <= menor_fim -""" -def permissoes(nome_grupo, app_label): - lista_permissoes = [] - try: - perms = list(Permission.objects.filter( - group__name=nome_grupo)) - for p in perms: - lista_permissoes.append('%s.%s' % (app_label, p.codename)) - except: - pass - return set(lista_permissoes) - - -def permission_required_for_app(app_label, login_url=None, - raise_exception=False): - - Decorator for views that checks whether a user has a particular permission - enabled, redirecting to the log-in page if necessary. - If the raise_exception parameter is given the PermissionDenied exception - is raised. - - def check_perms(user): - if user.has_module_perms(app_label): - return True - # In case the 403 handler should be called raise the exception - if raise_exception: - raise PermissionDenied - # As the last resort, show the login form - return False - return user_passes_test(check_perms, login_url=login_url) - -def permissoes_materia(): - return permissoes('Operador de Matéria', 'materia') - - -def permissoes_comissoes(): - return permissoes('Operador de Comissões', 'comissoes') - - -def permissoes_norma(): - return permissoes('Operador de Norma Jurídica', 'norma') - - -def permissoes_protocoloadm(): - return permissoes('Operador de Protocolo Administrativo', 'protocoloadm') - - -def permissoes_adm(): - return permissoes('Operador Administrativo', 'protocoloadm') - - -def permissoes_sessao(): - return permissoes('Operador de Sessão Plenária', 'sessao') - - -def permissoes_painel(): - return permissoes('Operador de Painel Eletrônico', 'painel') - - -def permissoes_autor(): - return permissoes('Autor', 'materia') - - -def permissoes_parlamentares(): - lista_permissoes = [] - try: - cts = ContentType.objects.filter(app_label='parlamentares') - perms_parlamentares = list(Permission.objects.filter( - content_type__in=cts)) - for p in perms_parlamentares: - lista_permissoes.append('parlamentares.' + p.codename) - except: - pass - return set(lista_permissoes) - - -def permissao_tb_aux(self): - u = self.request.user - if u.groups.filter(name='Operador Geral').exists() or u.is_superuser: - return True - else: - return False - -""" - - class MateriaPesquisaOrderingFilter(django_filters.OrderingFilter): choices = ( From d40fc0e15e23e5319cb74ca42bc381fb0e869b29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rog=C3=A9rio=20Fr=C3=A1?= Date: Tue, 23 May 2017 13:58:32 -0300 Subject: [PATCH 13/17] campo texto para autor documentos acessorios em lote (#1117) --- sapl/materia/views.py | 2 +- sapl/templates/materia/em_lote/acessorio.html | 17 ++--------------- 2 files changed, 3 insertions(+), 16 deletions(-) diff --git a/sapl/materia/views.py b/sapl/materia/views.py index c3ad9f9e4..381e8042c 100644 --- a/sapl/materia/views.py +++ b/sapl/materia/views.py @@ -1619,7 +1619,7 @@ class DocumentoAcessorioEmLoteView(PermissionRequiredMixin, FilterView): arquivo=request.POST['arquivo'], nome=request.POST['nome'], data=datetime.strptime(request.POST['data'], "%d/%m/%Y"), - autor=Autor.objects.get(id=request.POST['autor']), + autor=request.POST['autor'], ementa=request.POST['ementa'] ) msg = _('Documento(s) criado(s).') diff --git a/sapl/templates/materia/em_lote/acessorio.html b/sapl/templates/materia/em_lote/acessorio.html index 5035d8956..1fe8086cc 100644 --- a/sapl/templates/materia/em_lote/acessorio.html +++ b/sapl/templates/materia/em_lote/acessorio.html @@ -40,22 +40,9 @@
- +
- - - -
-
-
-
-
-
- +
From b63d2e3b783f3178a7a8a1d5dc7a1ac0fd79e9b6 Mon Sep 17 00:00:00 2001 From: Edward Ribeiro Date: Tue, 23 May 2017 14:25:53 -0300 Subject: [PATCH 14/17] Conserto paliativo para doc acessorio em lote --- sapl/materia/views.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/sapl/materia/views.py b/sapl/materia/views.py index 381e8042c..2af41db6d 100644 --- a/sapl/materia/views.py +++ b/sapl/materia/views.py @@ -1613,15 +1613,15 @@ class DocumentoAcessorioEmLoteView(PermissionRequiredMixin, FilterView): tipo = TipoDocumento.objects.get(descricao=request.POST['tipo']) for materia_id in marcadas: - DocumentoAcessorio.objects.create( - materia_id=materia_id, - tipo=tipo, - arquivo=request.POST['arquivo'], - nome=request.POST['nome'], - data=datetime.strptime(request.POST['data'], "%d/%m/%Y"), - autor=request.POST['autor'], - ementa=request.POST['ementa'] - ) + doc = DocumentoAcessorio() + doc.materia_id = materia_id + doc.tipo = tipo + doc.arquivo = request.POST['arquivo'] + doc.nome = request.POST['nome'] + doc.data = datetime.strptime(request.POST['data'], "%d/%m/%Y") + doc.autor_id = request.POST['autor'] + doc.ementa = request.POST['ementa'] + doc.save() msg = _('Documento(s) criado(s).') messages.add_message(request, messages.SUCCESS, msg) return self.get(request, self.kwargs) From af9603972587a7c01ed182d422693d94f81d25f3 Mon Sep 17 00:00:00 2001 From: Edward Ribeiro Date: Tue, 23 May 2017 15:50:47 -0300 Subject: [PATCH 15/17] Conserta DocumentoAcessorioEmLote --- sapl/materia/views.py | 2 +- sapl/templates/materia/em_lote/acessorio.html | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/sapl/materia/views.py b/sapl/materia/views.py index 2af41db6d..f0c95f330 100644 --- a/sapl/materia/views.py +++ b/sapl/materia/views.py @@ -1616,7 +1616,7 @@ class DocumentoAcessorioEmLoteView(PermissionRequiredMixin, FilterView): doc = DocumentoAcessorio() doc.materia_id = materia_id doc.tipo = tipo - doc.arquivo = request.POST['arquivo'] + doc.arquivo = request.FILES['arquivo'] doc.nome = request.POST['nome'] doc.data = datetime.strptime(request.POST['data'], "%d/%m/%Y") doc.autor_id = request.POST['autor'] diff --git a/sapl/templates/materia/em_lote/acessorio.html b/sapl/templates/materia/em_lote/acessorio.html index 1fe8086cc..a4b09d796 100644 --- a/sapl/templates/materia/em_lote/acessorio.html +++ b/sapl/templates/materia/em_lote/acessorio.html @@ -14,7 +14,7 @@ {% else %}

{% blocktrans with object_list.count as total_materias %}Foram encontradas {{total_materias}} matérias.{% endblocktrans %}

{% endif %} -
+ {% csrf_token %}
Documento Acessório @@ -42,7 +42,7 @@
- +
From bf7c477641ca6898fb797d62799bfda85aa33e3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rog=C3=A9rio=20Fr=C3=A1?= Date: Tue, 23 May 2017 16:18:22 -0300 Subject: [PATCH 16/17] fix conserta acessorio em lote (#1119) --- sapl/materia/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sapl/materia/views.py b/sapl/materia/views.py index f0c95f330..180a69690 100644 --- a/sapl/materia/views.py +++ b/sapl/materia/views.py @@ -1619,7 +1619,7 @@ class DocumentoAcessorioEmLoteView(PermissionRequiredMixin, FilterView): doc.arquivo = request.FILES['arquivo'] doc.nome = request.POST['nome'] doc.data = datetime.strptime(request.POST['data'], "%d/%m/%Y") - doc.autor_id = request.POST['autor'] + doc.autor = request.POST['autor'] doc.ementa = request.POST['ementa'] doc.save() msg = _('Documento(s) criado(s).') From c2fcc06d0ddb7fb7789d67d6bf02bca6436c9c9f Mon Sep 17 00:00:00 2001 From: Edward Ribeiro Date: Tue, 23 May 2017 18:08:05 -0300 Subject: [PATCH 17/17] =?UTF-8?q?Captura=20erro=20de=20indexa=C3=A7=C3=A3o?= =?UTF-8?q?=20de=20arquivo.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sapl/base/search_indexes.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/sapl/base/search_indexes.py b/sapl/base/search_indexes.py index 58e1688c4..61fe3438a 100644 --- a/sapl/base/search_indexes.py +++ b/sapl/base/search_indexes.py @@ -32,10 +32,7 @@ class DocumentoAcessorioIndex(indexes.SearchIndex, indexes.Indexable): arquivo = getattr(obj, self.filename) if arquivo: - try: - arquivo.open() - arquivo.close() - except OSError: + if not os.path.exists(arquivo.path): return self.prepared_data if not os.path.splitext(arquivo.path)[1][:1]: @@ -43,10 +40,13 @@ class DocumentoAcessorioIndex(indexes.SearchIndex, indexes.Indexable): try: extracted_data = textract.process( - arquivo.path).decode( - 'utf-8').replace('\n', ' ') + arquivo.path, + language='pt-br').decode('utf-8').replace('\n', ' ') except ExtensionNotSupported: return self.prepared_data + except Exception: + print('Erro inesperado processando arquivo: %s' % arquivo.path) + return self.prepared_data extracted_data = extracted_data.replace('\t', ' ')