|
@@ -45,7 +45,7 @@ class EmComponent(object):
|
45
|
45
|
# @param id_or_name int|str: name or id of the object
|
46
|
46
|
# @throw TypeError if id_or_name is not an integer nor a string
|
47
|
47
|
# @throw NotImplementedError if called with EmComponent
|
48
|
|
- def __init__(self, id_or_name):
|
|
48
|
+ def __init__(self, data):
|
49
|
49
|
if type(self) == EmComponent:
|
50
|
50
|
raise NotImplementedError('Abstract class')
|
51
|
51
|
|
|
@@ -55,14 +55,10 @@ class EmComponent(object):
|
55
|
55
|
# @see EmComponent::_fields EditorialModel::fieldtypes::EmFieldType
|
56
|
56
|
self._fields = OrderedDict([(name, ftype()) for (name, ftype) in (EmComponent._fields + self.__class__._fields)])
|
57
|
57
|
|
58
|
|
- # populate
|
59
|
|
- if isinstance(id_or_name, int):
|
60
|
|
- self._fields['uid'].value = id_or_name # read only propertie set
|
61
|
|
- elif isinstance(id_or_name, str):
|
62
|
|
- self.name = id_or_name
|
63
|
|
- else:
|
64
|
|
- raise TypeError('Bad argument: expecting <int> or <str> but got : ' + str(type(id_or_name)))
|
65
|
|
- self.populate()
|
|
58
|
+ for name, value in data.items():
|
|
59
|
+ if name in self._fields:
|
|
60
|
+ self._fields[name].from_string(value)
|
|
61
|
+
|
66
|
62
|
|
67
|
63
|
## @brief Access an attribute of an EmComponent
|
68
|
64
|
# This method is overloads the default __getattr__ to search in EmComponents::_fields . If there is an EditorialModel::EmField with a corresponding name in the component
|