|
@@ -70,23 +70,6 @@ class EmComponent(object):
|
70
|
70
|
except AttributeError: pass
|
71
|
71
|
uname += '_'+self.name
|
72
|
72
|
return uname
|
73
|
|
-
|
74
|
|
- ## @brief dumps attr for serialization
|
75
|
|
- def dumps(self):
|
76
|
|
- #attr = {fname: fval for fname, fval in self.__dict__.items() if not (fname.startswith('_'))}
|
77
|
|
- attr = self.attr_dump
|
78
|
|
- if 'model' in attr:
|
79
|
|
- del(attr['model'])
|
80
|
|
- for attr_f in attr:
|
81
|
|
- if isinstance(attr[attr_f], EmComponent):
|
82
|
|
- attr[attr_f] = attr[attr_f].uid
|
83
|
|
- elif isinstance(attr[attr_f], MlString):
|
84
|
|
- attr[attr_f] = attr[attr_f].__str__()
|
85
|
|
- if isinstance(self, EditorialModel.fields.EmField):
|
86
|
|
- attr['component'] = 'EmField'
|
87
|
|
- else:
|
88
|
|
- attr['component'] = self.__class__.__name__
|
89
|
|
- return attr
|
90
|
73
|
|
91
|
74
|
## @brief This function has to be called after the instanciation, checks, and init manipulations are done
|
92
|
75
|
# @note Create a new attribute _inited that allow __setattr__ to know if it has or not to call the migration handler
|
|
@@ -117,9 +100,26 @@ class EmComponent(object):
|
117
|
100
|
## @brief Hash function that allows to compare two EmComponent
|
118
|
101
|
# @return EmComponent+ClassName+uid
|
119
|
102
|
def __hash__(self):
|
120
|
|
- component_dump = self.dumps()
|
121
|
|
- del component_dump['date_create']
|
122
|
|
- del component_dump['date_update']
|
|
103
|
+ # flatten list of attributes of the component to an ordered list
|
|
104
|
+ # so every time we have the same string representation
|
|
105
|
+ attributes_dump = self.attr_dump
|
|
106
|
+ ordered_attributes = sorted(list(attributes_dump.keys()))
|
|
107
|
+
|
|
108
|
+ component_dump = []
|
|
109
|
+ for attr_name in ordered_attributes:
|
|
110
|
+ if isinstance(attributes_dump[attr_name], EmComponent):
|
|
111
|
+ value = attributes_dump[attr_name].uid
|
|
112
|
+ elif isinstance(attributes_dump[attr_name], MlString):
|
|
113
|
+ value = attributes_dump[attr_name].__str__()
|
|
114
|
+ elif isinstance(attributes_dump[attr_name], datetime.datetime):
|
|
115
|
+ continue
|
|
116
|
+ else:
|
|
117
|
+ value = attributes_dump[attr_name]
|
|
118
|
+ component_dump.append((attr_name, value))
|
|
119
|
+
|
|
120
|
+ component_name = 'EmField' if isinstance(self, EditorialModel.fields.EmField) else self.__class__.__name__
|
|
121
|
+ component_dump.append(('component', component_name))
|
|
122
|
+
|
123
|
123
|
return int(hashlib.md5(str(component_dump).encode('utf-8')).hexdigest(), 16)
|
124
|
124
|
|
125
|
125
|
## @brief Test if two EmComponent are "equals"
|