Add pre-validation
review536002
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
* Add pre-validation
|
||||
* Allow to use XML file for views
|
||||
* Add RPC definition
|
||||
* Repace BrowseRecord by Model instance
|
||||
|
||||
@@ -98,6 +98,12 @@ Class methods:
|
||||
|
||||
Return the definition of each field on the model.
|
||||
|
||||
Instance methods:
|
||||
|
||||
.. method:: Model.pre_validate()
|
||||
|
||||
This method is called by the client to validate the instance.
|
||||
|
||||
=========
|
||||
ModelView
|
||||
=========
|
||||
|
||||
@@ -118,6 +118,13 @@ List of attributes shared by many form elements:
|
||||
* ``help``: The string that will be displayed when the cursor hovers over
|
||||
the widget.
|
||||
|
||||
.. _common-attributes-pre_validate:
|
||||
|
||||
* ``pre_validate``: A boolean only for fields
|
||||
:class:`trytond.model.fields.One2Many` to specify if the client must
|
||||
pre-validate the records using
|
||||
:meth:`trytond.model.Model.pre_validate`.
|
||||
|
||||
|
||||
form
|
||||
^^^^
|
||||
@@ -216,6 +223,8 @@ Display a field of the object with the value of the current record.
|
||||
|
||||
* ``help``: see in common-attributes-help_.
|
||||
|
||||
* ``pre_validate``: see in common-attributes-pre_validate_.
|
||||
|
||||
image
|
||||
^^^^^
|
||||
|
||||
@@ -471,6 +480,8 @@ field
|
||||
columns that have their "expand" property set to True. Resize don't work
|
||||
if this option is enabled.
|
||||
|
||||
* ``pre_validate``: see in common-attributes-pre_validate_.
|
||||
|
||||
Example
|
||||
-------
|
||||
|
||||
|
||||
@@ -101,6 +101,7 @@ attlist.field &= attribute img_width { text }?
|
||||
attlist.field &= attribute img_height { text }?
|
||||
attlist.field &=
|
||||
[a:defaultValue = "0"] attribute filename_visible { "0" | "1" }?
|
||||
attlist.field &= [a:defaultValue = "0"] attribute pre_validate { "0" | "1" }?
|
||||
image = element image { attlist.image, empty }
|
||||
attlist.image &= attribute name { text }
|
||||
attlist.image &= [ a:defaultValue = "1" ] attribute colspan { text }?
|
||||
|
||||
@@ -354,6 +354,16 @@
|
||||
</attribute>
|
||||
</optional>
|
||||
</define>
|
||||
<define name="attlist.field" combine="interleave">
|
||||
<optional>
|
||||
<attribute name="pre_validate" a:defaultValue="0">
|
||||
<choice>
|
||||
<value>0</value>
|
||||
<value>1</value>
|
||||
</choice>
|
||||
</attribute>
|
||||
</optional>
|
||||
</define>
|
||||
<define name="image">
|
||||
<element name="image">
|
||||
<ref name="attlist.image"/>
|
||||
|
||||
@@ -50,6 +50,7 @@ attlist.field &=
|
||||
| "top_to_bottom"
|
||||
}?
|
||||
attlist.field &= attribute float_time { text }?
|
||||
attlist.field &= [a:defaultValue = "0"] attribute pre_validate { "0" | "1" }?
|
||||
button = element button { attlist.button, empty }
|
||||
attlist.button &= attribute help { text }?
|
||||
attlist.button &=
|
||||
|
||||
@@ -147,6 +147,16 @@
|
||||
<attribute name="float_time"/>
|
||||
</optional>
|
||||
</define>
|
||||
<define name="attlist.field" combine="interleave">
|
||||
<optional>
|
||||
<attribute name="pre_validate" a:defaultValue="0">
|
||||
<choice>
|
||||
<value>0</value>
|
||||
<value>1</value>
|
||||
</choice>
|
||||
</attribute>
|
||||
</optional>
|
||||
</define>
|
||||
<define name="button">
|
||||
<element name="button">
|
||||
<ref name="attlist.button"/>
|
||||
|
||||
@@ -53,6 +53,7 @@ class Model(WarningErrorMixin, URLMixin):
|
||||
'default_get': RPC(),
|
||||
'fields_get': RPC(),
|
||||
'on_change_with': RPC(instantiate=0),
|
||||
'pre_validate': RPC(instantiate=0),
|
||||
}
|
||||
cls._error_messages = {}
|
||||
|
||||
@@ -571,6 +572,9 @@ class Model(WarningErrorMixin, URLMixin):
|
||||
changes[fieldname] = getattr(self, method_name)()
|
||||
return changes
|
||||
|
||||
def pre_validate(self):
|
||||
pass
|
||||
|
||||
def __init__(self, id=None, **kwargs):
|
||||
super(Model, self).__init__()
|
||||
if id is not None:
|
||||
|
||||
@@ -861,6 +861,9 @@ class ModelStorage(Model):
|
||||
with Transaction().set_user(Transaction().context.get('user')):
|
||||
return cls._validate(cls.browse(records))
|
||||
|
||||
for record in records:
|
||||
record.pre_validate()
|
||||
|
||||
def call(name):
|
||||
method = getattr(cls, name)
|
||||
if not hasattr(method, 'im_self') or method.im_self:
|
||||
|
||||
Reference in New Issue
Block a user