|
@@ -26,6 +26,12 @@ class Model(object):
|
26
|
26
|
self.components = {'uids':{}, 'class':{}, 'type':{}, 'field':{}, 'fieldgroup':{}}
|
27
|
27
|
self.load()
|
28
|
28
|
|
|
29
|
+ @staticmethod
|
|
30
|
+ ## Given a name return an EmComponent child class
|
|
31
|
+ # @param class_name str : The name to identify an EmComponent class
|
|
32
|
+ def emclass_from_name(class_name):
|
|
33
|
+ return getattr(Model, class_name)
|
|
34
|
+
|
29
|
35
|
## Loads the structure of the Editorial Model
|
30
|
36
|
#
|
31
|
37
|
# Gets all the objects contained in that structure and creates a dict indexed by their uids
|
|
@@ -33,7 +39,7 @@ class Model(object):
|
33
|
39
|
data = self.backend.load()
|
34
|
40
|
for uid, component in data.items():
|
35
|
41
|
cls_name = 'component_' + component['component']
|
36
|
|
- cls = getattr(Model, cls_name)
|
|
42
|
+ cls = self.emclass_from_name(cls_name)
|
37
|
43
|
if cls:
|
38
|
44
|
component['uid'] = uid
|
39
|
45
|
# create a dict for the component and one indexed by uids, store instanciated component in it
|
|
@@ -44,6 +50,22 @@ class Model(object):
|
44
|
50
|
def save(self):
|
45
|
51
|
return self.backend.save()
|
46
|
52
|
|
|
53
|
+ ## Create a component from a component type and datas
|
|
54
|
+ #
|
|
55
|
+ # @param component_type str : a component type ( component_class, component_fieldgroup, component_field or component_type )
|
|
56
|
+ # @param datas dict : the options needed by the component creation
|
|
57
|
+ def create_component(self, component_type, datas):
|
|
58
|
+ return self.emclass_from_name[component_type].create(datas)
|
|
59
|
+
|
|
60
|
+ ## Delete a component
|
|
61
|
+ # @param uid int : Component identifier
|
|
62
|
+ # @throw NoSuchCompoentException
|
|
63
|
+ # @todo unable uid check
|
|
64
|
+ def delete_component(self, uid):
|
|
65
|
+ #if uid not in self.components:
|
|
66
|
+ # raise NoSuchComponentException()
|
|
67
|
+ return self.components[uid].delete()
|
|
68
|
+
|
47
|
69
|
## Changes the current backend
|
48
|
70
|
#
|
49
|
71
|
# @param backend unknown: A backend object
|