Browse Source

[#12] Ajout de la class Em_Field_Type et du select_field

Roland Haroutiounian 10 years ago
parent
commit
f13b6f844d
2 changed files with 54 additions and 0 deletions
  1. 11
    0
      EditorialModel/fields.py
  2. 43
    0
      EditorialModel/test/test_field.py

+ 11
- 0
EditorialModel/fields.py View File

2
 
2
 
3
 from EditorialModel.components import EmComponent, EmComponentNotExistError
3
 from EditorialModel.components import EmComponent, EmComponentNotExistError
4
 from EditorialModel.fieldtypes import *
4
 from EditorialModel.fieldtypes import *
5
+from EditorialModel.fields_types import Em_Field_Type
5
 from Database import sqlutils
6
 from Database import sqlutils
6
 from Database.sqlwrapper import SqlWrapper
7
 from Database.sqlwrapper import SqlWrapper
7
 from Database.sqlquerybuilder import SqlQueryBuilder
8
 from Database.sqlquerybuilder import SqlQueryBuilder
168
 
169
 
169
         return super(EmField, self).save(values)
170
         return super(EmField, self).save(values)
170
 
171
 
172
+
173
+    ## Select_field (Function)
174
+    #
175
+    # @param type EmType: Type to link this field to
176
+    # @return True if success, False if failure
177
+    def select_field(self, type):
178
+        if Em_Field_Type.create(self.uid, type.uid):
179
+            return True
180
+        else:
181
+            return False

+ 43
- 0
EditorialModel/test/test_field.py View File

12
 from EditorialModel.classtypes import EmClassType
12
 from EditorialModel.classtypes import EmClassType
13
 from EditorialModel.types import EmType
13
 from EditorialModel.types import EmType
14
 from EditorialModel.fieldgroups import EmFieldGroup
14
 from EditorialModel.fieldgroups import EmFieldGroup
15
+from EditorialModel.fields_types import Em_Field_Type
15
 from EditorialModel.fieldtypes import *
16
 from EditorialModel.fieldtypes import *
16
 
17
 
17
 from Database.sqlsetup import SQLSetup
18
 from Database.sqlsetup import SQLSetup
63
 
64
 
64
         pass
65
         pass
65
 
66
 
67
+
68
+    ## Get_Field_Type_Record (Function)
69
+    #
70
+    # Returns associations between field and type from the em_field_type table
71
+    #
72
+    # @param field EmField: Field object
73
+    # @param type EmType: Type object
74
+    # @return list of found associations
75
+    def get_field_type_record(self, field, type):
76
+        return self._get_field_type_record_Db(field, type)
77
+
78
+    ## _Get_Field_Type_Record_Db (Function)
79
+    #
80
+    # Queries the database to get the record from the em_field_type table corresponding to a given field and type
81
+    # @param field EmField: Field object
82
+    # @param type EmType: Type object
83
+    # @return found associations
84
+    def _get_field_type_record_Db(self, field, type):
85
+        sqlwrapper = SqlWrapper(read_db='default', write_db='default', alchemy_logs=False)
86
+        sql_builder = SqlQueryBuilder(sql_wrapper, 'em_field_type')
87
+        sql_builder.Select().From('em_field_type').Where('em_field_type.field_id=%s' % field.uid).Where('em_field_type.type_id=%s' % type.uid)
88
+        records = sql_builder.Execute().fetchall()
89
+        field_type_records = []
90
+        for record in records:
91
+            field_type_records.append(dict(zip(record.keys(),record)))
92
+
93
+        return field_type_records
94
+
95
+
66
     ## Get_Field_Records (Function)
96
     ## Get_Field_Records (Function)
67
     #
97
     #
68
     # Returns the list of fields corresponding to a given uid
98
     # Returns the list of fields corresponding to a given uid
143
         self.assertIn(field_column,field_table_columns)
173
         self.assertIn(field_column,field_table_columns)
144
         pass
174
         pass
145
 
175
 
176
+
177
+    ## Test_Select (Function)
178
+    #
179
+    # The selected field has a record in the em_field_type table
180
+    def testSelectField(self):
181
+        testType = EmType.create('testtype2',self.testClass)
182
+
183
+        field=EmField('testfield1')
184
+        field.select_field('testtype2')
185
+
186
+        field_type_object = Em_Field_Type(testType.uid, field.uid)
187
+        self.assertEqual(field_type_object.exists(),True)
188
+        pass

Loading…
Cancel
Save