Browse Source

Imprime datas em CRUD automático de acordo com formato em settings.py

pull/336/head
Edward Ribeiro 9 years ago
parent
commit
8504619c75
  1. 5
      crispy_layout_mixin.py
  2. 3
      protocoloadm/views.py

5
crispy_layout_mixin.py

@ -5,6 +5,7 @@ import rtyaml
from crispy_forms.bootstrap import FormActions from crispy_forms.bootstrap import FormActions
from crispy_forms.helper import FormHelper from crispy_forms.helper import FormHelper
from crispy_forms.layout import HTML, Div, Fieldset, Layout, Submit from crispy_forms.layout import HTML, Div, Fieldset, Layout, Submit
from django.utils import formats
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
@ -57,9 +58,9 @@ def get_field_display(obj, fieldname):
if value is None: if value is None:
display = '' display = ''
elif 'date' in str(type(value)): elif 'date' in str(type(value)):
display = value.strftime("%d/%m/%Y") # TODO: localize display = formats.date_format(value, "SHORT_DATE_FORMAT")
elif 'bool' in str(type(value)): elif 'bool' in str(type(value)):
display = 'Sim' if value else 'Não' display = _('Sim') if value else _('Não')
else: else:
display = str(value) display = str(value)
return verbose_name, display return verbose_name, display

3
protocoloadm/views.py

@ -67,7 +67,7 @@ class ProtocoloPesquisaView(FormView):
# kwargs['final'] = request.POST['final'] # kwargs['final'] = request.POST['final']
# if request.POST['natureza_processo']: # if request.POST['natureza_processo']:
# kwargs['natureza_processo'] = request.POST['natureza_processo'] # kwargs['natureza_processo'] = request.POST['natureza_processo']
if request.POST['tipo_documento']: if request.POST['tipo_documento']:
kwargs['tipo_documento'] = request.POST['tipo_documento'] kwargs['tipo_documento'] = request.POST['tipo_documento']
@ -238,6 +238,7 @@ class ComprovanteProtocoloView(TemplateView):
autenticacao = _("** NULO **") autenticacao = _("** NULO **")
if not protocolo.anulado: if not protocolo.anulado:
# data is not i18n sensitive 'Y-m-d' is the right format.
autenticacao = str(protocolo.tipo_processo) + \ autenticacao = str(protocolo.tipo_processo) + \
protocolo.data.strftime("%Y/%m/%d") + \ protocolo.data.strftime("%Y/%m/%d") + \
str(protocolo.numero).zfill(6) str(protocolo.numero).zfill(6)

Loading…
Cancel
Save