Browse Source

Refatora widget de range de datas

pull/626/head
LeandroRoberto 8 years ago
parent
commit
8ccb23daf7
  1. 33
      sapl/base/forms.py
  2. 26
      sapl/materia/forms.py
  3. 6
      sapl/protocoloadm/forms.py
  4. 23
      sapl/utils.py

33
sapl/base/forms.py

@ -12,32 +12,12 @@ from sapl.crispy_layout_mixin import form_actions, to_row
from sapl.materia.models import MateriaLegislativa from sapl.materia.models import MateriaLegislativa
from sapl.sessao.models import SessaoPlenaria from sapl.sessao.models import SessaoPlenaria
from sapl.settings import MAX_IMAGE_UPLOAD_SIZE from sapl.settings import MAX_IMAGE_UPLOAD_SIZE
from sapl.utils import (RANGE_ANOS, ImageThumbnailFileInput, autor_label, from sapl.utils import (RANGE_ANOS, ImageThumbnailFileInput,
autor_modal) RangeWidgetOverride, autor_label, autor_modal)
from .models import AppConfig, CasaLegislativa from .models import AppConfig, CasaLegislativa
class RangeWidgetOverride(forms.MultiWidget):
def __init__(self, attrs=None):
widgets = (forms.DateInput(format='%d/%m/%Y',
attrs={'class': 'dateinput',
'placeholder': 'Inicial'}),
forms.DateInput(format='%d/%m/%Y',
attrs={'class': 'dateinput',
'placeholder': 'Final'}))
super(RangeWidgetOverride, self).__init__(widgets, attrs)
def decompress(self, value):
if value:
return [value.start, value.stop]
return [None, None]
def format_output(self, rendered_widgets):
return ''.join(rendered_widgets)
class RelatorioAtasFilterSet(django_filters.FilterSet): class RelatorioAtasFilterSet(django_filters.FilterSet):
filter_overrides = {models.DateField: { filter_overrides = {models.DateField: {
@ -53,7 +33,7 @@ class RelatorioAtasFilterSet(django_filters.FilterSet):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super(RelatorioAtasFilterSet, self).__init__( super(RelatorioAtasFilterSet, self).__init__(
*args, **kwargs) *args, **kwargs)
self.filters['data_inicio'].label = 'Período (Inicial - Final)' self.filters['data_inicio'].label = 'Período (Inicial - Final)'
self.form.fields['data_inicio'].required = True self.form.fields['data_inicio'].required = True
@ -83,7 +63,7 @@ class RelatorioPresencaSessaoFilterSet(django_filters.FilterSet):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super(RelatorioPresencaSessaoFilterSet, self).__init__( super(RelatorioPresencaSessaoFilterSet, self).__init__(
*args, **kwargs) *args, **kwargs)
self.filters['data_inicio'].label = 'Período (Inicial - Final)' self.filters['data_inicio'].label = 'Período (Inicial - Final)'
self.form.fields['data_inicio'].required = True self.form.fields['data_inicio'].required = True
@ -114,7 +94,7 @@ class RelatorioHistoricoTramitacaoFilterSet(django_filters.FilterSet):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super(RelatorioHistoricoTramitacaoFilterSet, self).__init__( super(RelatorioHistoricoTramitacaoFilterSet, self).__init__(
*args, **kwargs) *args, **kwargs)
self.filters['tipo'].label = 'Tipo de Matéria' self.filters['tipo'].label = 'Tipo de Matéria'
@ -146,7 +126,7 @@ class RelatorioMateriasTramitacaoilterSet(django_filters.FilterSet):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super(RelatorioMateriasTramitacaoilterSet, self).__init__( super(RelatorioMateriasTramitacaoilterSet, self).__init__(
*args, **kwargs) *args, **kwargs)
self.filters['tipo'].label = 'Tipo de Matéria' self.filters['tipo'].label = 'Tipo de Matéria'
@ -287,6 +267,7 @@ class LoginForm(AuthenticationForm):
class ConfiguracoesAppForm(ModelForm): class ConfiguracoesAppForm(ModelForm):
class Meta: class Meta:
model = AppConfig model = AppConfig
fields = ['documentos_administrativos', fields = ['documentos_administrativos',

26
sapl/materia/forms.py

@ -17,7 +17,8 @@ from sapl.crispy_layout_mixin import form_actions, to_row
from sapl.norma.models import (LegislacaoCitada, NormaJuridica, from sapl.norma.models import (LegislacaoCitada, NormaJuridica,
TipoNormaJuridica) TipoNormaJuridica)
from sapl.settings import MAX_DOC_UPLOAD_SIZE from sapl.settings import MAX_DOC_UPLOAD_SIZE
from sapl.utils import RANGE_ANOS, autor_label, autor_modal from sapl.utils import (RANGE_ANOS, RangeWidgetOverride, autor_label,
autor_modal)
from .models import (AcompanhamentoMateria, Anexada, Autor, Autoria, from .models import (AcompanhamentoMateria, Anexada, Autor, Autoria,
DespachoInicial, DocumentoAcessorio, MateriaLegislativa, DespachoInicial, DocumentoAcessorio, MateriaLegislativa,
@ -34,6 +35,7 @@ def em_tramitacao():
class ConfirmarProposicaoForm(ModelForm): class ConfirmarProposicaoForm(ModelForm):
class Meta: class Meta:
model = Proposicao model = Proposicao
exclude = ['texto_original', 'descricao', 'tipo'] exclude = ['texto_original', 'descricao', 'tipo']
@ -247,7 +249,7 @@ class TramitacaoForm(ModelForm):
raise ValidationError(msg) raise ValidationError(msg)
if (ultima_tramitacao and if (ultima_tramitacao and
data_tram_form < ultima_tramitacao.data_tramitacao): data_tram_form < ultima_tramitacao.data_tramitacao):
msg = _('A data da nova tramitação deve ser ' + msg = _('A data da nova tramitação deve ser ' +
'maior que a data da última tramitação!') 'maior que a data da última tramitação!')
raise ValidationError(msg) raise ValidationError(msg)
@ -445,26 +447,6 @@ class AnexadaForm(ModelForm):
fields = ['tipo', 'numero', 'ano', 'data_anexacao', 'data_desanexacao'] fields = ['tipo', 'numero', 'ano', 'data_anexacao', 'data_desanexacao']
class RangeWidgetOverride(forms.MultiWidget):
def __init__(self, attrs=None):
widgets = (forms.DateInput(format='%d/%m/%Y',
attrs={'class': 'dateinput',
'placeholder': 'Inicial'}),
forms.DateInput(format='%d/%m/%Y',
attrs={'class': 'dateinput',
'placeholder': 'Final'}))
super(RangeWidgetOverride, self).__init__(widgets, attrs)
def decompress(self, value):
if value:
return [value.start, value.stop]
return [None, None]
def format_output(self, rendered_widgets):
return ''.join(rendered_widgets)
class MateriaLegislativaFilterSet(django_filters.FilterSet): class MateriaLegislativaFilterSet(django_filters.FilterSet):
filter_overrides = {models.DateField: { filter_overrides = {models.DateField: {

6
sapl/protocoloadm/forms.py

@ -11,9 +11,9 @@ from django.forms import ModelForm
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from sapl.crispy_layout_mixin import form_actions, to_row from sapl.crispy_layout_mixin import form_actions, to_row
from sapl.materia.forms import RangeWidgetOverride
from sapl.materia.models import Autor, UnidadeTramitacao from sapl.materia.models import Autor, UnidadeTramitacao
from sapl.utils import RANGE_ANOS, autor_label, autor_modal from sapl.utils import (RANGE_ANOS, RangeWidgetOverride, autor_label,
autor_modal)
from .models import (DocumentoAcessorioAdministrativo, DocumentoAdministrativo, from .models import (DocumentoAcessorioAdministrativo, DocumentoAdministrativo,
Protocolo, TipoDocumentoAdministrativo, Protocolo, TipoDocumentoAdministrativo,
@ -512,7 +512,7 @@ class TramitacaoAdmForm(ModelForm):
raise ValidationError(msg) raise ValidationError(msg)
if (ultima_tramitacao and if (ultima_tramitacao and
data_tram_form < ultima_tramitacao.data_tramitacao): data_tram_form < ultima_tramitacao.data_tramitacao):
msg = _('A data da nova tramitação deve ser ' + msg = _('A data da nova tramitação deve ser ' +
'maior que a data da última tramitação!') 'maior que a data da última tramitação!')
raise ValidationError(msg) raise ValidationError(msg)

23
sapl/utils.py

@ -3,6 +3,7 @@ from datetime import date
from functools import wraps from functools import wraps
import magic import magic
from django import forms
from django.apps import apps from django.apps import apps
from django.conf import settings from django.conf import settings
from django.contrib import admin from django.contrib import admin
@ -46,6 +47,28 @@ class ImageThumbnailFileInput(ClearableFileInput):
template_name = 'floppyforms/image_thumbnail.html' template_name = 'floppyforms/image_thumbnail.html'
class RangeWidgetOverride(forms.MultiWidget):
def __init__(self, attrs=None):
widgets = (forms.DateInput(format='%d/%m/%Y',
attrs={'class': 'dateinput',
'placeholder': 'Inicial'}),
forms.DateInput(format='%d/%m/%Y',
attrs={'class': 'dateinput',
'placeholder': 'Final'}))
super(RangeWidgetOverride, self).__init__(widgets, attrs)
def decompress(self, value):
if value:
return [value.start, value.stop]
return [None, None]
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
def register_all_models_in_admin(module_name): def register_all_models_in_admin(module_name):
appname = module_name.split('.') appname = module_name.split('.')
appname = appname[1] if appname[0] == 'sapl' else appname[0] appname = appname[1] if appname[0] == 'sapl' else appname[0]

Loading…
Cancel
Save