Browse Source

EM: on avance…

ArnAud 9 years ago
parent
commit
9dab9ce22f
4 changed files with 76 additions and 52 deletions
  1. 27
    16
      em/class.py
  2. 44
    30
      em/component.py
  3. 4
    4
      em/field.py
  4. 1
    2
      em/fieldgroup.py

+ 27
- 16
em/class.py View File

@@ -1,41 +1,52 @@
1 1
 # -*- coding: utf-8 -*-
2 2
 
3
-## Manipulate Classes of the Editorial Model
4
-#
5
-# Create classes of object
6
-# @see EmClass, EmType, EmFieldGroup, EmField
3
+""" Manipulate Classes of the Editorial Model
4
+    Create classes of object
5
+    @see EmClass, EmType, EmFieldGroup, EmField
6
+"""
7 7
 
8
-import EmComponent
8
+from component import EmComponent
9 9
 
10 10
 class EmClass(EmComponent)
11 11
     def __init(id_or_name):
12 12
         self.table = 'em_class'
13 13
         pass
14 14
 
15
-    ## create a new class
16
-    # @param str         name       name of the new class
17
-    # @param EmClasstype class_type type of the class
15
+    """ create a new class
16
+        @param name str: name of the new class
17
+        @param class_type EmClasstype: type of the class
18
+    """
19
+    @staticmethod
18 20
     def create(self, name, class_type):
19 21
        pass
20 22
 
21
-    ## retrieve list field_groups of this class
22
-    # @return [EmFieldGroup]
23
+    """ retrieve list of the field_groups of this class
24
+        @return field_groups [EmFieldGroup]:
25
+    """
23 26
     def field_groups():
24 27
        pass
25 28
 
29
+    """ retrieve list of fields
30
+        @return fields [EmField]:
31
+    """
26 32
     def fields():
27 33
        pass
28 34
 
35
+    """ retrieve list of type of this class
36
+        @return types [EmType]:
37
+    """
29 38
     def types():
30 39
         pass
31 40
 
32
-    ## add a new EmType that can ben linked to this class
33
-    # @param  EmType t       type to link
34
-    # @return bool   success
41
+    """ add a new EmType that can ben linked to this class
42
+        @param  t EmType: type to link
43
+        @return success bool: done or not
44
+    """
35 45
     def link_type(t <EmType>):
36 46
         pass
37
-    
38
-    ## retrieve list of EmType that are linked to this class
39
-    # @return [EmType]
47
+
48
+    """ retrieve list of EmType that are linked to this class
49
+        @return types [EmType]:
50
+    """
40 51
     def linked_types():
41 52
         pass

+ 44
- 30
em/component.py View File

@@ -1,16 +1,21 @@
1 1
 # -*- coding: utf-8 -*-
2 2
 
3
-## Main object to manipulate Editorial Model
4
-#
5
-# parent of all other EM editing classes
6
-# @see EmClass, EmType, EmFieldGroup, EmField
3
+""" Main object to manipulate Editorial Model
4
+    parent of all other EM editing classes
5
+    @see EmClass, EmType, EmFieldGroup, EmField
6
+"""
7
+
8
+from ml_string import MlString
7 9
 
8 10
 class EmComponent(object):
9 11
 
10
-    ## instaciate an EmComponent
11
-    # @param int|str id_or_name 
12
-    # @raise TypeError
13
-    def __init(id_or_name):
12
+    """ instaciate an EmComponent
13
+        @param id_or_name int|str: name or id of the object
14
+        @exception TypeError
15
+    """
16
+    def __init__(self, id_or_name):
17
+        if self is EmComponent:
18
+            raise EnvironmentError('Abstract class')
14 19
         if id_or_name is int:
15 20
             self.id = id_or_name
16 21
         else if id_or_name is str:
@@ -19,56 +24,65 @@ class EmComponent(object):
19 24
         else:
20 25
             raise TypeError('Bad argument: expecting <int> or <str>')
21 26
 
22
-    ## Lookup in the database properties of the object
27
+    """ Lookup in the database properties of the object to populate the properties
28
+    """
23 29
     def populate(self):
24 30
         if self.id is None:
25 31
             where = "name = " + db.quote(self.name)
26 32
         else:
27 33
             where = "id = " + self.id
28 34
 
29
-        row = db.query(where)
35
+        row = db.query('*', self.table, where)
30 36
         if not row:
31 37
             # could have two possible Error message for id and for name
32 38
             raise EmComponentNotExistError("Bad id_or_name: could not find the component")
33 39
 
