From c6f380ce17df039c8aa35d0a5fbb49d3daba241c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Thu, 27 Feb 2014 12:37:47 +0100 Subject: [PATCH] Add Len to PYSON issue3692 review3671002 --- CHANGELOG | 1 + tryton/pyson.py | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index 15ca23ab3f..307ad212db 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -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 diff --git a/tryton/pyson.py b/tryton/pyson.py index 5b7bf46bc0..9f637a5c50 100644 --- a/tryton/pyson.py +++ b/tryton/pyson.py @@ -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, }