Browse Source

Fix #1621 - Migra para Django 1.11.x

pull/2448/head
Leandro Roberto da Silva 6 years ago
committed by GitHub
parent
commit
f6fb0b51fc
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 56
      requirements/requirements.txt
  2. 2
      sapl/api/forms.py
  3. 5
      sapl/api/views.py
  4. 2
      sapl/base/email_utils.py
  5. 15
      sapl/base/templatetags/common_tags.py
  6. 15
      sapl/crud/base.py
  7. 8
      sapl/sessao/forms.py
  8. 47
      sapl/settings.py
  9. 3
      sapl/static/styles/app.scss
  10. 22
      sapl/temp_suppress_crispy_form_warnings.py
  11. 6
      sapl/templates/parlamentares/parlamentares_list.html
  12. 37
      sapl/utils.py
  13. 56
      setup.py

56
requirements/requirements.txt

@ -1,37 +1,39 @@
dj-database-url==0.4.1
django-haystack==2.6.0
django>=1.10,<1.11
django-bootstrap3==7.0.1
django>=1.11,<2.0
django-bootstrap3==11.0.0
django-haystack==2.8.1
django-filter==2.0.0
djangorestframework==3.9.0
dj-database-url==0.5.0
django-bower==5.2.0
django-braces==1.9.0
django-compressor==2.0
django-crispy-forms==1.6.1
django-extensions==1.9.8
django-extra-views==0.11.0
django-filter==1.0.0
django-floppyforms==1.6.2
django-model-utils==3.1.1
django-sass-processor==0.5.8
djangorestframework==3.4.0
easy-thumbnails==2.5
django-crispy-forms==1.7.2
django-floppyforms==1.7.0
django-extra-views==0.12.0
django-model-utils==3.1.2
django-sass-processor==0.7.2
django-reversion==3.0.2
django-reversion-compare==0.8.6
django-speedinfo==1.4.0
django-extensions==2.1.4
django-image-cropping==1.2
libsass==0.11.1
psycopg2-binary==2.7.4
python-decouple==3.0
pytz==2016.4
easy-thumbnails==2.5
libsass==0.17.0
python-decouple==3.1
psycopg2-binary==2.7.6.1
pyyaml==4.2b1
rtyaml==0.0.3
textract==1.5.0
pytz==2018.9
rtyaml==0.0.5
python-magic==0.4.15
unipath==1.1
WeasyPrint==44
gunicorn==19.9.0
textract==1.5.0
pysolr==3.6.0
python-magic==0.4.12
gunicorn==19.6.0
django-reversion==2.0.8
WeasyPrint==0.42
whoosh==2.7.4
django-speedinfo==1.3.5
django-reversion-compare==0.8.4
git+git://github.com/interlegis/trml2pdf.git
git+git://github.com/jasperlittle/django-rest-framework-docs
git+git://github.com/rubgombar1/django-admin-bootstrapped.git
git+git://github.com/rubgombar1/django-admin-bootstrapped.git
#django-compressor==2.2

2
sapl/api/forms.py

@ -6,8 +6,8 @@ from django.forms.widgets import MultiWidget, TextInput
from django.utils import timezone
from django.utils.translation import ugettext_lazy as _
from django_filters.filters import CharFilter, ModelChoiceFilter, DateFilter
from django_filters.rest_framework.filterset import FilterSet
from rest_framework import serializers
from rest_framework.filters import FilterSet
from sapl.base.models import Autor, TipoAutor
from sapl.parlamentares.models import Legislatura

5
sapl/api/views.py

