[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
This commit is contained in:
committed by
Xavier Morel
parent
691254cbfe
commit
f0cefa7232
@@ -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', '!=', [])] }"/>
|
||||
|
||||
@@ -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"/>
|
||||
|
||||
@@ -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>
|
||||
</openerp>
|
||||
|
||||
@@ -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.
|
||||
|
||||
|
||||
@@ -35,7 +35,6 @@ Base methods requirement
|
||||
|
||||
* ``__getattr__``
|
||||
* ``dict.get``
|
||||
* ``__len__``
|
||||
|
||||
In datamodel, not implemented in any type, untested
|
||||
***************************************************
|
||||
|
||||
@@ -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__();
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user