1
0
Fork 0
mirror of https://github.com/yweber/lodel2.git synced 2026-06-13 22:20:47 +02:00

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

This commit is contained in:
Roland Haroutiounian 2015-06-19 11:57:58 +02:00
commit f13b6f844d
2 changed files with 54 additions and 0 deletions

View file

@ -2,6 +2,7 @@
from EditorialModel.components import EmComponent, EmComponentNotExistError
from EditorialModel.fieldtypes import *
from EditorialModel.fields_types import Em_Field_Type
from Database import sqlutils
from Database.sqlwrapper import SqlWrapper
from Database.sqlquerybuilder import SqlQueryBuilder
@ -168,3 +169,13 @@ class EmField(EmComponent):
return super(EmField, self).save(values)
## Select_field (Function)
#
# @param type EmType: Type to link this field to
# @return True if success, False if failure
def select_field(self, type):
if Em_Field_Type.create(self.uid, type.uid):
return True
else:
return False

View file

@ -12,6 +12,7 @@ from EditorialModel.classes import EmClass
from EditorialModel.classtypes import EmClassType
from EditorialModel.types import EmType
from EditorialModel.fieldgroups import EmFieldGroup
from EditorialModel.fields_types import Em_Field_Type
from EditorialModel.fieldtypes import *
from Database.sqlsetup import SQLSetup
@ -63,6 +64,35 @@ class FieldTestCase(TestCase):
pass
## Get_Field_Type_Record (Function)
#
# Returns associations between field and type from the em_field_type table
#
# @param field EmField: Field object
# @param type EmType: Type object
# @return list of found associations
def get_field_type_record(self, field, type):
return self._get_field_type_record_Db(field, type)
## _Get_Field_Type_Record_Db (Function)
#
# Queries the database to get the record from the em_field_type table corresponding to a given field and type
# @param field EmField: Field object
# @param type EmType: Type object
# @return found associations
def _get_field_type_record_Db(self, field, type):
sqlwrapper = SqlWrapper(read_db='default', write_db='default', alchemy_logs=False)
sql_builder = SqlQueryBuilder(sql_wrapper, 'em_field_type')
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)
records = sql_builder.Execute().fetchall()
field_type_records = []
for record in records:
field_type_records.append(dict(zip(record.keys(),record)))
return field_type_records
## Get_Field_Records (Function)
#
# Returns the list of fields corresponding to a given uid
@ -143,3 +173,16 @@ class TestField(FieldTestCase):
self.assertIn(field_column,field_table_columns)
pass
## Test_Select (Function)
#
# The selected field has a record in the em_field_type table
def testSelectField(self):
testType = EmType.create('testtype2',self.testClass)
field=EmField('testfield1')
field.select_field('testtype2')
field_type_object = Em_Field_Type(testType.uid, field.uid)
self.assertEqual(field_type_object.exists(),True)
pass