1
0
Fork 0
mirror of https://github.com/yweber/lodel2.git synced 2025-11-30 08:36:53 +01:00

Changed the way of complete arguement is interpreted in fieldtypes() and fieldlist() method

This commit is contained in:
Yann 2016-01-21 16:59:45 +01:00
commit 2b2e219549
5 changed files with 16 additions and 27 deletions

View file

@ -18,14 +18,19 @@ class _LeClass(_LeObject):
_class_id = None
## @brief Stores the classtype
_classtype = None
## @brief Return a dict with fieldname as key and a fieldtype instance as value
# @note not optimised at all
@classmethod
def fieldtypes(cls, complete=True):
ret = dict()
if complete:
ret = dict()
ret.update(super().fieldtypes())
ret.update(cls._fieldtypes)
return ret
ret.update(cls._fieldtypes)
return ret
else:
leobject = cls.name2class('LeObject')
return { fname: cls._fieldtypes[fname] for fname in cls._fieldtypes if fname not in leobject.fieldtypes().keys() }
@classmethod
def fieldlist(cls, complete=True):

View file

@ -149,7 +149,7 @@ class {classname}(LeRel2Type):
type_fields = list()
type_superiors = list()
for field in emtype.fields(relational=False):
if not hasattr(field, 'immutable') or not field.immutable:
if not field.name in EditorialModel.classtypes.common_fields:
type_fields.append(field.name)
for nat, sup_l in emtype.superiors().items():

View file

@ -28,22 +28,10 @@ class LeClassTestCase(TestCase):
for leclass in [ Publication, Personnes, Textes ]:
for fieldname in leclass.fieldlist(complete = False):
ftype = leclass.fieldtypes()[fieldname]
if hasattr(ftype, 'immutable'):
if ftype.immutable:
self.assertNotIn(
fieldname,
LeObject.fieldlist()
)
else:
self.assertIn(
fieldname,
LeObject.fieldlist()
)
else:
self.assertNotIn(
fieldname,
LeObject.fieldlist()
)
self.assertNotIn(
fieldname,
LeObject.fieldlist()
)
for obj_fname in LeObject.fieldlist():
self.assertIn(
obj_fname,

View file

@ -104,7 +104,7 @@ class TestLeFactory(TestCase):
)
#Testing _fields
expected_fields = [ f for f in emtype.fields(relational=False) if not(hasattr(f, 'immutable') and f.immutable) ]
expected_fields = [ f for f in emtype.fields(relational=False) if f.name not in EditorialModel.classtypes.common_fields.keys() ]
self.assertEqual(
set([ f.name for f in expected_fields ]),
set([ f for f in letype._fields])

View file

@ -72,11 +72,7 @@ class LeTypeTestCase(TestCase):
for fname in letype.fieldlist(complete = False):
self.assertIn(fname, letype._leclass.fieldlist(False))
ftype = letype.fieldtypes()[fname]
if hasattr(ftype, 'immutable'):
if ftype.immutable:
self.assertNotIn(fname, LeObject.fieldlist())
else:
self.assertIn(fname, LeObject.fieldlist())
self.assertNotIn(fname, LeObject.fieldlist())
def test_fieldtypes(self):
""" Test fieldtypes() method """