From 2665c055f915d3307cceba9b0e0226860e59abb9 Mon Sep 17 00:00:00 2001 From: Marcio Mazza Date: Tue, 28 Jul 2015 11:37:53 -0300 Subject: [PATCH] Change table headers to verbose names in crud list --- comissoes/models.py | 3 ++- sapl/crud.py | 8 +++++--- sapl/test_crud.py | 4 ++-- templates/crud/list.html | 6 +++--- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/comissoes/models.py b/comissoes/models.py index a28bfd79d..859328165 100644 --- a/comissoes/models.py +++ b/comissoes/models.py @@ -81,7 +81,8 @@ class Comissao(models.Model): email = models.CharField( max_length=100, blank=True, null=True, verbose_name=_('E-mail')) unidade_deliberativa = models.BooleanField( - choices=UNIDADE_DELIBERATIVA_CHOICES) + choices=UNIDADE_DELIBERATIVA_CHOICES, + verbose_name=_('Unidade Deliberativa')) class Meta: verbose_name = _('Comissão') diff --git a/sapl/crud.py b/sapl/crud.py index a515f310e..6f41596dc 100644 --- a/sapl/crud.py +++ b/sapl/crud.py @@ -129,7 +129,7 @@ def build_crud(model, *layout): rows = layout[0][1:] return [fieldname for row in rows for fieldname, __ in row] - def get_field_values(self, object_list): + def get_rows(self, object_list): return [[(get_field_display(obj, name)[1], obj.pk if i == 0 else None) for i, name in enumerate(self.field_names)] @@ -143,8 +143,10 @@ def build_crud(model, *layout): context['page_range'] = make_pagination( page_obj.number, paginator.num_pages) object_list = context['object_list'] - context['field_names'] = self.field_names - context['field_values'] = self.get_field_values(object_list) + context['headers'] = [ + self.model._meta.get_field(fieldname).verbose_name + for fieldname in self.field_names] + context['rows'] = self.get_rows(object_list) context['NO_ENTRIES_MSG'] = NO_ENTRIES_MSG return context diff --git a/sapl/test_crud.py b/sapl/test_crud.py index a194236cf..7713e2029 100644 --- a/sapl/test_crud.py +++ b/sapl/test_crud.py @@ -138,7 +138,7 @@ def test_crud_detail_view_fieldsets(monkeypatch): {'id': 'unidade_deliberativa', 'span': 3, 'text': 'Sim', - 'verbose_name': 'unidade deliberativa'}]]}, + 'verbose_name': 'Unidade Deliberativa'}]]}, {'legend': 'Dados Complementares', 'rows': [[{'id': 'finalidade', 'span': 12, @@ -217,7 +217,7 @@ def test_flux_list_paginate_detail( table = res.html.find('table') assert table header, *trs = table.findAll('tr') - assert header.text.strip().split() == ['nome', 'sigla', 'tipo'] + assert header.text.strip().split() == ['Nome', 'Sigla', 'Tipo'] rows = [[td.text.strip() for td in tr.findAll('td')] for tr in trs] diff --git a/templates/crud/list.html b/templates/crud/list.html index 73d2d0ff3..46ca1e643 100644 --- a/templates/crud/list.html +++ b/templates/crud/list.html @@ -10,19 +10,19 @@ -{% if not field_values %} +{% if not rows %}

{{ NO_ENTRIES_MSG }}

{% else %} - {% for name in field_names %} + {% for name in headers %} {% endfor %} - {% for value_list in field_values %} + {% for value_list in rows %} {% for value, href in value_list %}
{{ name }}