From 0955ee2794fa9362a87d93abaa131b4be3d75f11 Mon Sep 17 00:00:00 2001 From: ced <> Date: Thu, 11 Oct 2007 13:56:36 +0000 Subject: [PATCH] Add UpdatableDict for wizard partial picking bzr revid: ced-3ddd65392ce2656864c58a4ccf04a5fa947ce9b5 --- bin/tools/misc.py | 105 ++++++++++++++++++++++++++++++++++++++++- bin/wizard/__init__.py | 10 ++-- 2 files changed, 110 insertions(+), 5 deletions(-) diff --git a/bin/tools/misc.py b/bin/tools/misc.py index 08ec90f4e02..4121406f322 100644 --- a/bin/tools/misc.py +++ b/bin/tools/misc.py @@ -325,8 +325,111 @@ class UpdateableStr(local): def __nonzero__(self): return bool(self.string) + +class UpdateableDict(local): + '''Stores an updateable dict to use in wizards''' + + def __init__(self, dict=None): + if dict is None: + dict = {} + self.dict = dict + + def __str__(self): + return str(self.dict) + + def __repr__(self): + return str(self.dict) + + def clear(self): + return self.dict.clear() + + def keys(self): + return self.dict.keys() + + def __setitem__(self, i, y): + self.dict.__setitem__(i, y) + + def __getitem__(self, i): + return self.dict.__getitem__(i) + + def copy(self): + return self.dict.copy() + + def iteritems(self): + return self.dict.iteritems() + + def iterkeys(self): + return self.dict.iterkeys() + + def itervalues(self): + return self.dict.itervalues() + + def pop(self, k, d=None): + return self.dict.pop(k, d) + + def popitem(self): + return self.dict.popitem() + + def setdefault(self, k, d=None): + return self.dict.setdefault(k, d) + + def update(self, E, **F): + return self.dict.update(E, F) + + def values(self): + return self.dict.values() + + def get(self, k, d=None): + return self.dict.get(k, d) + + def has_key(self, k): + return self.dict.has_key(k) + + def items(self): + return self.dict.items() + + def __cmp__(self, y): + return self.dict.__cmp__(y) + + def __contains__(self, k): + return self.dict.__contains__(k) + + def __delitem__(self, y): + return self.dict.__delitem__(y) + + def __eq__(self, y): + return self.dict.__eq__(y) + + def __ge__(self, y): + return self.dict.__ge__(y) + + def __getitem__(self, y): + return self.dict.__getitem__(y) + + def __gt__(self, y): + return self.dict.__gt__(y) + + def __hash__(self): + return self.dict.__hash__() + + def __iter__(self): + return self.dict.__iter__() + + def __le__(self, y): + return self.dict.__le__(y) + + def __len__(self): + return self.dict.__len__() + + def __lt__(self, y): + return self.dict.__lt__(y) + + def __ne__(self, y): + return self.dict.__ne__(y) + + # Don't use ! Use res.currency.round() -class currency(float): +class currency(float): def __init__(self, value, accuracy=2, rounding=None): if rounding is None: diff --git a/bin/wizard/__init__.py b/bin/wizard/__init__.py index 394f4555b64..c96e8cafd6f 100644 --- a/bin/wizard/__init__.py +++ b/bin/wizard/__init__.py @@ -27,7 +27,7 @@ import netsvc import copy -from tools.misc import UpdateableStr +from tools.misc import UpdateableStr, UpdateableDict from tools.translate import translate from xml import dom @@ -90,6 +90,11 @@ class interface(netsvc.Service): arch = copy.copy(result_def['arch']) button_list = copy.copy(result_def['state']) + if isinstance(fields, UpdateableDict): + fields = fields.dict + if isinstance(arch, UpdateableStr): + arch = arch.string + # fetch user-set defaut values for the field... shouldn't we pass it the uid? defaults = ir.ir_get(cr, uid, 'default', False, [('wizard.'+self.wiz_name, False)]) default_values = dict([(x[1], x[2]) for x in defaults]) @@ -110,9 +115,6 @@ class interface(netsvc.Service): fields[val] = copy.copy(fields[val]) fields[val]['selection'] = fields[val]['selection'](self, cr, uid, context) - if isinstance(arch, UpdateableStr): - arch = arch.string - if lang: # translate fields for field in fields: