Browse Source

ME : renommage et import

ArnAud 9 years ago
parent
commit
a86ff9ee97

EditorialModel/class.py → EditorialModel/classes.py View File

5
     @see EmClass, EmType, EmFieldGroup, EmField
5
     @see EmClass, EmType, EmFieldGroup, EmField
6
 """
6
 """
7
 
7
 
8
-from component import EmComponent
8
+from EditorialModel.components import EmComponent, EmComponentNotExistError
9
+import EditorialModel.classtypes
10
+from Database.sqlwrapper import SqlWrapper
9
 
11
 
10
-class EmClass(EmComponent)
11
-    def __init(id_or_name):
12
+class EmClass(EmComponent):
13
+    def __init__(self, id_or_name):
12
         self.table = 'em_class'
14
         self.table = 'em_class'
13
-        pass
15
+        super(EmClass, self).__init__(id_or_name)
14
 
16
 
15
     """ create a new class
17
     """ create a new class
16
         @param name str: name of the new class
18
         @param name str: name of the new class
17
         @param class_type EmClasstype: type of the class
19
         @param class_type EmClasstype: type of the class
18
     """
20
     """
19
     @staticmethod
21
     @staticmethod
20
-    def create(self, name, class_type):
21
-       pass
22
+    def create(name, class_type):
23
+        #try:
24
+        exists = EmClass(name)
25
+        #except EmComponentNotExistError:
26
+            #print ("bin")
27
+            #pass
28
+        print (name, class_type)
29
+        pass
22
 
30
 
23
     """ retrieve list of the field_groups of this class
31
     """ retrieve list of the field_groups of this class
24
         @return field_groups [EmFieldGroup]:
32
         @return field_groups [EmFieldGroup]:
25
     """
33
     """
26
     def field_groups():
34
     def field_groups():
27
-       pass
35
+        pass
28
 
36
 
29
     """ retrieve list of fields
37
     """ retrieve list of fields
30
         @return fields [EmField]:
38
         @return fields [EmField]:
31
     """
39
     """
32
     def fields():
40
     def fields():
33
-       pass
41
+        pass
34
 
42
 
35
     """ retrieve list of type of this class
43
     """ retrieve list of type of this class
36
         @return types [EmType]:
44
         @return types [EmType]:
42
         @param  t EmType: type to link
50
         @param  t EmType: type to link
43
         @return success bool: done or not
51
         @return success bool: done or not
44
     """
52
     """
45
-    def link_type(t <EmType>):
53
+    def link_type(t):
46
         pass
54
         pass
47
 
55
 
48
     """ retrieve list of EmType that are linked to this class
56
     """ retrieve list of EmType that are linked to this class

+ 55
- 0
EditorialModel/classtypes.py View File

1
+# -*- coding: utf-8 -*-
2
+
3
+"""
4
+    representation of the classTypes (sic…)
5
+"""
6
+
7
+class EmNature(object):
8
+    PARENT = 'parent'
9
+    TRANSLATION = 'translation'
10
+    IDENTITY = 'identity'
11
+
12
+class EmClassType(object):
13
+
14
+    entity = {
15
+        'name' : 'entity',
16
+        'hierarchy' : [
17
+            {
18
+                'nature'   : EmNature.PARENT,
19
+                'attach'   : 'type',
20
+                'editable' : True,
21
+            },
22
+            {
23
+                'nature'   : EmNature.TRANSLATION,
24
+                'attach'   : 'type',
25
+                'editable' : True,
26
+            },
27
+        ],
28
+    }
29
+
30
+    entry = {
31
+        'name' : 'entry',
32
+        'hierarchy' : [
33
+            {
34
+                'nature'   : EmNature.PARENT,
35
+                'attach'   : 'type',
36
+                'editable' : True,
37
+            },
38
+            {
39
+                'nature'   : EmNature.TRANSLATION,
40
+                'attach'   : 'type',
41
+                'editable' : True,
42
+            },
43
+        ],
44
+    }
45
+
46
+    person = {
47
+        'name' : 'person',
48
+        'hierarchy' : [
49
+            {
50
+                'nature'   : EmNature.IDENTITY,
51
+                'attach'   : 'classtype',
52
+                'editable' : False,
53
+            },
54
+        ],
55
+    }

EditorialModel/component.py → EditorialModel/components.py View File

6
 """
6
 """
7
 
7
 
8
 from Lodel.utils.mlstring import MlString
8
 from Lodel.utils.mlstring import MlString
9
+from Database.sqlwrapper import SqlWrapper
10
+from Database.sqlobject import SqlObject
9
 import logging
11
 import logging
12
+import sqlalchemy as sql
10
 
13
 
11
 logger = logging.getLogger('Lodel2.EditorialModel')
14
 logger = logging.getLogger('Lodel2.EditorialModel')
12
 
15
 
17
         @exception TypeError
20
         @exception TypeError
