[ADD] row-wise colors
bzr revid: xmo@openerp.com-20110411125450-3h0ay8fskd1s6nz5
This commit is contained in:
parent
911369822a
commit
5fc7311f1a
|
@ -566,10 +566,36 @@ class ListView(View):
|
|||
rows = DataSet().do_search_read(request, model,
|
||||
offset=offset, limit=limit,
|
||||
domain=domain)
|
||||
# rows pipe
|
||||
# process_attrs
|
||||
# process_colors
|
||||
return rows
|
||||
eval_context = request.session.evaluation_context(
|
||||
request.context)
|
||||
return [
|
||||
{'data': row,
|
||||
'attrs': self.process_attrs(view, row, eval_context),
|
||||
'color': self.process_colors(view, row, eval_context)}
|
||||
for row in rows
|
||||
]
|
||||
|
||||
def process_attrs(self, view, row, context):
|
||||
pass
|
||||
|
||||
def process_colors(self, view, row, context):
|
||||
colors = view['arch']['attrs'].get('colors')
|
||||
|
||||
if not colors:
|
||||
return None
|
||||
|
||||
color = [
|
||||
pair.split(':')[0]
|
||||
for pair in colors.split(';')
|
||||
if eval(pair.split(':')[1], dict(context, **row))
|
||||
]
|
||||
|
||||
if not color:
|
||||
return None
|
||||
elif len(color) == 1:
|
||||
return color[0]
|
||||
return 'maroon'
|
||||
|
||||
|
||||
class SearchView(View):
|
||||
_cp_path = "/base/searchview"
|
||||
|
|
|
@ -197,9 +197,14 @@
|
|||
</thead>
|
||||
</t>
|
||||
<t t-name="ListView.rows" t-foreach="rows" t-as="row">
|
||||
<t t-call="ListView.row"/>
|
||||
<t t-call="ListView.row">
|
||||
<t t-set="style" t-value="null"/>
|
||||
<t-if test="row.color">
|
||||
<t t-set="style" t-value="'color: ' + row.color"/>
|
||||
</t-if>
|
||||
</t>
|
||||
</t>
|
||||
<tr t-name="ListView.row">
|
||||
<tr t-name="ListView.row" t-att-style="style">
|
||||
<th t-if="options.selectable" class="oe-record-selector">
|
||||
<input type="checkbox"/>
|
||||
</th>
|
||||
|
@ -208,8 +213,8 @@
|
|||
<td t-if="column.invisible !== '1'" t-att-title="column.help">
|
||||
<t t-set="is_button" t-value="column.tag === 'button'"/>
|
||||
<!-- TODO: get correct widget from form -->
|
||||
<t t-if="!is_button and row[column.id]">
|
||||
<t t-esc="row[column.id]"/>
|
||||
<t t-if="!is_button and row['data'][column.id]">
|
||||
<t t-esc="row['data'][column.id]"/>
|
||||
</t>
|
||||
<button type="button" t-att-title="column.help"
|
||||
t-if="is_button">
|
||||
|
|
|
@ -205,3 +205,36 @@ class ListViewTest(unittest2.TestCase):
|
|||
|
||||
self.assertEqual(view['arch']['attrs']['editable'],
|
||||
'bottom')
|
||||
|
||||
def test_color_nocolor(self):
|
||||
self.assertEqual(
|
||||
self.view.process_colors(
|
||||
{'arch': {'attrs': {}, 'children': []}}, {}, {}),
|
||||
None)
|
||||
def test_color_literal(self):
|
||||
self.assertEqual(
|
||||
self.view.process_colors(
|
||||
{'arch': {'attrs': {'colors': 'black:1'}}, 'children': []},
|
||||
{}, {}),
|
||||
'black')
|
||||
def test_color_miss(self):
|
||||
self.assertEqual(
|
||||
self.view.process_colors(
|
||||
{'arch': {'attrs': {'colors': "grey:state in ('cancelled','done');blue:state in ('pending')"}},
|
||||
'children': []
|
||||
}, {'state': 'open'}, {}),
|
||||
None)
|
||||
def test_color_compute(self):
|
||||
self.assertEqual(
|
||||
self.view.process_colors(
|
||||
{'arch': {'attrs': {'colors': "grey:state in ('cancelled','done');blue:state in ('pending')"}},
|
||||
'children': []
|
||||
}, {'state': 'done'}, {}),
|
||||
'grey')
|
||||
def test_color_multiple(self):
|
||||
self.assertEqual(
|
||||
self.view.process_colors(
|
||||
{'arch': {'attrs': {'colors': "grey:state in ('cancelled','done');blue:state in ('done')"}},
|
||||
'children': []
|
||||
}, {'state': 'done'}, {}),
|
||||
'maroon')
|
||||
|
|
Loading…
Reference in New Issue