Browse Source

Add pesquisa em Autor pelo campo ativo de parlamentar

pull/1117/head
LeandroRoberto 8 years ago
parent
commit
fe5a28ccdc
  1. 11
      sapl/api/forms.py
  2. 12
      sapl/parlamentares/models.py
  3. 24
      sapl/utils.py

11
sapl/api/forms.py

@ -35,10 +35,11 @@ class SaplGenericRelationSearchFilterSet(FilterSet):
item.related_query_name(), item.related_query_name(),
field[0]) field[0])
) )
q_fs = q_fs | Q(**{'%s__%s%s' % ( if len(field) == 3 and field[2](qtext) is not None:
item.related_query_name(), q_fs = q_fs | Q(**{'%s__%s%s' % (
field[0], item.related_query_name(),
field[1]): qtext}) field[0],
field[1]): qtext if len(field) == 2 else field[2](qtext)})
q = q & q_fs q = q & q_fs
@ -60,4 +61,4 @@ class AutorChoiceFilterSet(SaplGenericRelationSearchFilterSet):
def filter_q(self, queryset, value): def filter_q(self, queryset, value):
return SaplGenericRelationSearchFilterSet.filter_q( return SaplGenericRelationSearchFilterSet.filter_q(
self, queryset, value).order_by('nome') self, queryset, value).distinct('nome').order_by('nome')

12
sapl/parlamentares/models.py

@ -1,9 +1,9 @@
from datetime import datetime from datetime import datetime
import reversion
from django.db import models from django.db import models
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from model_utils import Choices from model_utils import Choices
import reversion
from sapl.base.models import Autor from sapl.base.models import Autor
from sapl.utils import (INDICADOR_AFASTAMENTO, UF, YES_NO_CHOICES, 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='') 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() @reversion.register()
class Parlamentar(models.Model): class Parlamentar(models.Model):
FEMININO = 'F' FEMININO = 'F'
@ -303,6 +312,7 @@ class Parlamentar(models.Model):
('nome_completo', '__icontains'), ('nome_completo', '__icontains'),
('nome_parlamentar', '__icontains'), ('nome_parlamentar', '__icontains'),
('filiacao__partido__sigla', '__icontains'), ('filiacao__partido__sigla', '__icontains'),
('ativo', '', true_false_none),
)) ))
class Meta: class Meta:

24
sapl/utils.py

@ -1,15 +1,13 @@
import hashlib
import logging
import os
import re
from datetime import date from datetime import date
from functools import wraps from functools import wraps
from unicodedata import normalize as unicodedata_normalize
from subprocess import PIPE, call from subprocess import PIPE, call
from threading import Thread 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.helper import FormHelper
from crispy_forms.layout import HTML, Button from crispy_forms.layout import HTML, Button
from django import forms from django import forms
@ -22,10 +20,13 @@ from django.core.exceptions import ValidationError
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from floppyforms import ClearableFileInput from floppyforms import ClearableFileInput
from reversion.admin import VersionAdmin from reversion.admin import VersionAdmin
import django_filters
import magic
from sapl.crispy_layout_mixin import SaplFormLayout, form_actions, to_row from sapl.crispy_layout_mixin import SaplFormLayout, form_actions, to_row
from sapl.settings import BASE_DIR, PROJECT_DIR from sapl.settings import BASE_DIR, PROJECT_DIR
sapl_logger = logging.getLogger(BASE_DIR.name) sapl_logger = logging.getLogger(BASE_DIR.name)
@ -159,8 +160,8 @@ class SaplGenericRelation(GenericRelation):
assert isinstance(field, (tuple, list)), _( assert isinstance(field, (tuple, list)), _(
'fields_search deve ser um array de tuplas ou listas.') 'fields_search deve ser um array de tuplas ou listas.')
assert len(field) == 2, _( assert len(field) <= 3, _(
'cada tupla de fields_search deve possuir duas strins') 'cada tupla de fields_search deve possuir até 3 strings')
# TODO implementar assert para validar campos do Model e lookups # 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): def restringe_tipos_de_arquivo(value):
if not os.path.splitext(value.path)[1][:1]: if not os.path.splitext(value.path)[1][:1]:
raise ValidationError(_( raise ValidationError(_(
'Não é possível fazer upload de arquivos sem extensão.')) 'Não é possível fazer upload de arquivos sem extensão.'))
mime = magic.from_buffer(value.read(), mime=True) mime = magic.from_buffer(value.read(), mime=True)
if mime not in lista: if mime not in lista:
@ -637,6 +638,7 @@ def texto_upload_path(instance, filename, subpath=''):
class UpdateIndexCommand(Thread): class UpdateIndexCommand(Thread):
def run(self): def run(self):
call([PROJECT_DIR.child('manage.py'), 'update_index'], call([PROJECT_DIR.child('manage.py'), 'update_index'],
stdout=PIPE) stdout=PIPE)

Loading…
Cancel
Save