Browse Source

Change table headers to verbose names in crud list

pull/6/head
Marcio Mazza 10 years ago
parent
commit
2665c055f9
  1. 3
      comissoes/models.py
  2. 8
      sapl/crud.py
  3. 4
      sapl/test_crud.py
  4. 6
      templates/crud/list.html

3
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')

8
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

4
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]

6
templates/crud/list.html

@ -10,19 +10,19 @@
</a></dd>
</dl>
{% if not field_values %}
{% if not rows %}
<p>{{ NO_ENTRIES_MSG }}</p>
{% else %}
<table class="table table-hover">
<thead>
<tr>
{% for name in field_names %}
{% for name in headers %}
<th>{{ name }}</th>
{% endfor %}
</tr>
</thead>
<tbody>
{% for value_list in field_values %}
{% for value_list in rows %}
<tr>
{% for value, href in value_list %}
<td>

Loading…
Cancel
Save