|
@ -1,12 +1,13 @@ |
|
|
from math import ceil |
|
|
from math import ceil |
|
|
|
|
|
|
|
|
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 import template |
|
|
from django import template |
|
|
|
|
|
from django.core.urlresolvers import reverse |
|
|
from django.utils import formats |
|
|
from django.utils import formats |
|
|
from django.utils.translation import ugettext as _ |
|
|
from django.utils.translation import ugettext as _ |
|
|
|
|
|
import rtyaml |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def heads_and_tails(list_of_lists): |
|
|
def heads_and_tails(list_of_lists): |
|
@ -77,29 +78,30 @@ def get_field_display(obj, fieldname): |
|
|
else: |
|
|
else: |
|
|
value = getattr(obj, fieldname) |
|
|
value = getattr(obj, fieldname) |
|
|
|
|
|
|
|
|
str_type = str(type(value)) |
|
|
str_type_from_value = str(type(value)) |
|
|
|
|
|
str_type_from_field = str(type(field)) |
|
|
|
|
|
|
|
|
if value is None: |
|
|
if value is None: |
|
|
display = '' |
|
|
display = '' |
|
|
elif 'date' in str_type: |
|
|
elif 'date' in str_type_from_value: |
|
|
display = formats.date_format(value, "SHORT_DATE_FORMAT") |
|
|
display = formats.date_format(value, "SHORT_DATE_FORMAT") |
|
|
elif 'bool' in str(type(value)): |
|
|
elif 'bool' in str_type_from_value: |
|
|
display = _('Sim') if value else _('Não') |
|
|
display = _('Sim') if value else _('Não') |
|
|
elif 'ImageFieldFile' in str(type(value)): |
|
|
elif 'ImageFieldFile' in str(type(value)): |
|
|
if value: |
|
|
if value: |
|
|
display = '<img src="{}" />'.format(value.url) |
|
|
display = '<img src="{}" />'.format(value.url) |
|
|
else: |
|
|
else: |
|
|
display = '' |
|
|
display = '' |
|
|
elif 'FieldFile' in str(type(value)): |
|
|
elif 'FieldFile' in str_type_from_value: |
|
|
if value: |
|
|
if value: |
|
|
display = '<a href="{}">{}</a>'.format( |
|
|
display = '<a href="{}">{}</a>'.format( |
|
|
value.url, |
|
|
value.url, |
|
|
value.name.split('/')[-1:][0]) |
|
|
value.name.split('/')[-1:][0]) |
|
|
else: |
|
|
else: |
|
|
display = '' |
|
|
display = '' |
|
|
elif 'ManyRelatedManager' in str(type(value))\ |
|
|
elif 'ManyRelatedManager' in str_type_from_value\ |
|
|
or 'RelatedManager' in str(type(value))\ |
|
|
or 'RelatedManager' in str_type_from_value\ |
|
|
or 'GenericRelatedObjectManager' in str(type(value)): |
|
|
or 'GenericRelatedObjectManager' in str_type_from_value: |
|
|
display = '<ul>' |
|
|
display = '<ul>' |
|
|
for v in value.all(): |
|
|
for v in value.all(): |
|
|
display += '<li>%s</li>' % str(v) |
|
|
display += '<li>%s</li>' % str(v) |
|
@ -110,6 +112,13 @@ def get_field_display(obj, fieldname): |
|
|
field.related_model._meta.verbose_name_plural) |
|
|
field.related_model._meta.verbose_name_plural) |
|
|
elif hasattr(field, 'model'): |
|
|
elif hasattr(field, 'model'): |
|
|
verbose_name = str(field.model._meta.verbose_name_plural) |
|
|
verbose_name = str(field.model._meta.verbose_name_plural) |
|
|
|
|
|
elif 'GenericForeignKey' in str_type_from_field: |
|
|
|
|
|
display = '<a href="{}">{}</a>'.format( |
|
|
|
|
|
reverse( |
|
|
|
|
|
'%s:%s_detail' % ( |
|
|
|
|
|
value._meta.app_config.name, obj.content_type.model), |
|
|
|
|
|
args=(value.id,)), |
|
|
|
|
|
value) |
|
|
else: |
|
|
else: |
|
|
display = str(value) |
|
|
display = str(value) |
|
|
return verbose_name, display |
|
|
return verbose_name, display |
|
|