Browse Source

ME : renommage et import

ArnAud 9 years ago
parent
commit
a86ff9ee97

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

@@ -5,32 +5,40 @@
5 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 14
         self.table = 'em_class'
13
-        pass
15
+        super(EmClass, self).__init__(id_or_name)
14 16
 
15 17
     """ create a new class
16 18
         @param name str: name of the new class
17 19
         @param class_type EmClasstype: type of the class
18 20
     """
19 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 31
     """ retrieve list of the field_groups of this class
24 32
         @return field_groups [EmFieldGroup]:
25 33
     """
26 34
     def field_groups():
27
-       pass
35
+        pass
28 36
 
29 37
     """ retrieve list of fields
30 38
         @return fields [EmField]:
31 39
     """
32 40
     def fields():
33
-       pass
41
+        pass
34 42
 
35 43
     """ retrieve list of type of this class
36 44
         @return types [EmType]:
@@ -42,7 +50,7 @@ class EmClass(EmComponent)
42 50
         @param  t EmType: type to link
43 51
         @return success bool: done or not
44 52
     """
45
-    def link_type(t <EmType>):
53
+    def link_type(t):
46 54
         pass
47 55
 
48 56
     """ retrieve list of EmType that are linked to this class

+ 55
- 0
EditorialModel/classtypes.py View File

@@ -0,0 +1,55 @@
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,7 +6,10 @@
6 6
 """
7 7
 
8 8
 from Lodel.utils.mlstring import MlString
9
+from Database.sqlwrapper import SqlWrapper
10
+from Database.sqlobject import SqlObject
9 11
 import logging
12
+import sqlalchemy as sql
10 13
 
11 14
 logger = logging.getLogger('Lodel2.EditorialModel')
12 15
 
@@ -17,11 +20,13 @@ class EmComponent(object):
17 20
         @exception TypeError
18 21
     """
19 22
     def __init__(self, id_or_name):
23
+        SqlWrapper.start()
20 24
         if self is EmComponent:
21 25
             raise EnvironmentError('Abstract class')
22 26
         if type(id_or_name) is int:
23 27
             self.id = id_or_name
24 28
         elif type(id_or_name) is str:
29
+            self.id = None
25 30
             self.name = id_or_name
26 31
             self.populate()
27 32
         else:
@@ -30,12 +35,28 @@ class EmComponent(object):
30 35
     """ Lookup in the database properties of the object to populate the properties
31 36
     """
32 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 45
         if self.id is None:
34
-            where = "name = " + db.quote(self.name)
46
+            req.where(t.c.name == self.name)
35 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 60
         if not row:
40 61
             # could have two possible Error message for id and for name
41 62
             raise EmComponentNotExistError("Bad id_or_name: could not find the component")
@@ -89,3 +110,6 @@ class EmComponent(object):
89 110
     """
90 111
     def get_string(self, lang):
91 112
         pass
113
+
114
+class EmComponentNotExistError(Exception):
115
+    pass

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

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

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

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

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

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

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

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

Loading…
Cancel
Save