ORM, ir_*: convert standard constraint messages to callables
Also, fix way that callable constraints are passed with the context so that they can have translatable strings inside (but not on the results of the callable). Conflicts: bin/addons/base/ir/ir_model.py bin/addons/base/module/module.py bin/tools/translate.py bzr revid: p_christ@hol.gr-20101118164721-19rgx43d3p96b2lf
This commit is contained in:
parent
1f380f0504
commit
c8f52b8c98
|
@ -151,8 +151,12 @@ class act_window(osv.osv):
|
|||
if action.src_model and not self.pool.get(action.src_model):
|
||||
return False
|
||||
return True
|
||||
|
||||
def _invalid_model_msg(self, cr, uid, ids, context=None):
|
||||
return _('Invalid model name in the action definition.')
|
||||
|
||||
_constraints = [
|
||||
(_check_model, 'Invalid model name in the action definition.', ['res_model','src_model'])
|
||||
(_check_model, _invalid_model_msg, ['res_model','src_model'])
|
||||
]
|
||||
|
||||
def _views_get_fnc(self, cr, uid, ids, name, arg, context={}):
|
||||
|
|
|
@ -88,8 +88,10 @@ class ir_model(osv.osv):
|
|||
return False
|
||||
return True
|
||||
|
||||
def _model_name_msg(self, cr, uid, ids, context=None):
|
||||
return _('The Object name must start with x_ and not contain any special character !')
|
||||
_constraints = [
|
||||
(_check_model_name, 'The Object name must start with x_ and not contain any special character !', ['model']),
|
||||
(_check_model_name, _model_name_msg, ['model']),
|
||||
]
|
||||
|
||||
# overridden to allow searching both on model name (model field)
|
||||
|
@ -181,8 +183,11 @@ class ir_model_fields(osv.osv):
|
|||
'selectable': lambda *a: 1,
|
||||
}
|
||||
_order = "id"
|
||||
def _size_gt_zero_msg(self, cr, user, ids, context=None):
|
||||
return _('Size of the field can never be less than 1 !')
|
||||
|
||||
_sql_constraints = [
|
||||
('size_gt_zero', 'CHECK (size>0)', 'Size of the field can never be less than 1 !'),
|
||||
('size_gt_zero', 'CHECK (size>0)',_size_gt_zero_msg ),
|
||||
]
|
||||
def unlink(self, cr, user, ids, context=None):
|
||||
for field in self.browse(cr, user, ids, context):
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
from osv import fields, osv
|
||||
import re
|
||||
import tools
|
||||
from tools.translate import _
|
||||
|
||||
def one_in(setA, setB):
|
||||
"""Check the presence of an element of setA in setB
|
||||
|
@ -285,8 +286,12 @@ class ir_ui_menu(osv.osv):
|
|||
('ir.actions.server', 'ir.actions.server'),
|
||||
]),
|
||||
}
|
||||
|
||||
def _rec_message(self, cr, uid, ids, context=None):
|
||||
return _('Error ! You can not create recursive Menu.')
|
||||
|
||||
_constraints = [
|
||||
(_check_recursion, 'Error ! You can not create recursive Menu.', ['parent_id'])
|
||||
(_check_recursion, _rec_message , ['parent_id'])
|
||||
]
|
||||
_defaults = {
|
||||
'icon' : lambda *a: 'STOCK_OPEN',
|
||||
|
|
|
@ -187,9 +187,14 @@ class module(osv.osv):
|
|||
}
|
||||
_order = 'name'
|
||||
|
||||
def _name_uniq_msg(self, cr, uid, ids, context=None):
|
||||
return _('The name of the module must be unique !')
|
||||
def _certificate_uniq_msg(self, cr, uid, ids, context=None):
|
||||
return _('The certificate ID of the module must be unique !')
|
||||
|
||||
_sql_constraints = [
|
||||
('name_uniq', 'unique (name)', 'The name of the module must be unique !'),
|
||||
('certificate_uniq', 'unique (certificate)', 'The certificate ID of the module must be unique !')
|
||||
('name_uniq', 'UNIQUE (name)',_name_uniq_msg ),
|
||||
('certificate_uniq', 'UNIQUE (certificate)',_certificate_uniq_msg )
|
||||
]
|
||||
|
||||
def unlink(self, cr, uid, ids, context=None):
|
||||
|
|
|
@ -1053,9 +1053,14 @@ class orm_template(object):
|
|||
# Check presence of __call__ directly instead of using
|
||||
# callable() because it will be deprecated as of Python 3.0
|
||||
if hasattr(msg, '__call__'):
|
||||
txt_msg, params = msg(self, cr, uid, ids)
|
||||
tmp_msg = trans._get_source(cr, uid, self._name, 'constraint', lng, source=txt_msg) or txt_msg
|
||||
translated_msg = tmp_msg % params
|
||||
tmp_msg = msg(self, cr, uid, ids, context=context)
|
||||
# Why translate something that has been generated dynamically?
|
||||
# tmp_msg = trans._get_source(cr, uid, self._name, 'constraint', lng, source=txt_msg) or txt_msg
|
||||
if isinstance(tmp_msg, tuple):
|
||||
tmp_msg, params = tmp_msg
|
||||
translated_msg = tmp_msg % params
|
||||
else:
|
||||
translated_msg = tmp_msg
|
||||
else:
|
||||
translated_msg = trans._get_source(cr, uid, self._name, 'constraint', lng, source=msg) or msg
|
||||
error_msgs.append(
|
||||
|
|
Loading…
Reference in New Issue