398 """Sets an object attribute or relationship.
400 This method overrides the default setattr method, so it can apply
401 existence and type verification on class attributes. If the attribute
402 to be set starts with '__', or the passed value is None,
403 no verification is performed. If the value to set an attribute is a
404 list, the type verification is performed in every component of that
407 N.B.: This method takes a reference to the object being passed. It does
408 not copy the value, so, if you do a.b = c, and then you apply changes
409 to 'c', these changes will be also applied to 'a.b'.
413 par -- The name of the parameter (attribute or relationship)
415 val -- The value that will be attributed to 'par'.
417 Raises AttributeError if the parameter does not exist.
419 Raises ValueError if the value you passed cannot be coerced to a
420 compatible OKS python type for the attribute or relationship you are
423 from .schema
import coerce, check_relation, check_cardinality
424 from .
import dalproperty
428 self.__dict__[par] = val
433 if isinstance(val, str):
435 prop.__set__(self, val)
440 'The "id" attribute of a DAL object must be a string')
442 if par
in list(self.__schema__[
'attribute'].keys()):
446 self.__dict__[par] = val
450 check_cardinality(val, self.__schema__[
'attribute'][par])
451 if self.__schema__[
'attribute'][par][
'multivalue']:
453 [coerce(v, self.__schema__[
'attribute'][par])
456 result = coerce(val, self.__schema__[
'attribute'][par])
463 except AttributeError:
465 prop = property(dalproperty._return_attribute(par),
466 dalproperty._assign_attribute(par))
469 prop.__set__(self, result)
471 except ValueError
as e:
472 raise ValueError(
'Problems setting attribute "%s" '
476 elif par
in list(self.__schema__[
'relation'].keys()):
481 check_cardinality(val, self.__schema__[
'relation'][par])
484 val
if self.__schema__[
485 'relation'][par][
'multivalue']
else [val]
487 check_relation(v, self.__schema__[
'relation'][par])
492 except AttributeError:
494 multi = self.__schema__[
'relation'][par][
'multivalue']
496 dalproperty._return_relation(par, multi=multi),
497 dalproperty._assign_relation(par))
500 prop.__set__(self, val)
503 except ValueError
as e:
504 raise ValueError(
'Problems setting relation "%s" at '
509 raise AttributeError(
'Parameter "%s" is not ' % par +
510 'part of class "%s" or any of its '