@ -1,9 +1,10 @@
import logging
from django.contrib.contenttypes.models import ContentType
from django.db.models import Q
from django.http import Http404
from django.utils.translation import ugettext_lazy as _
from rest_framework.filters import DjangoFilterBackend
from django_filters.rest_framework.backends import DjangoFilterBackend
from rest_framework.generics import ListAPIView
from rest_framework.mixins import ListModelMixin, RetrieveModelMixin
from rest_framework.permissions import (AllowAny, IsAuthenticated,
@ -175,7 +176,7 @@ class AutoresProvaveisListView(ListAPIView):
serializer_class = ChoiceSerializer
def get_queryset(self):
params = {'content_type__isnull': False}
username = self.request.user.username
tipo = ''

2
sapl/base/email_utils.py

@ -18,7 +18,7 @@ def load_email_templates(templates, context={}):
emails = []
for t in templates:
tpl = loader.get_template(t)
email = tpl.render(Context(context))
email = tpl.render(context)
if t.endswith(".html"):
email = email.replace('\n', '').replace('\r', '')
emails.append(email)

15
sapl/base/templatetags/common_tags.py

@ -1,8 +1,4 @@
import logging
from compressor.utils import get_class
from django import template
from django.conf import settings
from django.template.defaultfilters import stringfilter
from sapl.base.models import AppConfig
@ -15,6 +11,15 @@ from sapl.utils import filiacao_data, SEPARADOR_HASH_PROPOSICAO
register = template.Library()
def get_class(class_string):
if not hasattr(class_string, '__bases__'):
class_string = str(class_string)
dot = class_string.rindex('.')
mod_name, class_name = class_string[:dot], class_string[dot + 1:]
if class_name:
return getattr(__import__(mod_name, {}, {}, [str('')]), class_name)
@register.simple_tag
def define(arg):
return arg
@ -228,7 +233,7 @@ def file_extension(value):
def cronometro_to_seconds(value):
if not AppConfig.attr('cronometro_' + value):
return 0
return AppConfig.attr('cronometro_' + value).seconds

15
sapl/crud/base.py

@ -1,6 +1,6 @@
import logging
from braces.views import FormMessagesMixin
from compressor.utils.decorators import cached_property
from crispy_forms.bootstrap import FieldWithButtons, StrictButton
from crispy_forms.helper import FormHelper
from crispy_forms.layout import Field, Layout
@ -16,6 +16,7 @@ from django.http.response import Http404
from django.shortcuts import redirect
from django.utils.decorators import classonlymethod
from django.utils.encoding import force_text
from django.utils.functional import cached_property
from django.utils.translation import string_concat
from django.utils.translation import ugettext_lazy as _
from django.views.generic import (CreateView, DeleteView, DetailView, ListView,
@ -29,6 +30,7 @@ from sapl.rules.map_rules import (RP_ADD, RP_CHANGE, RP_DELETE, RP_DETAIL,
from sapl.settings import BASE_DIR
from sapl.utils import normalize
ACTION_LIST, ACTION_CREATE, ACTION_DETAIL, ACTION_UPDATE, ACTION_DELETE = \
'list', 'create', 'detail', 'update', 'delete'
@ -558,7 +560,8 @@ class CrudListView(PermissionRequiredContainerCrudMixin, ListView):
fm = model._meta.get_field(fo)
except Exception as e:
username = self.request.user.username
self.logger.error("user=" + username + ". " + str(e))
self.logger.error(
"user=" + username + ". " + str(e))
pass
if fm and hasattr(fm, 'related_model')\
@ -824,7 +827,7 @@ class CrudUpdateView(PermissionRequiredContainerCrudMixin,
logger = logging.getLogger(__name__)
def form_valid(self, form):
self.object = form.instance
try:
self.object.modifier = self.request.user
@ -882,12 +885,12 @@ class CrudDeleteView(PermissionRequiredContainerCrudMixin,
error_msg2 += '{} - {}, '.format(
i._meta.verbose_name, i
)
error_msg2 = error_msg2[:len(error_msg2)-2] + '.'
error_msg2 = error_msg2[:len(error_msg2) - 2] + '.'
error_msg += '</ul>'
username = request.user.username
self.logger.error("user=" + username + ". Registro não pode ser removido, pois "
"é referenciado por outros registros: " + error_msg2)
"é referenciado por outros registros: " + error_msg2)
messages.add_message(request,
messages.ERROR,
error_msg)

8
sapl/sessao/forms.py

@ -3,7 +3,6 @@ from datetime import datetime
from crispy_forms.helper import FormHelper
from crispy_forms.layout import HTML, Button, Fieldset, Layout
from django import forms
from django.contrib import messages
from django.contrib.contenttypes.models import ContentType
from django.core.exceptions import ObjectDoesNotExist, ValidationError
from django.db import transaction
@ -12,22 +11,21 @@ from django.forms import ModelForm
from django.forms.widgets import CheckboxSelectMultiple
from django.utils.translation import ugettext_lazy as _
import django_filters
from floppyforms import widgets
from sapl.base.models import Autor, TipoAutor
from sapl.crispy_layout_mixin import form_actions, to_row, SaplFormLayout
from sapl.materia.forms import MateriaLegislativaFilterSet
from sapl.materia.models import (MateriaLegislativa, StatusTramitacao,
TipoMateriaLegislativa)
from sapl.parlamentares.models import Parlamentar, Legislatura, Mandato
from sapl.parlamentares.models import Parlamentar, Mandato
from sapl.utils import (RANGE_DIAS_MES, RANGE_MESES,
MateriaPesquisaOrderingFilter, autor_label,
autor_modal, timezone, choice_anos_com_sessaoplenaria)
from .models import (Bancada, Bloco, ExpedienteMateria, JustificativaAusencia,
Orador, OradorExpediente, OrdemDia, PresencaOrdemDia, SessaoPlenaria,
SessaoPlenariaPresenca, TipoJustificativa, TipoResultadoVotacao,
OcorrenciaSessao, RegistroVotacao, RetiradaPauta, TipoRetiradaPauta)
SessaoPlenariaPresenca, TipoResultadoVotacao,
OcorrenciaSessao, RetiradaPauta, TipoRetiradaPauta)
MES_CHOICES = RANGE_MESES

47
sapl/settings.py

@ -22,9 +22,6 @@ from dj_database_url import parse as db_url
from easy_thumbnails.conf import Settings as thumbnail_settings
from unipath import Path
from .temp_suppress_crispy_form_warnings import \
SUPRESS_CRISPY_FORM_WARNINGS_LOGGING
host = socket.gethostbyname_ex(socket.gethostname())[0]
@ -78,20 +75,24 @@ INSTALLED_APPS = (
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
# more
'django_extensions',
'djangobower',
'bootstrap3', # basically for django_admin_bootstrapped
'bootstrap3',
'crispy_forms',
'easy_thumbnails',
'image_cropping',
'floppyforms',
'haystack',
'sass_processor',
'rest_framework',
'django_filters',
'easy_thumbnails',
'image_cropping',
'reversion',
'reversion_compare',
'haystack',
'whoosh',
'speedinfo',
@ -110,7 +111,7 @@ SOLR_URL = config('SOLR_URL', cast=str, default='http://localhost:8983')
SOLR_COLLECTION = config('SOLR_COLLECTION', cast=str, default='sapl')
if USE_SOLR:
HAYSTACK_SIGNAL_PROCESSOR = 'haystack.signals.RealtimeSignalProcessor' #enable auto-index
HAYSTACK_SIGNAL_PROCESSOR = 'haystack.signals.RealtimeSignalProcessor' # enable auto-index
SEARCH_BACKEND = 'haystack.backends.solr_backend.SolrEngine'
SEARCH_URL = ('URL', '{}/solr/{}'.format(SOLR_URL, SOLR_COLLECTION))
@ -118,7 +119,7 @@ if USE_SOLR:
HAYSTACK_CONNECTIONS = {
'default': {
'ENGINE': SEARCH_BACKEND,
SEARCH_URL[0]: SEARCH_URL[1],
SEARCH_URL[0]: SEARCH_URL[1],
'BATCH_SIZE': 1000,
'TIMEOUT': 60,
},
@ -166,7 +167,7 @@ REST_FRAMEWORK = {
"DEFAULT_PAGINATION_CLASS": "sapl.api.pagination.StandardPagination",
"DEFAULT_FILTER_BACKENDS": (
"rest_framework.filters.SearchFilter",
"rest_framework.filters.DjangoFilterBackend",
'django_filters.rest_framework.DjangoFilterBackend',
),
}
@ -282,6 +283,7 @@ DAB_FIELD_RENDERER = \
CRISPY_TEMPLATE_PACK = 'bootstrap3'
CRISPY_ALLOWED_TEMPLATE_PACKS = 'bootstrap3'
CRISPY_FAIL_SILENTLY = not DEBUG
FLOPPY_FORMS_USE_GIS = False
BOWER_COMPONENTS_ROOT = PROJECT_DIR.child("bower")
BOWER_INSTALLED_APPS = (
@ -339,6 +341,22 @@ LOGGING = {
}
}
PASSWORD_HASHERS = [
'django.contrib.auth.hashers.PBKDF2PasswordHasher', # default
'sapl.hashers.ZopeSHA1PasswordHasher',
]
def remove_warnings():
import warnings
warnings.filterwarnings(
'ignore', module='floppyforms',
message='Unable to import floppyforms.gis'
)
remove_warnings()
def uncaught_exceptions(type, value, error_traceback):
import traceback
@ -350,8 +368,3 @@ def uncaught_exceptions(type, value, error_traceback):
# captura exceções que não foram tratadas
sys.excepthook = uncaught_exceptions
PASSWORD_HASHERS = [
'django.contrib.auth.hashers.PBKDF2PasswordHasher', # default
'sapl.hashers.ZopeSHA1PasswordHasher',
]

3
sapl/static/styles/app.scss

@ -451,6 +451,9 @@ nav {
overflow-x: auto;
}
}
.lista-parlamentares .table td {
vertical-align: middle;
}
@media (min-width: 1092px) and (max-width: 1199px) {
.container {

22
sapl/temp_suppress_crispy_form_warnings.py

@ -1,22 +0,0 @@
import copy
import logging
from django.utils.log import DEFAULT_LOGGING
# hack to suppress many annoying warnings from crispy_forms
# Do remove this file and corresponding import in settings
# when crispy_forms is corrected !!!
SUPRESS_CRISPY_FORM_WARNINGS_LOGGING = copy.deepcopy(DEFAULT_LOGGING)
SUPRESS_CRISPY_FORM_WARNINGS_LOGGING['filters']['suppress_deprecated'] = {
'()': 'sapl.temp_suppress_crispy_form_warnings.SuppressDeprecated'
}
SUPRESS_CRISPY_FORM_WARNINGS_LOGGING['handlers']['console']['filters'].append(
'suppress_deprecated')
class SuppressDeprecated(logging.Filter):
def filter(self, record):
msg = record.getMessage()
return not ('crispy_forms' in msg and
'RemovedInDjango19Warning' in msg)

6
sapl/templates/parlamentares/parlamentares_list.html

@ -21,7 +21,7 @@
{% if not rows %}
<p>{{ NO_ENTRIES_MSG }}</p>
{% else %}
<div class="container-table">
<div class="container-table lista-parlamentares">
<div class="result-count">{% blocktrans with verbose_name_plural=view.verbose_name_plural %}Total de {{ verbose_name_plural }}: <strong>{{count}}</strong>{% endblocktrans %}</div>
<table class="table table-striped table-hover table-link-ordering">
<thead>
@ -43,7 +43,9 @@
{% for value, href, obj in value_list %}
{% if forloop.first %}
<td>
<img class="avatar-parlamentar" src="{% cropped_thumbnail obj "cropping" %}">
{% if obj.fotografia %}
<img class="avatar-parlamentar" src="{% cropped_thumbnail obj "cropping" %}">
{% endif %}
</td>
{% endif %}
<td>

37
sapl/utils.py

@ -21,7 +21,6 @@ from django.db.models import Q
from django.utils import six, timezone
from django.utils.translation import ugettext_lazy as _
import django_filters
from django_filters.filterset import STRICTNESS
from easy_thumbnails import source_generators
from floppyforms import ClearableFileInput
import magic
@ -209,19 +208,27 @@ class RangeWidgetOverride(forms.MultiWidget):
def __init__(self, attrs=None):
widgets = (forms.DateInput(format='%d/%m/%Y',
attrs={'class': 'dateinput',
attrs={'class': 'dateinput form-control',
'placeholder': 'Inicial'}),
forms.DateInput(format='%d/%m/%Y',
attrs={'class': 'dateinput',
attrs={'class': 'dateinput form-control',
'placeholder': 'Final'}))
super(RangeWidgetOverride, self).__init__(widgets, attrs)
def decompress(self, value):
if value:
return [value.start, value.stop]
return [None, None]
return []
def render(self, name, value, attrs=None, renderer=None):
rendered_widgets = []
for i, x in enumerate(self.widgets):
rendered_widgets.append(
x.render(
'%s_%d' % (name, i), value[i] if value else ''
)
)
def format_output(self, rendered_widgets):
html = '<div class="col-sm-6">%s</div><div class="col-sm-6">%s</div>'\
% tuple(rendered_widgets)
return '<div class="row">%s</div>' % html
@ -685,12 +692,12 @@ def qs_override_django_filter(self):
valid = self.is_bound and self.form.is_valid()
if self.is_bound and not valid:
if self.strict == STRICTNESS.RAISE_VALIDATION_ERROR:
"""if self.strict == STRICTNESS.RAISE_VALIDATION_ERROR:
raise forms.ValidationError(self.form.errors)
elif bool(self.strict) == STRICTNESS.RETURN_NO_RESULTS:
self._qs = self.queryset.none()
return self._qs
# else STRICTNESS.IGNORE... ignoring
elif bool(self.strict) == STRICTNESS.RETURN_NO_RESULTS:"""
self._qs = self.queryset.none()
return self._qs
# else STRICTNESS.IGNORE... ignoring
# start with all the results and filter from there
qs = self.queryset.all()
@ -703,12 +710,12 @@ def qs_override_django_filter(self):
try:
value = self.form.fields[name].clean(raw_value)
except forms.ValidationError:
if self.strict == STRICTNESS.RAISE_VALIDATION_ERROR:
"""if self.strict == STRICTNESS.RAISE_VALIDATION_ERROR:
raise
elif bool(self.strict) == STRICTNESS.RETURN_NO_RESULTS:
self._qs = self.queryset.none()
return self._qs
# else STRICTNESS.IGNORE... ignoring
elif bool(self.strict) == STRICTNESS.RETURN_NO_RESULTS:"""
self._qs = self.queryset.none()
return self._qs
# else STRICTNESS.IGNORE... ignoring
if value is not None: # valid & clean data
qs = qs._next_is_sticky()

56
setup.py

@ -9,43 +9,45 @@ with open(os.path.join(os.path.dirname(__file__), 'README.rst')) as readme:
os.chdir(os.path.normpath(os.path.join(os.path.abspath(__file__), os.pardir)))
install_requires = [
'dj-database-url==0.4.1',
'django-haystack==2.6.0',
'django>=1.10,<1.11',
'django-bootstrap3==7.0.1',
'django>=1.11,<2.0',
'django-bootstrap3==11.0.0',
'django-haystack==2.8.1',
'django-filter==2.0.0',
'djangorestframework==3.9.0',
'dj-database-url==0.5.0',
'django-bower==5.2.0',
'django-braces==1.9.0',
'django-compressor==2.0',
'django-crispy-forms==1.6.1',
'django-extensions==1.9.8',
'django-extra-views==0.11.0',
'django-filter==0.15.3',
'django-floppyforms==1.6.2',
'django-model-utils==3.1.1',
'django-sass-processor==0.5.8',
'djangorestframework==3.4.0',
'drfdocs',
'django-crispy-forms==1.7.2',
'django-floppyforms==1.7.0',
'django-extra-views==0.12.0',
'django-model-utils==3.1.2',
'django-sass-processor==0.7.2',
'django-reversion==3.0.2',
'django-reversion-compare==0.8.6'
'django-speedinfo==1.4.0',
'django-extensions==2.1.4',
'django-image-cropping==1.2.0',
'easy-thumbnails==2.5',
'django-image-cropping==1.1.0',
'libsass==0.11.1',
'psycopg2==2.7.4',
'python-decouple==3.0',
'pytz==2016.4',
'libsass==0.17.0',
'python-decouple==3.1',
'psycopg2-binary==2.7.6.1',
'pyyaml==4.2b1',
'rtyaml==0.0.3',
'textract==1.5.0',
'pytz==2018.9',
'rtyaml==0.0.5',
'python-magic==0.4.15',
'unipath==1.1',
'WeasyPrint==44',
'gunicorn==19.9.0',
'textract==1.5.0',
'pysolr==3.6.0',
'python-magic==0.4.12',
'gunicorn==19.6.0',
'django-reversion==2.0.8',
'WeasyPrint==0.42',
'whoosh==2.7.4',
'django-speedinfo==1.3.5',
'django-reversion-compare==0.8.4'
# 'git+git://github.com/interlegis/trml2pdf.git',
# 'git+git://github.com/jasperlittle/django-rest-framework-docs'
# 'git+git://github.com/rubgombar1/django-admin-bootstrapped.git''
#'django-compressor==2.2',
]
setup(
name='interlegis-sapl',

Loading…
Cancel
Save