|
@@ -5,16 +5,24 @@
|
5
|
5
|
|
6
|
6
|
from EditorialModel.classes import EmClass
|
7
|
7
|
|
|
8
|
+
|
8
|
9
|
class Model(object):
|
|
10
|
+
|
9
|
11
|
componentClass = EmClass
|
10
|
12
|
|
|
13
|
+ ## Constructor
|
|
14
|
+ #
|
|
15
|
+ # @param backend unknown: A backend object instanciated from one of the classes in the backend module
|
11
|
16
|
def __init__(self, backend):
|
12
|
17
|
self.backend = backend
|
|
18
|
+ self.uids = {}
|
13
|
19
|
self.load()
|
14
|
20
|
|
|
21
|
+ ## Loads the structure of the Editorial Model
|
|
22
|
+ #
|
|
23
|
+ # Gets all the objects contained in that structure and creates a list indexed by their uids
|
15
|
24
|
def load(self):
|
16
|
25
|
data = self.backend.load()
|
17
|
|
- self.uids = {}
|
18
|
26
|
for uid, component in data.items():
|
19
|
27
|
cls_name = 'component' + component['component']
|
20
|
28
|
cls = getattr(Model, cls_name)
|
|
@@ -22,15 +30,17 @@ class Model(object):
|
22
|
30
|
component['uid'] = uid
|
23
|
31
|
self.uids[uid] = cls(component)
|
24
|
32
|
|
25
|
|
- # save data using the current backend
|
|
33
|
+ ## Saves data using the current backend
|
26
|
34
|
def save(self):
|
27
|
35
|
return self.backend.save()
|
28
|
36
|
|
29
|
|
- # change the current backend
|
|
37
|
+ ## Changes the current backend
|
|
38
|
+ #
|
|
39
|
+ # @param backend unknown: A backend object
|
30
|
40
|
def set_backend(self, backend):
|
31
|
41
|
self.backend = backend
|
32
|
42
|
|
33
|
|
- # return a list of all EmClass of the model
|
34
|
|
- def classes():
|
35
|
|
- classes = [component for component in self.data.uids if isinstance(component, EmClass)]
|
|
43
|
+ ## Returns a list of all the EmClass objects of the model
|
|
44
|
+ def classes(self):
|
|
45
|
+ classes = [component for _, component in self.uids if isinstance(component, EmClass)]
|
36
|
46
|
return classes
|