|
@@ -1,20 +1,16 @@
|
1
|
1
|
#-*- coding: utf-8 -*-
|
2
|
2
|
|
3
|
3
|
from EditorialModel.components import EmComponent, EmComponentNotExistError
|
4
|
|
-from EditorialModel.fieldtypes import *
|
5
|
|
-from EditorialModel.fields_types import Em_Field_Type
|
|
4
|
+from EditorialModel.fieldtypes import EmField_boolean, EmField_char, EmField_integer, get_field_type
|
6
|
5
|
from EditorialModel.fieldgroups import EmFieldGroup
|
7
|
6
|
from EditorialModel.classes import EmClass
|
8
|
|
-from EditorialModel.types import EmType
|
9
|
7
|
|
10
|
8
|
from Database import sqlutils
|
11
|
9
|
from Database.sqlwrapper import SqlWrapper
|
12
|
|
-from Database.sqlquerybuilder import SqlQueryBuilder
|
13
|
10
|
from Database.sqlalter import DropColumn
|
14
|
11
|
|
15
|
12
|
import sqlalchemy as sql
|
16
|
13
|
|
17
|
|
-import EditorialModel
|
18
|
14
|
import logging
|
19
|
15
|
|
20
|
16
|
logger = logging.getLogger('Lodel2.EditorialModel')
|
|
@@ -73,7 +69,6 @@ class EmField(EmComponent):
|
73
|
69
|
|
74
|
70
|
created_field = super(EmField, cls).create(**values)
|
75
|
71
|
if created_field:
|
76
|
|
- # The field was created, we then add its column in the corresponding class' table
|
77
|
72
|
is_field_column_added = created_field.add_field_column_to_class_table()
|
78
|
73
|
if is_field_column_added:
|
79
|
74
|
return created_field
|
|
@@ -81,7 +76,7 @@ class EmField(EmComponent):
|
81
|
76
|
exists = created_field
|
82
|
77
|
|
83
|
78
|
return exists
|
84
|
|
-
|
|
79
|
+
|
85
|
80
|
## @brief Delete a field if it's not linked
|
86
|
81
|
# @return bool : True if deleted False if deletion aborded
|
87
|
82
|
# @todo Check if unconditionnal deletion is correct
|
|
@@ -92,7 +87,7 @@ class EmField(EmComponent):
|
92
|
87
|
ddl = DropColumn(class_table, field_col)
|
93
|
88
|
sqlutils.ddl_execute(ddl, self.__class__.db_engine())
|
94
|
89
|
return super(EmField, self).delete()
|
95
|
|
-
|
|
90
|
+
|
96
|
91
|
## add_field_column_to_class_table (Function)
|
97
|
92
|
#
|
98
|
93
|
# Adds a column representing the field in its class' table
|
|
@@ -100,7 +95,7 @@ class EmField(EmComponent):
|
100
|
95
|
# @param emField EmField: the object representing the field
|
101
|
96
|
# @return True in case of success, False if not
|
102
|
97
|
def add_field_column_to_class_table(self):
|
103
|
|
- field_type = "%s%s" % (EditorialModel.fieldtypes.get_field_type(self.fieldtype).sql_column(), " DEFAULT 0" if self.fieldtype=='integer' else '')
|
|
98
|
+ field_type = "%s%s" % (get_field_type(self.fieldtype).sql_column(), " DEFAULT 0" if self.fieldtype == 'integer' else '')
|
104
|
99
|
field_uid = self.uid
|
105
|
100
|
field_class_table = self.get_class_table()
|
106
|
101
|
return SqlWrapper().addColumn(tname=field_class_table, colname=self.name, coltype=field_type)
|
|
@@ -121,9 +116,8 @@ class EmField(EmComponent):
|
121
|
116
|
def _get_class_table_db(self):
|
122
|
117
|
dbe = self.db_engine()
|
123
|
118
|
conn = dbe.connect()
|
124
|
|
- #fieldtable = sql.Table(EmField.table, sqlutils.meta(dbe))
|
125
|
|
- fieldgrouptable = sql.Table(EmFieldGroup.table, sqlutils.meta(dbe))
|
126
|
|
- request_get_class_id = fieldgrouptable.select().where(fieldgrouptable.c.uid == self.fieldgroup_id)
|
|
119
|
+ field_group_table = sql.Table(EmFieldGroup.table, sqlutils.meta(dbe))
|
|
120
|
+ request_get_class_id = field_group_table.select().where(field_group_table.c.uid == self.fieldgroup_id)
|
127
|
121
|
result_get_class_id = conn.execute(request_get_class_id).fetchall()
|
128
|
122
|
class_id = dict(zip(result_get_class_id[0].keys(), result_get_class_id[0]))['class_id']
|
129
|
123
|
|
|
@@ -133,4 +127,3 @@ class EmField(EmComponent):
|
133
|
127
|
class_table_name = dict(zip(result_get_class_table[0].keys(), result_get_class_table[0]))['name']
|
134
|
128
|
|
135
|
129
|
return class_table_name
|
136
|
|
-
|