|
@@ -4,6 +4,7 @@
|
4
|
4
|
# Manage instance of an editorial model
|
5
|
5
|
|
6
|
6
|
from EditorialModel.migrationhandler.dummy import DummyMigrationHandler
|
|
7
|
+from EditorialModel.backend.dummy_backend import EmBackendDummy
|
7
|
8
|
from EditorialModel.classes import EmClass
|
8
|
9
|
from EditorialModel.fieldgroups import EmFieldGroup
|
9
|
10
|
from EditorialModel.fields import EmField
|
|
@@ -15,7 +16,7 @@ import hashlib
|
15
|
16
|
## Manages the Editorial Model
|
16
|
17
|
class Model(object):
|
17
|
18
|
|
18
|
|
- components_class = [EmClass, EmField, EmFieldGroup, EmType]
|
|
19
|
+ components_class = [EmClass, EmType, EmFieldGroup, EmField]
|
19
|
20
|
|
20
|
21
|
## Constructor
|
21
|
22
|
#
|
|
@@ -141,10 +142,10 @@ class Model(object):
|
141
|
142
|
datas['uid'] = uid if uid else self.new_uid()
|
142
|
143
|
em_component = em_obj(self, **datas)
|
143
|
144
|
|
144
|
|
- em_component.rank = em_component.get_max_rank() + 1 #Inserting last by default
|
|
145
|
+ em_component.rank = em_component.get_max_rank() + 1 # Inserting last by default
|
145
|
146
|
|
146
|
147
|
self._components['uids'][em_component.uid] = em_component
|
147
|
|
- self._components[self.name_from_emclass(em_component.__class__)].append(em_component)
|
|
148
|
+ self._components[component_type].append(em_component)
|
148
|
149
|
|
149
|
150
|
if rank != 'last':
|
150
|
151
|
em_component.set_rank(1 if rank == 'first' else rank)
|
|
@@ -193,3 +194,38 @@ class Model(object):
|
193
|
194
|
## Returns a list of all the EmClass objects of the model
|
194
|
195
|
def classes(self):
|
195
|
196
|
return list(self._components[self.name_from_emclass(EmClass)])
|
|
197
|
+
|
|
198
|
+ ## Use a new migration handler, re-apply all the ME to this handler
|
|
199
|
+ #
|
|
200
|
+ # @param new_mh MigrationHandler: A migration_handler object
|
|
201
|
+ # @warning : if a relational-attribute field (with 'rel_field_id') comes before it's relational field (with 'rel_to_type_id'), this will blow up
|
|
202
|
+ def migrate_handler(self, new_mh):
|
|
203
|
+ new_me = Model(EmBackendDummy(), new_mh)
|
|
204
|
+ relations = {'fields_list': [], 'subordinates_list': []}
|
|
205
|
+
|
|
206
|
+ # re-create component one by one, in components_class[] order
|
|
207
|
+ for cls in self.components_class:
|
|
208
|
+ for component in self.components(cls):
|
|
209
|
+ component_type = self.name_from_emclass(cls)
|
|
210
|
+ component_dump = component.attr_dump
|
|
211
|
+ del component_dump['model'], component_dump['_inited']
|
|
212
|
+ # Save relations between component to apply them later
|
|
213
|
+ for relation in relations.keys():
|
|
214
|
+ if relation in component_dump and component_dump[relation]:
|
|
215
|
+ relations[relation].append((component.uid, component_dump[relation]))
|
|
216
|
+ del component_dump[relation]
|
|
217
|
+ new_me.create_component(component_type, component_dump, component.uid)
|
|
218
|
+
|
|
219
|
+ # apply selected field to types
|
|
220
|
+ for fields_list in relations['fields_list']:
|
|
221
|
+ uid, fields = fields_list
|
|
222
|
+ for field_id in fields:
|
|
223
|
+ new_me.component(uid).select_field(new_me.component(field_id))
|
|
224
|
+ # add superiors to types
|
|
225
|
+ for subordinates_list in relations['subordinates_list']:
|
|
226
|
+ uid, sub_list = subordinates_list
|
|
227
|
+ for nature, subordinates in sub_list.items():
|
|
228
|
+ for subordinate_id in subordinates:
|
|
229
|
+ new_me.component(subordinate_id).add_superior(new_me.component(uid), nature)
|
|
230
|
+
|
|
231
|
+ self.migration_handler = new_mh
|