Browse Source

IMP description, size param and check_vals

pull/246/head
eLBati 9 years ago
parent
commit
4ecfa97846
  1. 1
      base_field_validator/README.rst
  2. 2
      base_field_validator/__openerp__.py
  3. 20
      base_field_validator/ir_model.py
  4. 4
      base_field_validator/ir_model_field_regex.py

1
base_field_validator/README.rst

@ -3,6 +3,7 @@
:alt: License: AGPL-3
================
Fields Validator
================

2
base_field_validator/__openerp__.py

@ -23,7 +23,7 @@
'version': '0.1',
'category': 'Tools',
'summary': "Validate fields using regular expressions",
'author': 'Agile Business Group',
'author': 'Agile Business Group, Odoo Community Association (OCA)',
'website': 'http://www.agilebg.com',
'license': 'AGPL-3',
"depends": ['base'],

20
base_field_validator/ir_model.py

@ -36,16 +36,16 @@ class IrModel(models.Model):
@api.model
def check_vals(self, vals, model_name):
models = self.search([('model', '=', model_name)])
for model in models:
for validator_line in model.validator_line_ids:
if validator_line.field_id.name in vals:
pattern = re.compile(validator_line.regex_id.regex)
if not pattern.match(vals[validator_line.field_id.name]):
raise Warning(
_('Expression %s not valid for %s') % (
validator_line.regex_id.regex,
vals[validator_line.field_id.name]))
models = self.search([('model', '=', model_name)], limit=1)
model = models[0]
for validator_line in model.validator_line_ids:
if validator_line.field_id.name in vals:
pattern = re.compile(validator_line.regex_id.regex)
if not pattern.match(vals[validator_line.field_id.name]):
raise Warning(
_('Expression %s not valid for %s') % (
validator_line.regex_id.regex,
vals[validator_line.field_id.name]))
return True

4
base_field_validator/ir_model_field_regex.py

@ -23,9 +23,9 @@ from openerp import models, fields
class IrModelFieldsRegex(models.Model):
_name = "ir.model.fields.regex"
name = fields.Char('Description', size=512, required=True)
name = fields.Char('Description', required=True)
regex = fields.Char(
'Regular Expression', size=512, required=True,
'Regular Expression', required=True,
help="Regular expression used to validate the field. For example, "
"you can add the expression\n%s\nto the email field"
% r'\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b')
Loading…
Cancel
Save