|
@@ -0,0 +1,52 @@
|
|
1
|
+# -*- coding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+## Main object to manipulate Editorial Model
|
|
4
|
+#
|
|
5
|
+# parent of all other EM editing classes
|
|
6
|
+# @see EmClass, EmType, EmFieldGroup, EmField
|
|
7
|
+
|
|
8
|
+class EmComponent(object):
|
|
9
|
+
|
|
10
|
+ ## instaciate an EmComponent
|
|
11
|
+ # @param id_or_name <int> || <str>
|
|
12
|
+ # @raise TypeError
|
|
13
|
+ def __init(id_or_name):
|
|
14
|
+ if id_or_name is int:
|
|
15
|
+ self.id = id_or_name
|
|
16
|
+ else if id_or_name is str:
|
|
17
|
+ self.name = id_or_name
|
|
18
|
+ self.populate()
|
|
19
|
+ else:
|
|
20
|
+ raise TypeError('Bad argument: expecting <int> or <str>')
|
|
21
|
+
|
|
22
|
+ ## Lookup in the database properties of the object
|
|
23
|
+ def populate(self):
|
|
24
|
+ if self.id is None:
|
|
25
|
+ where = "name = " + db.quote(self.name)
|
|
26
|
+ else:
|
|
27
|
+ where = "id = " + self.id
|
|
28
|
+
|
|
29
|
+ row = db.query(where)
|
|
30
|
+ if not row:
|
|
31
|
+ # could have two possible Error message for id and for name
|
|
32
|
+ raise EmComponentNotExistError("Bad id_or_name: could not find the component")
|
|
33
|
+
|
|
34
|
+ self.name = row.name
|
|
35
|
+ self.rank = row.rank
|
|
36
|
+ self.date_update = row.date_update
|
|
37
|
+ self.date_create <datetime object>
|
|
38
|
+ self.string <MlString object> : string representation of the component
|
|
39
|
+ self.help <MlString object> : help string
|
|
40
|
+ self.icon <string> : path to the icon (should be id_global of EmFile object)
|
|
41
|
+
|
|
42
|
+ @static_method
|
|
43
|
+ def id_from_name(name):
|
|
44
|
+
|
|
45
|
+ @staticmethod
|
|
46
|
+ def create(name <string>, parent_component <EmComponent object>)
|
|
47
|
+ def save(self)
|
|
48
|
+ def delete(self)
|
|
49
|
+ def modify_rank(self)
|
|
50
|
+ def set_string(self, lang, texte)
|
|
51
|
+ def set_strings(self)
|
|
52
|
+ def get_string(self, lang)
|