|
@@ -19,6 +19,7 @@ import logging
|
19
|
19
|
|
20
|
20
|
logger = logging.getLogger('Lodel2.EditorialModel')
|
21
|
21
|
|
|
22
|
+
|
22
|
23
|
## EmField (Class)
|
23
|
24
|
#
|
24
|
25
|
# Represents one data for a lodel2 document
|
|
@@ -55,29 +56,29 @@ class EmField(EmComponent):
|
55
|
56
|
# @see EmComponent::__init__()
|
56
|
57
|
# @staticmethod
|
57
|
58
|
@classmethod
|
58
|
|
- def create(c, name, fieldgroup, fieldtype, optional=0, internal=0, rel_to_type_id=0, rel_field_id=0, icon=0):
|
|
59
|
+ def create(cls, name, fieldgroup, fieldtype, optional=0, internal=0, rel_to_type_id=0, rel_field_id=0, icon=0):
|
59
|
60
|
try:
|
60
|
61
|
exists = EmField(name)
|
61
|
62
|
except EmComponentNotExistError:
|
62
|
63
|
values = {
|
63
|
|
- 'name' : name,
|
64
|
|
- 'fieldgroup_id' : fieldgroup.uid,
|
65
|
|
- 'fieldtype' : fieldtype.name,
|
66
|
|
- 'optional' : optional,
|
67
|
|
- 'internal' : internal,
|
|
64
|
+ 'name': name,
|
|
65
|
+ 'fieldgroup_id': fieldgroup.uid,
|
|
66
|
+ 'fieldtype': fieldtype.name,
|
|
67
|
+ 'optional': optional,
|
|
68
|
+ 'internal': internal,
|
68
|
69
|
'rel_to_type_id': rel_to_type_id,
|
69
|
70
|
'rel_field_id': rel_field_id,
|
70
|
71
|
'icon': icon
|
71
|
72
|
}
|
72
|
73
|
|
73
|
|
- createdField = super(EmField,c).create(**values)
|
74
|
|
- if createdField:
|
|
74
|
+ created_field = super(EmField, cls).create(**values)
|
|
75
|
+ if created_field:
|
75
|
76
|
# The field was created, we then add its column in the corresponding class' table
|
76
|
|
- is_field_column_added = createdField.addFieldColumnToClassTable()
|
|
77
|
+ is_field_column_added = created_field.add_field_column_to_class_table()
|
77
|
78
|
if is_field_column_added:
|
78
|
|
- return createdField
|
|
79
|
+ return created_field
|
79
|
80
|
|
80
|
|
- exists = createdField
|
|
81
|
+ exists = created_field
|
81
|
82
|
|
82
|
83
|
return exists
|
83
|
84
|
|
|
@@ -92,14 +93,13 @@ class EmField(EmComponent):
|
92
|
93
|
sqlutils.ddl_execute(ddl, self.__class__.getDbE())
|
93
|
94
|
return super(EmField, self).delete()
|
94
|
95
|
|
95
|
|
-
|
96
|
|
- ## addFieldColumnToClassTable (Function)
|
|
96
|
+ ## add_field_column_to_class_table (Function)
|
97
|
97
|
#
|
98
|
98
|
# Adds a column representing the field in its class' table
|
99
|
99
|
#
|
100
|
100
|
# @param emField EmField: the object representing the field
|
101
|
101
|
# @return True in case of success, False if not
|
102
|
|
- def addFieldColumnToClassTable(self):
|
|
102
|
+ def add_field_column_to_class_table(self):
|
103
|
103
|
field_type = "%s%s" % (EditorialModel.fieldtypes.get_field_type(self.fieldtype).sql_column(), " DEFAULT 0" if self.fieldtype=='integer' else '')
|
104
|
104
|
field_uid = self.uid
|
105
|
105
|
field_class_table = self.get_class_table()
|