summaryrefslogtreecommitdiff
path: root/bin/wizard/__init__.py
diff options
context:
space:
mode:
authorChristophe Simonis <christophe@tinyerp.com>2008-07-22 16:24:36 +0200
committerChristophe Simonis <christophe@tinyerp.com>2008-07-22 16:24:36 +0200
commit2dd9723b8b3d38df8c8962300ab67afffa5cdaaa (patch)
tree13dbea91b265af5ad775af16efcdef4ae6ef962c /bin/wizard/__init__.py
parentc5c7c2ef07b346b72eb5a48d6e8cc7a433fba2e8 (diff)
convert tabs to 4 spaces
bzr revid: christophe@tinyerp.com-20080722142436-143iu4ryy47w3av0
Diffstat (limited to 'bin/wizard/__init__.py')
-rw-r--r--bin/wizard/__init__.py248
1 files changed, 124 insertions, 124 deletions
diff --git a/bin/wizard/__init__.py b/bin/wizard/__init__.py
index 10e57e93585..adeaee803d0 100644
--- a/bin/wizard/__init__.py
+++ b/bin/wizard/__init__.py
@@ -41,138 +41,138 @@ from netsvc import Logger, LOG_ERROR
import sys
class except_wizard(Exception):
- def __init__(self, name, value):
- self.name = name
- self.value = value
- self.args = (name, value)
+ def __init__(self, name, value):
+ self.name = name
+ self.value = value
+ self.args = (name, value)
class interface(netsvc.Service):
- states = {}
-
- def __init__(self, name):
- assert not netsvc.service_exist('wizard.'+name), 'The wizard "%s" already exists!'%name
- super(interface, self).__init__('wizard.'+name)
- self.exportMethod(self.execute)
- self.wiz_name = name
-
- def translate_view(self, cr, node, state, lang):
- if node.nodeType == node.ELEMENT_NODE:
- if node.hasAttribute('string') and node.getAttribute('string'):
- trans = translate(cr, self.wiz_name+','+state, 'wizard_view', lang, node.getAttribute('string').encode('utf8'))
- if trans:
- node.setAttribute('string', trans.decode('utf8'))
- for n in node.childNodes:
- self.translate_view(cr, n, state, lang)
+ states = {}
+
+ def __init__(self, name):
+ assert not netsvc.service_exist('wizard.'+name), 'The wizard "%s" already exists!'%name
+ super(interface, self).__init__('wizard.'+name)
+ self.exportMethod(self.execute)
+ self.wiz_name = name
+
+ def translate_view(self, cr, node, state, lang):
+ if node.nodeType == node.ELEMENT_NODE:
+ if node.hasAttribute('string') and node.getAttribute('string'):
+ trans = translate(cr, self.wiz_name+','+state, 'wizard_view', lang, node.getAttribute('string').encode('utf8'))
+ if trans:
+ node.setAttribute('string', trans.decode('utf8'))
+ for n in node.childNodes:
+ self.translate_view(cr, n, state, lang)
- def execute_cr(self, cr, uid, data, state='init', context=None):
- if not context:
- context={}
- res = {}
- try:
- state_def = self.states[state]
- result_def = state_def.get('result', {})
-
- actions_res = {}
- # iterate through the list of actions defined for this state
- for action in state_def.get('actions', []):
- # execute them
- action_res = action(self, cr, uid, data, context)
- assert isinstance(action_res, dict), 'The return value of wizard actions should be a dictionary'
- actions_res.update(action_res)
-
- res = copy.copy(result_def)
- res['datas'] = actions_res
-
- lang = context.get('lang', False)
- if result_def['type'] == 'action':
- res['action'] = result_def['action'](self, cr, uid, data, context)
- elif result_def['type'] == 'form':
- fields = copy.copy(result_def['fields'])
- arch = copy.copy(result_def['arch'])
- button_list = copy.copy(result_def['state'])
+ def execute_cr(self, cr, uid, data, state='init', context=None):
+ if not context:
+ context={}
+ res = {}
+ try:
+ state_def = self.states[state]
+ result_def = state_def.get('result', {})
+
+ actions_res = {}
+ # iterate through the list of actions defined for this state
+ for action in state_def.get('actions', []):
+ # execute them
+ action_res = action(self, cr, uid, data, context)
+ assert isinstance(action_res, dict), 'The return value of wizard actions should be a dictionary'
+ actions_res.update(action_res)
+
+ res = copy.copy(result_def)
+ res['datas'] = actions_res
+
+ lang = context.get('lang', False)
+ if result_def['type'] == 'action':
+ res['action'] = result_def['action'](self, cr, uid, data, context)
+ elif result_def['type'] == 'form':
+ fields = copy.copy(result_def['fields'])
+ 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
+ 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])
- for val in fields.keys():
- if 'default' in fields[val]:
- # execute default method for this field
- if callable(fields[val]['default']):
- fields[val]['value'] = fields[val]['default'](uid, data, state)
- else:
- fields[val]['value'] = fields[val]['default']
- del fields[val]['default']
- else:
- # if user has set a default value for the field, use it
- if val in default_values:
- fields[val]['value'] = default_values[val]
- if 'selection' in fields[val]:
- if not isinstance(fields[val]['selection'], (tuple, list)):
- fields[val] = copy.copy(fields[val])
- fields[val]['selection'] = fields[val]['selection'](self, cr, uid, context)
+ # 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])
+ for val in fields.keys():
+ if 'default' in fields[val]:
+ # execute default method for this field
+ if callable(fields[val]['default']):
+ fields[val]['value'] = fields[val]['default'](uid, data, state)
+ else:
+ fields[val]['value'] = fields[val]['default']
+ del fields[val]['default']
+ else:
+ # if user has set a default value for the field, use it
+ if val in default_values:
+ fields[val]['value'] = default_values[val]
+ if 'selection' in fields[val]:
+ if not isinstance(fields[val]['selection'], (tuple, list)):
+ fields[val] = copy.copy(fields[val])
+ fields[val]['selection'] = fields[val]['selection'](self, cr, uid, context)
- if lang:
- # translate fields
- for field in fields:
- trans = translate(cr, self.wiz_name+','+state+','+field, 'wizard_field', lang)
- if trans:
- fields[field]['string'] = trans
+ if lang:
+ # translate fields
+ for field in fields:
+ trans = translate(cr, self.wiz_name+','+state+','+field, 'wizard_field', lang)
+ if trans:
+ fields[field]['string'] = trans
- # translate arch
- if not isinstance(arch, UpdateableStr):
- doc = dom.minidom.parseString(arch)
- self.translate_view(cr, doc, state, lang)
- arch = doc.toxml()
+ # translate arch
+ if not isinstance(arch, UpdateableStr):
+ doc = dom.minidom.parseString(arch)
+ self.translate_view(cr, doc, state, lang)
+ arch = doc.toxml()
- # translate buttons
- button_list = list(button_list)
- for i, aa in enumerate(button_list):
- button_name = aa[0]
- trans = translate(cr, self.wiz_name+','+state+','+button_name, 'wizard_button', lang)
- if trans:
- aa = list(aa)
- aa[1] = trans
- button_list[i] = aa
-
- res['fields'] = fields
- res['arch'] = arch
- res['state'] = button_list
+ # translate buttons
+ button_list = list(button_list)
+ for i, aa in enumerate(button_list):
+ button_name = aa[0]
+ trans = translate(cr, self.wiz_name+','+state+','+button_name, 'wizard_button', lang)
+ if trans:
+ aa = list(aa)
+ aa[1] = trans
+ button_list[i] = aa
+
+ res['fields'] = fields
+ res['arch'] = arch
+ res['state'] = button_list
- except Exception, e:
- if isinstance(e, except_wizard) \
- or isinstance(e, except_osv) \
- or isinstance(e, except_orm):
- self.abortResponse(2, e.name, 'warning', e.value)
- else:
- import traceback
- tb_s = reduce(lambda x, y: x+y, traceback.format_exception(
- sys.exc_type, sys.exc_value, sys.exc_traceback))
- logger = Logger()
- logger.notifyChannel("web-services", LOG_ERROR,
- 'Exception in call: ' + tb_s)
- raise
+ except Exception, e:
+ if isinstance(e, except_wizard) \
+ or isinstance(e, except_osv) \
+ or isinstance(e, except_orm):
+ self.abortResponse(2, e.name, 'warning', e.value)
+ else:
+ import traceback
+ tb_s = reduce(lambda x, y: x+y, traceback.format_exception(
+ sys.exc_type, sys.exc_value, sys.exc_traceback))
+ logger = Logger()
+ logger.notifyChannel("web-services", LOG_ERROR,
+ 'Exception in call: ' + tb_s)
+ raise
- if result_def['type'] == 'choice':
- next_state = result_def['next_state'](self, cr, uid, data, context)
- return self.execute_cr(cr, uid, data, next_state, context)
- return res
+ if result_def['type'] == 'choice':
+ next_state = result_def['next_state'](self, cr, uid, data, context)
+ return self.execute_cr(cr, uid, data, next_state, context)
+ return res
- def execute(self, db, uid, data, state='init', context=None):
- if not context:
- context={}
- cr = pooler.get_db(db).cursor()
- try:
- try:
- res = self.execute_cr(cr, uid, data, state, context)
- cr.commit()
- except Exception:
- cr.rollback()
- raise
- finally:
- cr.close()
- return res
+ def execute(self, db, uid, data, state='init', context=None):
+ if not context:
+ context={}
+ cr = pooler.get_db(db).cursor()
+ try:
+ try:
+ res = self.execute_cr(cr, uid, data, state, context)
+ cr.commit()
+ except Exception:
+ cr.rollback()
+ raise
+ finally:
+ cr.close()
+ return res