mirror of
https://github.com/yweber/lodel2.git
synced 2026-03-14 15:22:02 +01:00
Removing rel2type fields and rel2type attributes fields from LeClass and LeType fields lists
This commit is contained in:
parent
119b9b6f9f
commit
7b0df11496
6 changed files with 31 additions and 14 deletions
|
|
@ -81,11 +81,11 @@ class EmClass(EmComponent):
|
|||
|
||||
## Retrieve list of fields
|
||||
# @return fields [EmField]:
|
||||
def fields(self):
|
||||
def fields(self, relational = True):
|
||||
fieldgroups = self.fieldgroups()
|
||||
fields = []
|
||||
for fieldgroup in fieldgroups:
|
||||
fields += fieldgroup.fields()
|
||||
fields += fieldgroup.fields(relational=relational)
|
||||
return fields
|
||||
|
||||
## Retrieve list of type of this class
|
||||
|
|
|
|||
|
|
@ -45,9 +45,11 @@ class EmFieldGroup(EmComponent):
|
|||
|
||||
## Get the list of associated fields
|
||||
# if type_id, the fields will be filtered to represent selected fields of this EmType
|
||||
# @param type_id int|None : if not None the fields will be filtered to represent selected fields of the EmType identified by this uid
|
||||
# @param relational bool : If False don't returns the relational fields
|
||||
# @return A list of EmField instance
|
||||
def fields(self, type_id=0):
|
||||
if not type_id:
|
||||
def fields(self, type_id=None, relational=True):
|
||||
if type_id is None:
|
||||
fields = [field for field in self.model.components(EmField) if field.fieldgroup_id == self.uid]
|
||||
else:
|
||||
# for an EmType, fields have to be filtered
|
||||
|
|
@ -62,6 +64,9 @@ class EmFieldGroup(EmComponent):
|
|||
if parent.optional and parent.uid not in em_type.fields_list:
|
||||
continue
|
||||
fields.append(field)
|
||||
|
||||
if not relational:
|
||||
fields = [ f for f in fields if f.rel_field_id is None and f.fieldtype != 'rel2type' ]
|
||||
|
||||
return fields
|
||||
|
||||
|
|
|
|||
|
|
@ -179,6 +179,12 @@ class TestFields(FieldGroupTestCase):
|
|||
res.append(field.uid)
|
||||
self.assertEqual(set(res), set(expected1))
|
||||
|
||||
def test_non_relational(self):
|
||||
""" Check that relationnal=False returns only non relational fields """
|
||||
for fgrp in [ self.fg1, self.fg2, self.fg3 ]:
|
||||
for field in fgrp.fields(relational=False):
|
||||
self.assertTrue(field.fieldtype != 'rel2type' and field.rel_field_id is None)
|
||||
|
||||
def test_empty_fields(self):
|
||||
""" Testing fields method on an empty fieldgroup """
|
||||
fieldgroup = self.fg3
|
||||
|
|
|
|||
|
|
@ -101,8 +101,10 @@ class EmType(EmComponent):
|
|||
|
||||
## Return the list of associated fields
|
||||
# @return A list of EmField instance
|
||||
def fields(self):
|
||||
def fields(self, relational = False):
|
||||
fields = [field for fieldgroup in self.fieldgroups() for field in fieldgroup.fields(self.uid)]
|
||||
if not relational:
|
||||
fields = [ f for f in fields if f.rel_field_id is None and f.fieldtype != 'rel2type' ]
|
||||
return fields
|
||||
|
||||
## Select_field (Function)
|
||||
|
|
|
|||
|
|
@ -65,16 +65,20 @@ class LeFactory(object):
|
|||
def emclass_pycode(model, emclass):
|
||||
cls_fields = dict()
|
||||
cls_linked_types = list()
|
||||
for field in emclass.fields():
|
||||
#Populating linked_type attr
|
||||
for rfield in [ f for f in emclass.fields() if f.fieldtype == 'rel2type']:
|
||||
fti = rfield.fieldtype_instance()
|
||||
cls_linked_types.append(LeFactory.name2classname(model.component(fti.rel_to_type_id).name))
|
||||
# Populating fieldtype attr
|
||||
for field in emclass.fields(relational = False):
|
||||
cls_fields[field.name] = LeFactory.fieldtype_construct_from_field(field)
|
||||
fti = field.fieldtype_instance()
|
||||
if fti.name == 'rel2type':
|
||||
#relationnal field/fieldtype
|
||||
cls_linked_types.append(LeFactory.name2classname(model.component(fti.rel_to_type_id).name))
|
||||
|
||||
# Populating fieldgroup attr
|
||||
cls_fieldgroup = dict()
|
||||
for fieldgroup in emclass.fieldgroups():
|
||||
cls_fieldgroup[fieldgroup.name] = list()
|
||||
for field in fieldgroup.fields():
|
||||
for field in fieldgroup.fields(relational = False):
|
||||
cls_fieldgroup[fieldgroup.name].append(field.name)
|
||||
|
||||
return """
|
||||
|
|
@ -97,7 +101,7 @@ class LeFactory(object):
|
|||
def emtype_pycode(model, emtype):
|
||||
type_fields = list()
|
||||
type_superiors = list()
|
||||
for field in emtype.fields():
|
||||
for field in emtype.fields(relational=False):
|
||||
type_fields.append(field.name)
|
||||
|
||||
for nat, sup_l in emtype.superiors().items():
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ class TestLeFactory(TestCase):
|
|||
)
|
||||
for fgroup in emclass.fieldgroups():
|
||||
self.assertEqual(
|
||||
set([ f.name for f in fgroup.fields()]),
|
||||
set([ f.name for f in fgroup.fields(relational=False)]),
|
||||
set(leclass._fieldgroups[fgroup.name])
|
||||
)
|
||||
|
||||
|
|
@ -81,10 +81,10 @@ class TestLeFactory(TestCase):
|
|||
|
||||
#Testing fieldtypes
|
||||
self.assertEqual(
|
||||
set([ f.name for f in emclass.fields()]),
|
||||
set([ f.name for f in emclass.fields(relational=False)]),
|
||||
set(leclass._fieldtypes.keys())
|
||||
)
|
||||
for field in emclass.fields():
|
||||
for field in emclass.fields(relational=False):
|
||||
self.assertEqual(
|
||||
hash(field.fieldtype_instance()),
|
||||
hash(leclass._fieldtypes[field.name])
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue