Add Len to PYSON
issue3692 review3671002
This commit is contained in:
1 parent
e9f9dc5620
commit
c6f380ce17
2 files changed
+27
No files matched your search
@@ -1,3 +1,4 @@
|
||||
* Add Len to PYSON
|
||||
* Use a pool of connection
|
||||
* Manage client actions from button and wizard
|
||||
* Add tree_invisible attribute to button in tree view
|
||||
|
||||
@@ -537,6 +537,31 @@ class DateTime(Date):
|
||||
)
|
||||
|
||||
|
||||
class Len(PYSON):
|
||||
|
||||
def __init__(self, value):
|
||||
super(Len, self).__init__()
|
||||
if isinstance(value, PYSON):
|
||||
assert value.types().issubset(set([dict, list, str])), \
|
||||
'value must be a dict or a list or a string'
|
||||
else:
|
||||
assert type(value) in [dict, list, str], \
|
||||
'value must be a dict or list or a string'
|
||||
self._value = value
|
||||
|
||||
def pyson(self):
|
||||
return {
|
||||
'__class__': 'Len',
|
||||
'v': self._value,
|
||||
}
|
||||
|
||||
def types(self):
|
||||
return set([int, long])
|
||||
|
||||
@staticmethod
|
||||
def eval(dct, context):
|
||||
return len(dct['v'])
|
||||
|
||||
CONTEXT = {
|
||||
'Eval': Eval,
|
||||
'Not': Not,
|
||||
@@ -551,4 +576,5 @@ CONTEXT = {
|
||||
'In': In,
|
||||
'Date': Date,
|
||||
'DateTime': DateTime,
|
||||
'Len': Len,
|
||||
}
|
||||
Reference in new issue
Block a user