Reviewers: ,


Please review this at http://codereview.tryton.org/216001/

Affected files:
  M proteus/__init__.py
  M proteus/tests/test_wizard.py


Index: proteus/__init__.py
===================================================================

--- a/proteus/__init__.py
+++ b/proteus/__init__.py
@@ -650,6 +650,8 @@

     def _default_set(self, values):
         for field, value in values.iteritems():
+            if '.' in field:
+                continue
             definition = self._fields[field]
             if definition['type'] in ('one2many', 'many2many'):
if value and len(value) and isinstance(value[0], (int, long)):
@@ -774,62 +776,53 @@
             assert len(set(type(x) for x in models)) == 1
         super(Wizard, self).__init__()
         self.name = name
-        self.state = None
-        self.states = ['init']
         self.form = None
+        self.form_state = None
         self._config = config or proteus.config.get_config()
         self._context = context or {}
         self._proxy = self._config.get_proxy(name, type='wizard')
-        self.id = self._proxy.create(self._config.context)
-        if models:
-            self.datas = {
-                    'model': models[0].__class__.__name__,
-                    'id': models[0].id,
-                    'ids': [model.id for model in models]
-                    }
-        else:
-            self.datas = {}
-        self.execute('init')
+        result = self._proxy.create(self._config.context)
+        self.session_id, self.start_state, self.end_state = result
+        self.states = [self.start_state]
+        self.models = models
+        self.execute(self.start_state)

     def execute(self, state):
         assert state in self.states

-        if 'form' not in self.datas:
-            self.datas['form'] = {}
-
-        if self.form:
-            self.datas['form'].update(self.form._get_values())
-
         self.state = state
         while self.state != 'end':
             ctx = self._context.copy()
             ctx.update(self._config.context)
-            ctx['active_id'] = self.datas.get('id')
-            ctx['active_ids'] = self.datas.get('ids')
+            if self.models:
+                ctx['active_id'] = self.models[0].id
+                ctx['active_ids'] = [model.id for model in self.models]
+                ctx['active_model'] = self.models[0].__class__.__name__
+            else:
+                ctx['active_id'] = None
+                ctx['active_ids'] = None
+                ctx['active_model'] = None

-            res = self._proxy.execute(self.id, self.datas, self.state, ctx)
-            if not res:
-                break
+            if self.form:
+                data = {self.form_state: self.form._get_eval()}
+            else:
+                data = {}

-            if 'datas' in res:
-                self.datas['form'] = res['datas']
-            elif res['type'] == 'form':
-                self.datas['form'] = {}
+            result = self._proxy.execute(self.session_id, data, self.state,
+                ctx)

-            if res['type'] == 'form':
-                self.states = [x[0] for x in res['state']]
-                # XXX set context
-                self.form = Model.get(res['object'])()
-                self.form._default_set(self.datas['form'])
+            if 'view' in result:
+                view = result['view']
+                self.form = Model.get(view['fields_view']['model'])()
+                self.form._default_set(view['defaults'])
+                self.states = [b['state'] for b in view['buttons']]
+                self.form_state = view['state']
                 return
-            elif res['type'] == 'action':
-                # TODO run action
-                self.state = res['state']
-            elif res['type'] == 'print':
-                # TODO run print
-                self.state = res['state']
-            elif res['type'] == 'state':
-                self.state = res['state']
+            else:
+                self.state = self.end_state

-        if self.state == 'end':
-            self._proxy.delete(self.id, self._config.context)
+            if 'actions' in result:
+                pass  # TODO
+
+        if self.state == self.end_state:
+            self._proxy.delete(self.session_id, self._config.context)

Index: proteus/tests/test_wizard.py
===================================================================

--- a/proteus/tests/test_wizard.py
+++ b/proteus/tests/test_wizard.py
@@ -12,14 +12,18 @@
     def test_translation_clean(self):
         translation_clean = Wizard('ir.translation.clean')
         self.assertEqual(translation_clean.form.__class__.__name__,
-                'ir.translation.clean.init')
-        translation_clean.execute('start')
+                'ir.translation.clean.start')
+        translation_clean.execute('clean')
+        self.assertEqual(translation_clean.form.__class__.__name__,
+            'ir.translation.clean.succeed')

     def test_translation_export(self):
+        Lang = Model.get('ir.lang')
+        Module = Model.get('ir.module.module')
         translation_export = Wizard('ir.translation.export')
-        translation_export.form.lang = 'en_US'
-        translation_export.form.module = 'ir'
-        translation_export.execute('start')
+ translation_export.form.language, = Lang.find([('code', '=', 'en_US')]) + translation_export.form.module, = Module.find([('name', '=', 'ir')])
+        translation_export.execute('export')
         self.assert_(translation_export.form.file)
         translation_export.execute('end')




--
[email protected] mailing list

Reply via email to