34 40
         self.name = row.name
35
-        self.rank = row.rank
41
+        self.rank = int(row.rank)
36 42
         self.date_update = row.date_update
37 43
         self.date_create = row.date_create
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)
44
+        self.string = MlString.from_json(row.string)
45
+        self.help = MlString.from_json(row.help)
46
+        self.icon = row.icon
47
+
48
+        return row
41 49
 
42
-    ## write the representation of the component in the database
43
-    # @return bool
50
+    """ write the representation of the component in the database
51
+        @return bool
52
+    """
44 53
     def save(self):
45 54
         pass
46 55
 
47
-    ## delete this component in the database
48
-    # @return bool
56
+    """ delete this component data in the database
57
+        @return bool
58
+    """
49 59
     def delete(self):
50 60
         pass
51 61
 
52
-    ## change the rank of the component
53
-    # @param int new_rank new position
62
+    """ change the rank of the component
63
+        @param int new_rank new position
64
+    """
54 65
     def modify_rank(self, new_rank):
55 66
         pass
56 67
 
57
-    ## set a string representation of the component for a given language
58
-    # @param  str lang iso 639-2 representation of the language http://en.wikipedia.org/wiki/List_of_ISO_639-2_codes
59
-    # @param  str text
60
-    # @return bool
68
+    """ set a string representation of the component for a given language
69
+        @param  lang str: iso 639-2 code of the language http://en.wikipedia.org/wiki/List_of_ISO_639-2_codes
70
+        @param  text str: text to set
71
+        @return bool
72
+    """
61 73
     def set_string(self, lang, text):
62 74
         pass
63 75
 
64
-    ## set the string representation of the component
65
-    # @param  MlString ml_string strings for all language
66
-    # @return bool
76
+    """ set the string representation of the component
77
+        @param  ml_string  MlString: strings for all language
78
+        @return bool
79
+    """
67 80
     def set_strings(self, ml_string):
68 81
         pass
69 82
 
70
-    ## get the string representation of the component for the given language
71
-    # @param  str lang iso 639-2 representation of the language
72
-    # @return str
83
+    """ get the string representation of the component for the given language
84
+        @param  lang   str: iso 639-2 code of the language
85
+        @return text   str: 
86
+    """
73 87
     def get_string(self, lang):
74 88
         pass

+ 4
- 4
em/field.py View File

@@ -15,6 +15,7 @@ class EmField(EmComponent):
15 15
         super(EmField, self).__init__()
16 16
         pass
17 17
 
18
+    @staticmethod
18 19
     def create( name, em_fieldgroup, ml_repr = None, ml_help = None,
19 20
                 icon = None, optionnal = False, type_relation = None,
20 21
                 relationnal_field = None, primary_data = False,
@@ -22,7 +23,6 @@ class EmField(EmComponent):
22 23
         """ Create a new EmType and instanciate it
23 24
             
24 25
             @todo Change the icon param type
25
-            @todo change staticmethod to classmethod ?
26 26
             @todo simplify function aguments ?
27 27
             @todo typeof default_value argument ?
28 28
             @todo typeof params argument ?
@@ -40,9 +40,9 @@ class EmField(EmComponent):
40 40
             @param type_relation EmType|None: If not None make a link between the class of the new EmField and this EmType
41 41
             @param relationnal_field EmField|None: If not None indicates that the new field defines the relation created by this EmField argument
42 42
             @param primary_data bool: Is the new field a primary data field ?
43
-            @param The default_value: field's default value
44
-            @param Params params: of the field
45
-            @param Value value: of the field
43
+            @param default_value str: The field's default value
44
+            @param params str: Params of the field
45
+            @param value str: Value of the field
46 46
             
47 47
             @throw TypeError
48 48
             @see EmComponent::__init__()

+ 1
- 2
em/fieldgroup.py View File

@@ -20,7 +20,7 @@ class EmFieldGroup(EmComponent):
20 20
         super(EmFieldGroup, self).__init__()
21 21
         pass
22 22
 
23
-
23
+    @staticmethod
24 24
     def create(name, em_class, ml_repr = None, ml_help = None, icon = None):
25 25
         """ Create a new EmType and instanciate it
26 26
             
@@ -35,7 +35,6 @@ class EmFieldGroup(EmComponent):
35 35
             @param The string|None: filename of the icon
36 36
             @return An EmFieldGroup instance
37 37
             @see EmComponent::__init__()
38
-            @staticmethod
39 38
         """
40 39
         pass
41 40
 

Loading…
Cancel
Save