|
@@ -1,7 +1,8 @@
|
1
|
1
|
#-*- coding: utf-8 -*-
|
2
|
2
|
|
3
|
3
|
from EditorialModel.components import EmComponent, EmComponentNotExistError
|
4
|
|
-from Database.sqlobject import SqlObject
|
|
4
|
+from Database import sqlutils
|
|
5
|
+import sqlalchemy as sql
|
5
|
6
|
|
6
|
7
|
import EditorialModel
|
7
|
8
|
|
|
@@ -33,16 +34,31 @@ class EmFieldGroup(EmComponent):
|
33
|
34
|
try:
|
34
|
35
|
exists = EmFieldGroup(name)
|
35
|
36
|
except EmComponentNotExistError:
|
36
|
|
- uids = SqlObject('uids')
|
37
|
|
- res = uids.wexec(uids.table.insert().values(table=EmFieldGroup.table))
|
38
|
|
- uid = res.inserted_primary_key
|
39
|
|
-
|
40
|
|
- emfieldgroup = SqlObject(EmFieldGroup.table)
|
41
|
|
- res = emfieldgroup.wexec(emfieldgroup.table.insert().values(uid=uid, name=name, class_id=em_class.id))
|
42
|
|
- return EmFieldGroup(name)
|
|
37
|
+ return EmFieldGroup._createDb(name, em_class)
|
43
|
38
|
|
44
|
39
|
return exists
|
45
|
40
|
|
|
41
|
+ @classmethod
|
|
42
|
+ def _createDb(c,name, em_class):
|
|
43
|
+ """ Make the Db insertion for fieldgroup creation """
|
|
44
|
+ dbe = c.getDbE()
|
|
45
|
+ #Create a new uid
|
|
46
|
+ uids = sql.Table('uids', sqlutils.meta(dbe))
|
|
47
|
+ conn = dbe.connect()
|
|
48
|
+ req = uids.insert(values={'table': c.table})
|
|
49
|
+ res = conn.execute(req)
|
|
50
|
+ uid = res.inserted_primary_key
|
|
51
|
+
|
|
52
|
+ req = sql.Table(c.table, sqlutils.meta(dbe)).insert().values(uid=uid, name=name, class_id=em_class.id)
|
|
53
|
+ res = conn.execute(req)
|
|
54
|
+
|
|
55
|
+ conn.close()
|
|
56
|
+
|
|
57
|
+ return EmFieldGroup(name)
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
46
|
62
|
""" Use dictionary (from database) to populate the object
|
47
|
63
|
"""
|
48
|
64
|
def populate(self):
|