Reviewers: ,


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

Affected files:
  M CHANGELOG
  M doc/ref/models/models.rst
  M doc/topics/views/index.rst
  M trytond/ir/ui/form.rnc
  M trytond/ir/ui/form.rng
  M trytond/ir/ui/tree.rnc
  M trytond/ir/ui/tree.rng
  M trytond/model/model.py
  M trytond/model/modelstorage.py


Index: CHANGELOG
===================================================================

--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,3 +1,4 @@
+* Add pre-validation
 * Add RPC definition
 * Repace BrowseRecord by Model instance
 * Replace Cache decorator by a simple LRU Cache

Index: doc/ref/models/models.rst
===================================================================

--- a/doc/ref/models/models.rst
+++ b/doc/ref/models/models.rst
@@ -98,6 +98,12 @@

     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
 =========

Index: doc/topics/views/index.rst
===================================================================

--- a/doc/topics/views/index.rst
+++ b/doc/topics/views/index.rst
@@ -120,6 +120,13 @@
* ``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
 ^^^^
@@ -218,6 +225,8 @@

     * ``help``: see in common-attributes-help_.

+    * ``pre_validate``: see in common-attributes-pre_validate_.
+
 image
 ^^^^^

@@ -473,6 +482,8 @@
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
 -------


Index: trytond/ir/ui/form.rnc
===================================================================

--- a/trytond/ir/ui/form.rnc
+++ b/trytond/ir/ui/form.rnc
@@ -101,6 +101,7 @@
 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 }?

Index: trytond/ir/ui/form.rng
===================================================================

--- a/trytond/ir/ui/form.rng
+++ b/trytond/ir/ui/form.rng
@@ -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"/>

Index: trytond/ir/ui/tree.rnc
===================================================================

--- a/trytond/ir/ui/tree.rnc
+++ b/trytond/ir/ui/tree.rnc
@@ -50,6 +50,7 @@
     | "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 &=

Index: trytond/ir/ui/tree.rng
===================================================================

--- a/trytond/ir/ui/tree.rng
+++ b/trytond/ir/ui/tree.rng
@@ -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"/>

Index: trytond/model/model.py
===================================================================

--- a/trytond/model/model.py
+++ b/trytond/model/model.py
@@ -53,6 +53,7 @@
             'default_get': RPC(),
             'fields_get': RPC(),
             'on_change_with': RPC(instantiate=0),
+            'pre_validate': RPC(instantiate=0),
             }
         cls._error_messages = {}

@@ -571,6 +572,9 @@
             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:

Index: trytond/model/modelstorage.py
===================================================================

--- a/trytond/model/modelstorage.py
+++ b/trytond/model/modelstorage.py
@@ -873,6 +873,9 @@
             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:



--
[email protected] mailing list

Reply via email to