Browse Source

[#12] Modification de EmField pour supprimer le populate et le save et debugger le process de création de champ

Roland Haroutiounian 10 years ago
parent
commit
4e8074cfbb
1 changed files with 8 additions and 48 deletions
  1. 8
    48
      EditorialModel/fields.py

+ 8
- 48
EditorialModel/fields.py View File

@@ -59,6 +59,9 @@ class EmField(EmComponent):
59 59
                 'fieldtype' : em_fieldtype.name,
60 60
                 'optional' : 1 if optional else 0,
61 61
                 'internal' : 1 if internal else 0,
62
+                'rel_to_type_id': 0,
63
+                'rel_field_id': 0,
64
+                'icon':0
62 65
             }
63 66
 
64 67
             createdField = super(EmField,c).create(**values)
@@ -83,13 +86,10 @@ class EmField(EmComponent):
83 86
     # @return True in case of success, False if not
84 87
     @classmethod
85 88
     def addFieldColumnToClassTable(c, emField):
86
-        field_type = EditorialModel.fieldtypes.get_field_type(emField.em_fieldtype)
87
-        field_sqlalchemy_args = field_type.sqlalchemy_args()
88
-        field_sqlalchemy_args['name'] = emField.name
89
-        field_sqlalchemy_column_object = sqlwrapper.createColumn(**field_sqlalchemy_args)
89
+        field_type = "%s%s" % (EditorialModel.fieldtypes.get_field_type(emField.fieldtype).sql_column(), " DEFAULT 0" if emField.fieldtype=='integer' else '')
90 90
         field_uid = emField.uid
91 91
         field_class_table = emField.get_class_table()
92
-        return sqlwrapper.addColumnObject(tname=field_class_table, column=field_sqlalchemy_column_object)
92
+        return SqlWrapper().addColumn(tname=field_class_table, colname=emField.name, coltype=field_type)
93 93
 
94 94
     ## get_class_table (Function)
95 95
     #
@@ -108,14 +108,9 @@ class EmField(EmComponent):
108 108
         dbe = self.getDbE()
109 109
         uidtable = sql.Table('uids', sqlutils.meta(dbe))
110 110
         conn = dbe.connect()
111
-        sql_wrapper = SqlWrapper(read_db='default', write_db='default', alchemy_logs=False)
112
-        columns=('table')
113
-        query_builder = SqlQueryBuilder(sql_wrapper,'uids')
114
-        query_builder.Select(columns)
115
-        query_builder.From(uidtable)
116
-        query_builder.Where('uids.uid=%s' % self.uid)
117
-
118
-        records = query_builder.Execute().fetchall()
111
+        req = uidtable.select().where(uidtable.c.uid==self.uid)
112
+        records = conn.execute(req).fetchall()
113
+
119 114
         table_records = []
120 115
         for record in records:
121 116
             table_records.append(dict(zip(record.keys(), record)))
@@ -124,38 +119,3 @@ class EmField(EmComponent):
124 119
 
125 120
         return table_name
126 121
 
127
-    ## Populate (Function)
128
-    #
129
-    # Sets the object's properties using the values from the database
130
-    def populate(self):
131
-        row = super(EmField, self).populate()
132
-        self.fieldtype = EditorialModel.fieldtypes.get_field_type(row.fieldtype)
133
-        self.fieldgroup_id = EmFieldGroup(int(row.fieldgroup_id)).uid
134
-        self.optional = True if row.optional == 1 else False
135
-        self.internal = True if row.internal == 1 else False
136
-        self.icon = row.icon
137
-        self.rel_to_type_id = EditorialModel.fieldtypes.EmFieldType(int(row.rel_to_type_id)) if row.rel_to_type_id else None
138
-        self.rel_field_id = EmField(int(row.rel_field_id)) if row.rel_field_id else None
139
-
140
-    ## Save (Function)
141
-    #
142
-    # Saves the properties of the object as a record in the database
143
-    #
144
-    # @return True in case of success, False if not
145
-    def save(self):
146
-        # should not be here, but cannot see how to do this
147
-        if self.name is None:
148
-            self.populate()
149
-
150
-        values = {
151
-            'fieldgroup_id' : self.fieldgroup.id,
152
-            'fieldtype' : self.fieldtype.name,
153
-            'optional' : 1 if self.optional else 0,
154
-            'internal' : 1 if self.internal else 0,
155
-            'icon' : self.icon,
156
-            'rel_to_type_id' : self.rel_to_type_id.id if self.rel_to_type_id is not None else None,
157
-            'rel_field_id' : self.rel_field_id.id if self.rel_field_id is not None else None
158
-        }
159
-
160
-        return super(EmField, self).save(values)
161
-

Loading…
Cancel
Save