18
     """
21
     """
19
     def __init__(self, id_or_name):
22
     def __init__(self, id_or_name):
23
+        SqlWrapper.start()
20
         if self is EmComponent:
24
         if self is EmComponent:
21
             raise EnvironmentError('Abstract class')
25
             raise EnvironmentError('Abstract class')
22
         if type(id_or_name) is int:
26
         if type(id_or_name) is int:
23
             self.id = id_or_name
27
             self.id = id_or_name
24
         elif type(id_or_name) is str:
28
         elif type(id_or_name) is str:
29
+            self.id = None
25
             self.name = id_or_name
30
             self.name = id_or_name
26
             self.populate()
31
             self.populate()
27
         else:
32
         else:
30
     """ Lookup in the database properties of the object to populate the properties
35
     """ Lookup in the database properties of the object to populate the properties
31
     """
36
     """
32
     def populate(self):
37
     def populate(self):
38
+        dbo = SqlObject(self.table)
39
+        
40
+        t = dbo.table
41
+
42
+        req = dbo.sel
43
+        print(t.c.__dict__)
44
+        
33
         if self.id is None:
45
         if self.id is None:
34
-            where = "name = " + db.quote(self.name)
46
+            req.where(t.c.name == self.name)
35
         else:
47
         else:
36
-            where = "id = " + self.id
48
+            req.where(dbo.col.id == self.id)
49
+
50
+        sqlresult = dbo.rexec(req)
51
+        print (sqlresult)
52
+
53
+        # Transformation du résultat en une liste de dictionnaires
54
+        records = sqlresult.fetchall()
55
+        print (records)
56
+
57
+        for record in records:
58
+            selected_lines.append(dict(zip(record.keys(), record)))
37
 
59
 
38
-        row = db.query('*', self.table, where)
39
         if not row:
60
         if not row:
40
             # could have two possible Error message for id and for name
61
             # could have two possible Error message for id and for name
41
             raise EmComponentNotExistError("Bad id_or_name: could not find the component")
62
             raise EmComponentNotExistError("Bad id_or_name: could not find the component")
89
     """
110
     """
90
     def get_string(self, lang):
111
     def get_string(self, lang):
91
         pass
112
         pass
113
+
114
+class EmComponentNotExistError(Exception):
115
+    pass

EditorialModel/fieldgroup.py → EditorialModel/fieldgroups.py View File

1
 #-*- coding: utf-8 -*-
1
 #-*- coding: utf-8 -*-
2
 
2
 
3
-from component import EmComponent
4
-
3
+from EditorialModel.components import EmComponent
5
 
4
 
6
 class EmFieldGroup(EmComponent):
5
 class EmFieldGroup(EmComponent):
7
     """ Represents groups of EmField
6
     """ Represents groups of EmField

EditorialModel/field.py → EditorialModel/fields.py View File

1
 #-*- coding: utf-8 -*-
1
 #-*- coding: utf-8 -*-
2
 
2
 
3
-from component import EmComponent
3
+from EditorialModel.components import EmComponent
4
 
4
 
5
 """Represent one data for a lodel2 document"""
5
 """Represent one data for a lodel2 document"""
6
 class EmField(EmComponent):
6
 class EmField(EmComponent):

+ 1
- 1
EditorialModel/test/test_component.py View File

1
 #from django.test import TestCase
1
 #from django.test import TestCase
2
 from unittest import TestCase
2
 from unittest import TestCase
3
-from EditorialModel.lib.component import EmComponent
3
+from EditorialModel.component import EmComponent
4
 
4
 
5
 class ComponentTestCase(TestCase):
5
 class ComponentTestCase(TestCase):
6
 
6
 

EditorialModel/type.py → EditorialModel/types.py View File

1
 #-*- coding: utf-8 -*-
1
 #-*- coding: utf-8 -*-
2
 
2
 
3
-from component import EmComponent
3
+from EditorialModel.components import EmComponent
4
 
4
 
5
 class EmType(EmComponent):
5
 class EmType(EmComponent):
6
     """ Represents type of documents
6
     """ Represents type of documents
7
-    
7
+
8
         A type is a specialisation of a class, it can select optional field,
8
         A type is a specialisation of a class, it can select optional field,
9
         they have hooks, are organized in hierarchy and linked to other
9
         they have hooks, are organized in hierarchy and linked to other
10
         EmType with special fields called relation_to_type fields
10
         EmType with special fields called relation_to_type fields
11
         @see EmComponent
11
         @see EmComponent
12
     """
12
     """
13
-    
13
+
14
     def __init__(id_or_name):
14
     def __init__(id_or_name):
15
         """  Instanciate an EmType with data fetched from db
15
         """  Instanciate an EmType with data fetched from db
16
             @param id_or_name str|int: Identify the EmType by name or by global_id
16
             @param id_or_name str|int: Identify the EmType by name or by global_id

Loading…
Cancel
Save