~openerp-dev/openobject-client-web/6.0-opw-591397-xal

2865 by ame (Tiny)
[REF] separating base API to openobject
1
###############################################################################
2
#
4354 by Fabien Meghazi
[IMP] Replaced Tiny by OpenERP SA in license headers
3
#  Copyright (C) 2007-TODAY OpenERP SA. All Rights Reserved.
4
#
5
#  $Id$
6
#
7
#  Developed by OpenERP (http://openerp.com) and Axelor (http://axelor.com).
8
#
9
#  The OpenERP web client is distributed under the "OpenERP Public License".
10
#  It's based on Mozilla Public License Version (MPL) 1.1 with following 
11
#  restrictions:
12
#
13
#  -   All names, links and logos of OpenERP must be kept as in original
14
#      distribution without any changes in all software screens, especially
15
#      in start-up page and the software header, even if the application
16
#      source code has been changed or updated or code has been added.
17
#
18
#  You can see the MPL licence at: http://www.mozilla.org/MPL/MPL-1.1.html
2865 by ame (Tiny)
[REF] separating base API to openobject
19
#
20
###############################################################################
3330 by Xavier Morel
[IMP] tentative pretty major reorganization of the validators import in order to try and avoid systemic import failures due to a bunch of undebuggable errors related to Python getting lost in the crap.
21
import formencode
22
23
__all__ = ['BaseValidator', 'DefaultValidator', 'Schema']
24
25
class BaseValidator(formencode.api.FancyValidator):
2865 by ame (Tiny)
[REF] separating base API to openobject
26
    pass
27
28
29
class DefaultValidator(BaseValidator):
30
    pass
31
32
3330 by Xavier Morel
[IMP] tentative pretty major reorganization of the validators import in order to try and avoid systemic import failures due to a bunch of undebuggable errors related to Python getting lost in the crap.
33
class Schema(formencode.schema.Schema):
2865 by ame (Tiny)
[REF] separating base API to openobject
34
    """Modified Schema validator.
35
36
    A schema validates a dictionary of values, applying different validators
37
    (by key) to the different values.
38
39
    This modified Schema allows fields that do not appear in the fields
40
    parameter of your schema, but filters them out from the value dictionary.
41
    You might want to set filter_extra_fields to True when you're building a
42
    dynamic form with unpredictable keys and need these values.
43
44
    """
45
46
    filter_extra_fields = True
47
    allow_extra_fields = True
48
    if_key_missing = None
49
50
    def from_python(self, value, state=None):
51
        # The Schema shouldn't do any from_python conversion because
2953.1.2 by Numerigraphe - Lionel Sausin
[REF] wording: "children" intead of "childs"
52
        # adjust_value already takes care of that for all children.
2865 by ame (Tiny)
[REF] separating base API to openobject
53
        return value