def _check_name(self): for field in self: # if field.state == 'manual' and not field.name.startswith('x_'): # raise ValidationError(_("Custom fields must have a name that starts with 'x_' !")) try: models.check_pg_name(field.name) except ValidationError: msg = _( "Field names can only contain characters, digits and underscores (up to 63)." ) raise ValidationError(msg)
def _check_name(self): for field in self: if field.state == "manual": if (not field.model_id.m2o_module and not field.name.startswith("x_")): raise ValidationError( _("Custom fields must have a name that starts with" " 'x_' !")) try: models.check_pg_name(field.name) except ValidationError: msg = _("Field names can only contain characters, digits and" " underscores (up to 63).") raise ValidationError(msg)
def _build_model_new(cls, pool, cr): """ Instantiate a given model in the registry. This method creates or extends a "registry" class for the given model. This "registry" class carries inferred model metadata, and inherits (in the Python sense) from all classes that define the model, and possibly other registry classes. """ # Keep links to non-inherited constraints in cls; this is useful for # instance when exporting translations cls._local_constraints = cls.__dict__.get('_constraints', []) cls._local_sql_constraints = cls.__dict__.get('_sql_constraints', []) # determine inherited models parents = inherit_workflow_manager(cr, cls) parents = [parents] if isinstance(parents, str) else (parents or []) # determine the model's name name = cls._name or (len(parents) == 1 and parents[0]) or cls.__name__ # all models except 'base' implicitly inherit from 'base' if name != 'base': parents = list(parents) + ['base'] # create or retrieve the model's class if name in parents: if name not in pool: raise TypeError("Model %r does not exist in registry." % name) ModelClass = pool[name] ModelClass._build_model_check_base(cls) check_parent = ModelClass._build_model_check_parent else: ModelClass = type( name, (BaseModel, ), { '_name': name, '_register': False, '_original_module': cls._module, '_inherit_children': OrderedSet(), # names of children models '_inherits_children': set(), # names of children models '_fields': {}, # populated in _setup_base() }) check_parent = cls._build_model_check_parent # determine all the classes the model should inherit from bases = LastOrderedSet([cls]) for parent in parents: if parent not in pool: raise TypeError("Model %r inherits from non-existing model %r." % (name, parent)) parent_class = pool[parent] if parent == name: for base in parent_class.__bases__: bases.add(base) else: check_parent(cls, parent_class) bases.add(parent_class) parent_class._inherit_children.add(name) ModelClass.__bases__ = tuple(bases) # determine the attributes of the model's class ModelClass._build_model_attributes(pool) check_pg_name(ModelClass._table) # Transience if ModelClass._transient: assert ModelClass._log_access, \ "TransientModels must have log_access turned on, " \ "in order to implement their access rights policy" # link the class to the registry, and update the registry ModelClass.pool = pool pool[name] = ModelClass # backward compatibility: instantiate the model, and initialize it model = object.__new__(ModelClass) model.__init__(pool, cr) return ModelClass