Add straight values to wizard state view
issue11703 review431591006
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
* Add straight values to wizard state view
|
||||
* Add strip option to Char fields
|
||||
* Strip only one wildcard
|
||||
* Manage web extension origin as null
|
||||
|
||||
+18
-1
@@ -116,8 +116,15 @@ StateView
|
||||
|
||||
The form is defined by the :class:`~trytond.model.ModelView` with the name
|
||||
``model_name``, the ``XML`` id in ``view`` and the ``buttons``.
|
||||
The default value of the view can be set with a method on wizard having the
|
||||
The default values of the view can be set with a method on wizard having the
|
||||
same name as the state but starting with ``default_``.
|
||||
The values of the view can be also set with a method on wizard having the
|
||||
same name as the state but starting with ``value_``.
|
||||
|
||||
.. note::
|
||||
The difference between default values and values is that the client calls
|
||||
:meth:`~trytond.model.Model.on_change` and
|
||||
:meth:`~trytond.model.Model.on_change_with` for the default values.
|
||||
|
||||
Instance attributes are:
|
||||
|
||||
@@ -154,6 +161,16 @@ Instance methods are:
|
||||
|
||||
``fields`` is the list of field names.
|
||||
|
||||
.. method:: StateView.get_values(wizard, state_name, fields)
|
||||
|
||||
Return values for the fields.
|
||||
|
||||
``wizard`` is a :class:`Wizard` instance.
|
||||
|
||||
``state_name`` is the name of the :class:`State`.
|
||||
|
||||
``fields`` is the list of field names.
|
||||
|
||||
.. method:: StateView.get_buttons(wizard, state_name)
|
||||
|
||||
Return button definitions of the wizard.
|
||||
|
||||
+29
-12
@@ -93,18 +93,32 @@ class StateView(State):
|
||||
default = getattr(wizard, 'default_%s' % state_name, None)
|
||||
if default:
|
||||
defaults.update(default(fields))
|
||||
for field_name, value in list(defaults.items()):
|
||||
if '.' in field_name:
|
||||
continue
|
||||
field = Model_._fields[field_name]
|
||||
if value and field._type == 'many2one':
|
||||
Target = pool.get(field.model_name)
|
||||
if 'rec_name' in Target._fields:
|
||||
defaults.setdefault(
|
||||
field_name + '.', {})['rec_name'] = Target(
|
||||
value).rec_name
|
||||
self._complete_values(defaults)
|
||||
return defaults
|
||||
|
||||
def get_values(self, wizard, state_name, fields):
|
||||
"Return values for the fields"
|
||||
values = {}
|
||||
value = getattr(wizard, 'value_%s' % state_name, None)
|
||||
if value:
|
||||
values.update(value(fields))
|
||||
self._complete_values(values)
|
||||
return values
|
||||
|
||||
def _complete_values(self, values):
|
||||
pool = Pool()
|
||||
Model_ = pool.get(self.model_name)
|
||||
for field_name, value in list(values.items()):
|
||||
if '.' in field_name:
|
||||
continue
|
||||
field = Model_._fields[field_name]
|
||||
if value and field._type == 'many2one':
|
||||
Target = field.get_target()
|
||||
if 'rec_name' in Target._fields:
|
||||
values.setdefault(
|
||||
field_name + '.', {})['rec_name'] = Target(
|
||||
value).rec_name
|
||||
|
||||
def get_buttons(self, wizard, state_name):
|
||||
'''
|
||||
Returns button definitions translated
|
||||
@@ -300,6 +314,7 @@ class Wizard(URLMixin, PoolBase):
|
||||
- ``view``: a dictionary with:
|
||||
- ``fields_view``: a fields/view definition
|
||||
- ``defaults``: a dictionary with default values
|
||||
- ``values``: a dictionary with values
|
||||
- ``buttons``: a list of buttons
|
||||
'''
|
||||
cls.check_access()
|
||||
@@ -321,12 +336,14 @@ class Wizard(URLMixin, PoolBase):
|
||||
|
||||
if isinstance(state, StateView):
|
||||
view = state.get_view(self, state_name)
|
||||
defaults = state.get_defaults(self, state_name,
|
||||
list(view['fields'].keys()))
|
||||
fields = list(view['fields'].keys())
|
||||
defaults = state.get_defaults(self, state_name, fields)
|
||||
values = state.get_values(self, state_name, fields)
|
||||
buttons = state.get_buttons(self, state_name)
|
||||
result['view'] = {
|
||||
'fields_view': view,
|
||||
'defaults': defaults,
|
||||
'values': values,
|
||||
'buttons': buttons,
|
||||
'state': state_name,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user