~openerp/openobject-server/web-dashboard

« back to all changes in this revision

Viewing changes to bin/osv/orm.py

  • Committer: Olivier Dony
  • Author(s): Quentin De Paoli
  • Date: 2010-05-18 17:00:23 UTC
  • mfrom: (2245.1.1 server)
  • Revision ID: odo@openerp.com-20100518170023-h6t203f3ik8j46vq
[IMP] improved constraints: can now pass a callable message function instead of hardcoded message

Show diffs side-by-side

added added

removed removed

Lines of Context:
1023
1023
        for constraint in self._constraints:
1024
1024
            fun, msg, fields = constraint
1025
1025
            if not fun(self, cr, uid, ids):
1026
 
                translated_msg = trans._get_source(cr, uid, self._name, 'constraint', lng, source=msg) or msg
 
1026
                # Check presence of __call__ directly instead of using
 
1027
                # callable() because it will be deprecated as of Python 3.0
 
1028
                if hasattr(msg, '__call__'):
 
1029
                    txt_msg, params = msg(self, cr, uid, ids)
 
1030
                    tmp_msg = trans._get_source(cr, uid, self._name, 'constraint', lng, source=txt_msg) or txt_msg
 
1031
                    translated_msg = tmp_msg % params
 
1032
                else:
 
1033
                    translated_msg = trans._get_source(cr, uid, self._name, 'constraint', lng, source=msg) or msg
1027
1034
                error_msgs.append(
1028
1035
                        _("Error occurred while validating the field(s) %s: %s") % (','.join(fields), translated_msg)
1029
1036
                )