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( email = models.CharField(
max_length=100, blank=True, null=True, verbose_name=_('E-mail')) max_length=100, blank=True, null=True, verbose_name=_('E-mail'))
unidade_deliberativa = models.BooleanField( unidade_deliberativa = models.BooleanField(
choices=UNIDADE_DELIBERATIVA_CHOICES) choices=UNIDADE_DELIBERATIVA_CHOICES,
verbose_name=_('Unidade Deliberativa'))
class Meta: class Meta:
verbose_name = _('Comissão') verbose_name = _('Comissão')

8
sapl/crud.py

@ -129,7 +129,7 @@ def build_crud(model, *layout):
rows = layout[0][1:] rows = layout[0][1:]
return [fieldname for row in rows for fieldname, __ in row] 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], return [[(get_field_display(obj, name)[1],
obj.pk if i == 0 else None) obj.pk if i == 0 else None)
for i, name in enumerate(self.field_names)] for i, name in enumerate(self.field_names)]
@ -143,8 +143,10 @@ def build_crud(model, *layout):
context['page_range'] = make_pagination( context['page_range'] = make_pagination(
page_obj.number, paginator.num_pages) page_obj.number, paginator.num_pages)
object_list = context['object_list'] object_list = context['object_list']
context['field_names'] = self.field_names context['headers'] = [
context['field_values'] = self.get_field_values(object_list) 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 context['NO_ENTRIES_MSG'] = NO_ENTRIES_MSG
return context return context

4
sapl/test_crud.py

@ -138,7 +138,7 @@ def test_crud_detail_view_fieldsets(monkeypatch):
{'id': 'unidade_deliberativa', {'id': 'unidade_deliberativa',
'span': 3, 'span': 3,
'text': 'Sim', 'text': 'Sim',
'verbose_name': 'unidade deliberativa'}]]}, 'verbose_name': 'Unidade Deliberativa'}]]},
{'legend': 'Dados Complementares', {'legend': 'Dados Complementares',
'rows': [[{'id': 'finalidade', 'rows': [[{'id': 'finalidade',
'span': 12, 'span': 12,
@ -217,7 +217,7 @@ def test_flux_list_paginate_detail(
table = res.html.find('table') table = res.html.find('table')
assert table assert table
header, *trs = table.findAll('tr') 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')] rows = [[td.text.strip() for td in tr.findAll('td')]
for tr in trs] for tr in trs]

6
templates/crud/list.html

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

Loading…
Cancel
Save