|
@@ -9,17 +9,18 @@ from EditorialModel.fields import EmField
|
9
|
9
|
from EditorialModel.types import EmType
|
10
|
10
|
import EditorialModel
|
11
|
11
|
|
|
12
|
+
|
12
|
13
|
## Manages the Editorial Model
|
13
|
14
|
class Model(object):
|
14
|
15
|
|
15
|
|
- components_class = [ EmClass, EmField, EmFieldGroup, EmType ]
|
|
16
|
+ components_class = [EmClass, EmField, EmFieldGroup, EmType]
|
16
|
17
|
|
17
|
18
|
## Constructor
|
18
|
19
|
#
|
19
|
20
|
# @param backend unknown: A backend object instanciated from one of the classes in the backend module
|
20
|
21
|
def __init__(self, backend):
|
21
|
22
|
self.backend = backend
|
22
|
|
- self._components = {'uids':{}, 'EmClass':[], 'EmType':[], 'EmField':[], 'EmFieldGroup':[]}
|
|
23
|
+ self._components = {'uids': {}, 'EmClass': [], 'EmType': [], 'EmField': [], 'EmFieldGroup': []}
|
23
|
24
|
self.load()
|
24
|
25
|
|
25
|
26
|
@staticmethod
|
|
@@ -36,10 +37,10 @@ class Model(object):
|
36
|
37
|
## Given a python class return a name
|
37
|
38
|
# @param cls : The python class we want the name
|
38
|
39
|
# @return A class name as string or False if cls is not an EmComponent child class
|
39
|
|
- def name_from_emclass(cls):
|
40
|
|
- if cls not in Model.components_class:
|
|
40
|
+ def name_from_emclass(em_class):
|
|
41
|
+ if em_class not in Model.components_class:
|
41
|
42
|
return False
|
42
|
|
- return cls.__name__
|
|
43
|
+ return em_class.__name__
|
43
|
44
|
|
44
|
45
|
## Loads the structure of the Editorial Model
|
45
|
46
|
#
|
|
@@ -55,7 +56,7 @@ class Model(object):
|
55
|
56
|
self._components['uids'][uid] = cls(component, self)
|
56
|
57
|
self._components[cls_name].append(self._components['uids'][uid])
|
57
|
58
|
else:
|
58
|
|
- raise ValueError("Unknow EmComponent class : '"+cls_name+"'")
|
|
59
|
+ raise ValueError("Unknow EmComponent class : '" + cls_name + "'")
|
59
|
60
|
|
60
|
61
|
for emclass in Model.components_class:
|
61
|
62
|
comp_list = self.components(emclass)
|
|
@@ -79,12 +80,12 @@ class Model(object):
|
79
|
80
|
# @return The corresponding instance or False if uid don't exists
|
80
|
81
|
def component(self, uid):
|
81
|
82
|
return False if uid not in self._components['uids'] else self._components['uids'][uid]
|
82
|
|
-
|
|
83
|
+
|
83
|
84
|
## Return a new uid
|
84
|
85
|
# @return a new uid
|
85
|
86
|
def new_uid(self):
|
86
|
87
|
used_uid = self._components.keys()
|
87
|
|
- return sorted(new_uid)[-1] + 1 if len(used_uid) > 0 else 1
|
|
88
|
+ return sorted(used_uid)[-1] + 1 if len(used_uid) > 0 else 1
|
88
|
89
|
|
89
|
90
|
## Create a component from a component type and datas
|
90
|
91
|
#
|
|
@@ -95,7 +96,7 @@ class Model(object):
|
95
|
96
|
em_component = self.emclass_from_name(component_type)(datas, self)
|
96
|
97
|
|
97
|
98
|
self._components['uids'][em_component.uid] = em_component
|
98
|
|
- self._components[name_from_emclass(em_component.__class__)].append(em_component)
|
|
99
|
+ self._components[self.name_from_emclass(em_component.__class__)].append(em_component)
|
99
|
100
|
return em_component
|
100
|
101
|
|
101
|
102
|
## Delete a component
|
|
@@ -107,7 +108,7 @@ class Model(object):
|
107
|
108
|
raise EditorialModel.components.EmComponentNotExistError()
|
108
|
109
|
em_component = self._components[uid]
|
109
|
110
|
if em_component.delete_p():
|
110
|
|
- self._components[name_from_emclass(em_component.__class__)].remove(em_component)
|
|
111
|
+ self._components[self.name_from_emclass(em_component.__class__)].remove(em_component)
|
111
|
112
|
del self._components['uids'][uid]
|
112
|
113
|
return True
|
113
|
114
|
|
|
@@ -119,4 +120,4 @@ class Model(object):
|
119
|
120
|
|
120
|
121
|
## Returns a list of all the EmClass objects of the model
|
121
|
122
|
def classes(self):
|
122
|
|
- return list(self._components[Model.name_from_emclass(EmClass)])
|
|
123
|
+ return list(self._components[self.name_from_emclass(EmClass)])
|