summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArthur Maniet <arthurmaniet@me.com>2015-02-04 13:45:19 +0100
committerXavier Morel <xmo@odoo.com>2015-02-05 13:08:15 +0100
commitf0cefa72325cabcd2bff1952816a84a380dc6e2f (patch)
tree0d11938b1c0376d6085e234df522d67879dc43db
parent691254cbfe0d4c64762d2d1c2c5e3b0ad2c5423b (diff)
[ADD] py.js: len() and truthiness on lists, tuples and dicts
* use new support to colorize reconciled bank statement lines * fixes tokenization of ``is not`` to not blow up on ``not foo`` * improves calling code to get truthiness of evaluated expression instead of truthiness of javascript-equivalent objects: an empty list is falsy in Python but truthy in javascript, since the evaluated expression is in Python one would expect Python truthiness rules without having to manually convert to boolean closes #5070
-rw-r--r--addons/account/account_view.xml2
-rw-r--r--addons/account_bank_statement_extensions/account_bank_statement_view.xml2
-rw-r--r--addons/l10n_be_coda/l10n_be_coda_view.xml4
-rw-r--r--addons/web/static/lib/py.js/README.rst2
-rw-r--r--addons/web/static/lib/py.js/TODO.rst1
-rw-r--r--addons/web/static/lib/py.js/lib/py.js14
-rw-r--r--addons/web/static/src/js/view_list.js4
-rw-r--r--addons/web/static/src/js/view_tree.js2
8 files changed, 21 insertions, 10 deletions
diff --git a/addons/account/account_view.xml b/addons/account/account_view.xml
index b0dbb55bd51..623fef0662f 100644
--- a/addons/account/account_view.xml
+++ b/addons/account/account_view.xml
@@ -600,7 +600,7 @@
<notebook>
<page string="Transactions" name="statement_line_ids">
<field name="line_ids" context="{'date':date}">
- <tree editable="bottom" string="Statement lines">
+ <tree editable="bottom" string="Statement lines" colors="grey:journal_entry_ids">
<field name="sequence" readonly="1" invisible="1"/>
<field name="journal_entry_ids" invisible="1"/>
<field name="date" attrs="{'readonly' : [('journal_entry_ids', '!=', [])] }"/>
diff --git a/addons/account_bank_statement_extensions/account_bank_statement_view.xml b/addons/account_bank_statement_extensions/account_bank_statement_view.xml
index f0796b4631d..d546c49f6b1 100644
--- a/addons/account_bank_statement_extensions/account_bank_statement_view.xml
+++ b/addons/account_bank_statement_extensions/account_bank_statement_view.xml
@@ -57,7 +57,7 @@
<field name="name">bank.statement.line.list</field>
<field name="model">account.bank.statement.line</field>
<field name="arch" type="xml">
- <tree editable="bottom" string="Statement Lines">
+ <tree editable="bottom" string="Statement Lines" colors="blue:not journal_entry_ids">
<field name="sequence" readonly="1" invisible="1"/>
<field name="journal_id" readonly="1"/>
<field name="date" readonly="1"/>
diff --git a/addons/l10n_be_coda/l10n_be_coda_view.xml b/addons/l10n_be_coda/l10n_be_coda_view.xml
index 6983bc15790..079b63d643b 100644
--- a/addons/l10n_be_coda/l10n_be_coda_view.xml
+++ b/addons/l10n_be_coda/l10n_be_coda_view.xml
@@ -38,7 +38,7 @@
<field name="model">account.bank.statement.line</field>
<field name="priority">10</field>
<field name="arch" type="xml">
- <tree editable="bottom" string="Statement lines" create="0">
+ <tree editable="bottom" string="Statement lines" create="0" colors="blue:not journal_entry_ids">
<field name="sequence" readonly="1" invisible="1"/>
<field name="statement_id" readonly="1" />
<field name="date"/>
@@ -86,4 +86,4 @@
<menuitem name="Bank Statement Lines" parent="account.menu_finance_bank_and_cash" id="menu_account_bank_statement_line_coda" action="action_account_bank_statement_line_coda" sequence="8" groups="base.group_no_one"/>
</data>
-</openerp> \ No newline at end of file
+</openerp>
diff --git a/addons/web/static/lib/py.js/README.rst b/addons/web/static/lib/py.js/README.rst
index 7601318df6d..5380f3e6c8f 100644
--- a/addons/web/static/lib/py.js/README.rst
+++ b/addons/web/static/lib/py.js/README.rst
@@ -53,7 +53,7 @@ Builtins
Same as tuple (``list`` is currently an alias for ``tuple``)
``dict``
- Implements trivial getting and setting, nothing beyond that.
+ Implements trivial getting, setting and len, nothing beyond that.
Note that most methods are probably missing from all of these.
diff --git a/addons/web/static/lib/py.js/TODO.rst b/addons/web/static/lib/py.js/TODO.rst
index a1309bd3fc5..dd3237e3572 100644
--- a/addons/web/static/lib/py.js/TODO.rst
+++ b/addons/web/static/lib/py.js/TODO.rst
@@ -35,7 +35,6 @@ Base methods requirement
* ``__getattr__``
* ``dict.get``
-* ``__len__``
In datamodel, not implemented in any type, untested
***************************************************
diff --git a/addons/web/static/lib/py.js/lib/py.js b/addons/web/static/lib/py.js/lib/py.js
index 2c738dc95d1..2c6c832f9fe 100644
--- a/addons/web/static/lib/py.js/lib/py.js
+++ b/addons/web/static/lib/py.js/lib/py.js
@@ -320,7 +320,7 @@ var py = {};
if (token === 'in' && tokens[tokens.length-1].id === 'not') {
symbol = symbols['not in'];
tokens.pop();
- } else if (token === 'not' && tokens[tokens.length-1].id === 'is') {
+ } else if (token === 'not' && tokens.length > 0 && tokens[tokens.length-1].id === 'is') {
symbol = symbols['is not'];
tokens.pop();
} else {
@@ -969,6 +969,12 @@ var py = {};
__init__: function () {
this._values = [];
},
+ __len__: function () {
+ return this._values.length;
+ },
+ __nonzero__: function () {
+ return py.PY_size(this) > 0 ? py.True : py.False;
+ },
__contains__: function (value) {
for(var i=0, len=this._values.length; i<len; ++i) {
if (py.PY_isTrue(this._values[i].__eq__(value))) {
@@ -1013,6 +1019,12 @@ var py = {};
__setitem__: function (key, value) {
this._store[key.__hash__()] = [key, value];
},
+ __len__: function () {
+ return Object.keys(this._store).length
+ },
+ __nonzero__: function () {
+ return py.PY_size(this) > 0 ? py.True : py.False;
+ },
get: function () {
var args = py.PY_parseArgs(arguments, ['k', ['d', py.None]]);
var h = args.k.__hash__();
diff --git a/addons/web/static/src/js/view_list.js b/addons/web/static/src/js/view_list.js
index 0e446fb323e..135f73d2ce2 100644
--- a/addons/web/static/src/js/view_list.js
+++ b/addons/web/static/src/js/view_list.js
@@ -182,7 +182,7 @@ instance.web.ListView = instance.web.View.extend( /** @lends instance.web.ListVi
pair = this.fonts[i];
var font = pair[0];
expression = pair[1];
- if (py.evaluate(expression, context).toJSON()) {
+ if (py.PY_isTrue(py.evaluate(expression, context))) {
switch(font) {
case 'bold':
style += 'font-weight: bold;';
@@ -203,7 +203,7 @@ instance.web.ListView = instance.web.View.extend( /** @lends instance.web.ListVi
pair = this.colors[i];
var color = pair[0];
expression = pair[1];
- if (py.evaluate(expression, context).toJSON()) {
+ if (py.PY_isTrue(py.evaluate(expression, context))) {
return style += 'color: ' + color + ';';
}
// TODO: handle evaluation errors
diff --git a/addons/web/static/src/js/view_tree.js b/addons/web/static/src/js/view_tree.js
index aac7198f2c3..45cc183511a 100644
--- a/addons/web/static/src/js/view_tree.js
+++ b/addons/web/static/src/js/view_tree.js
@@ -145,7 +145,7 @@ instance.web.TreeView = instance.web.View.extend(/** @lends instance.web.TreeVie
var pair = this.colors[i],
color = pair[0],
expression = pair[1];
- if (py.evaluate(expression, context).toJSON()) {
+ if (py.PY_isTrue(py.evaluate(expression, context))) {
return 'color: ' + color + ';';
}
// TODO: handle evaluation errors