|
@@ -17,7 +17,16 @@ LodelContext.expose_modules(globals(), {
|
17
|
17
|
##@brief Describe an editorial model
|
18
|
18
|
#@ingroup lodel2_em
|
19
|
19
|
class EditorialModel(object):
|
20
|
|
-
|
|
20
|
+
|
|
21
|
+ ##@brief if true we are in editor mode (all groups visible & loaded)
|
|
22
|
+ #@note Usually comes from settings but can be overriden at runtime.
|
|
23
|
+ #It as been implemented this way in order to allow to load EM
|
|
24
|
+ #in lodelsites context (to generate dyncode for handled sites)
|
|
25
|
+ _editormode = Settings.editorialmodel.editormode
|
|
26
|
+ ##@brief When non in editor mode indicates the groups that we have to load
|
|
27
|
+ #in our EM
|
|
28
|
+ _groups = Settings.editorialmodel.groups
|
|
29
|
+
|
21
|
30
|
##@brief Create a new editorial model
|
22
|
31
|
# @param name MlString|str|dict : the editorial model name
|
23
|
32
|
# @param description MlString|str|dict : the editorial model description
|
|
@@ -33,7 +42,7 @@ class EditorialModel(object):
|
33
|
42
|
## @brief Stores all activated classes indexed by id
|
34
|
43
|
self.__active_classes = dict()
|
35
|
44
|
self.__set_actives()
|
36
|
|
-
|
|
45
|
+
|
37
|
46
|
##@brief EmClass uids accessor
|
38
|
47
|
#@return a dict of emclasses
|
39
|
48
|
def all_classes(self, uid = None):
|
|
@@ -44,7 +53,9 @@ class EditorialModel(object):
|
44
|
53
|
return copy.copy(self.__classes[uid])
|
45
|
54
|
except KeyError:
|
46
|
55
|
raise EditorialModelException("EmClass not found : '%s'" % uid)
|
47
|
|
-
|
|
56
|
+
|
|
57
|
+ ##@brief EmClass instances accessor
|
|
58
|
+ #@return a list of EmClass instances or a single EmClass instance
|
48
|
59
|
def all_classes_ref(self, uid = None):
|
49
|
60
|
if uid is None:
|
50
|
61
|
return self.__classes
|
|
@@ -111,6 +122,18 @@ class EditorialModel(object):
|
111
|
122
|
res.append(cls)
|
112
|
123
|
return set(res)
|
113
|
124
|
|
|
125
|
+ ##@brief Allow to override class attributes _editormode and
|
|
126
|
+ #_groups in order to control groups exposure
|
|
127
|
+ #
|
|
128
|
+ #A typicall usage of this method is for lodelsites when updating
|
|
129
|
+ #dyncode for handled sites. We have to set both attribute in order to
|
|
130
|
+ #load the EM as wanted by the handled site.
|
|
131
|
+ @classmethod
|
|
132
|
+ def _override_settings(cls, editormode = False, groups = []):
|
|
133
|
+ logger.warning("EM settings overriding ! If not in lodelsites \
|
|
134
|
+context this is a REALLY BAD idea !")
|
|
135
|
+ cls.__editormode = editormode
|
|
136
|
+ cls.__groups = groups
|
114
|
137
|
|
115
|
138
|
##@brief EmGroup getter
|
116
|
139
|
# @param uid None | str : give this argument to get a specific EmGroup
|
|
@@ -130,7 +153,7 @@ class EditorialModel(object):
|
130
|
153
|
##@brief Update the EditorialModel.__active_groups and
|
131
|
154
|
#EditorialModel.__active_classes attibutes
|
132
|
155
|
def __set_actives(self):
|
133
|
|
- if Settings.editorialmodel.editormode:
|
|
156
|
+ if self._editormode:
|
134
|
157
|
logger.warning("All EM groups active because editormode in ON")
|
135
|
158
|
# all groups & classes actives because we are in editor mode
|
136
|
159
|
self.__active_groups = self.__groups
|
|
@@ -139,7 +162,7 @@ class EditorialModel(object):
|
139
|
162
|
#determine groups first
|
140
|
163
|
self.__active_groups = dict()
|
141
|
164
|
self.__active_classes = dict()
|
142
|
|
- for agrp in Settings.editorialmodel.groups:
|
|
165
|
+ for agrp in self._groups:
|
143
|
166
|
if agrp not in self.__groups:
|
144
|
167
|
raise SettingsError('Invalid group found in settings : %s' % agrp)
|
145
|
168
|
logger.debug("Set group '%s' as active" % agrp)
|
|
@@ -227,7 +250,7 @@ class EditorialModel(object):
|
227
|
250
|
##@brief Raise an error if lodel is not in EM edition mode
|
228
|
251
|
@staticmethod
|
229
|
252
|
def raise_if_ro():
|
230
|
|
- if not Settings.editorialmodel.editormode:
|
|
253
|
+ if not self._editormode:
|
231
|
254
|
raise EditorialModelError("Lodel in not in EM editor mode. The EM is in read only state")
|
232
|
255
|
|
233
|
256
|
##@brief Load a model
|