mirror of
https://github.com/yweber/lodel2.git
synced 2026-01-07 07:42:14 +01:00
Implements _LeObject.link_remove() and LeType.unlink_subordinate()
This commit is contained in:
parent
70c237d65f
commit
a5996dc419
2 changed files with 28 additions and 0 deletions
|
|
@ -144,6 +144,9 @@ class _LeObject(object):
|
|||
# @throw LeObjectError if the link is not valid
|
||||
# @throw AttributeError if an non existing relation attribute is given as argument
|
||||
# @throw ValueError if the relation attrivute value check fails
|
||||
#
|
||||
# @todo Code factorisation on relation check
|
||||
# @todo unit tests
|
||||
@classmethod
|
||||
def link_together(cls, lesup, lesub, **rel_attr):
|
||||
if lesub.__class__ not in lesup._linked_types.keys():
|
||||
|
|
@ -162,6 +165,9 @@ class _LeObject(object):
|
|||
# @param leo_is_superior bool : if True leo is the superior in the relation
|
||||
# @return A dict with LeType child class instance as key and dict {rel_attr_name:rel_attr_value, ...}
|
||||
# @throw LeObjectError if the relation is not possible
|
||||
#
|
||||
# @todo Code factorisation on relation check
|
||||
# @todo unit tests
|
||||
@classmethod
|
||||
def linked_together(cls, leo, letype, leo_is_superior = True):
|
||||
valid_link = letype in leo._linked_types.keys() if leo_is_superior else leo.__class__ in letype._linked_types.keys()
|
||||
|
|
@ -174,6 +180,21 @@ class _LeObject(object):
|
|||
|
||||
return cls._datasource.get_related(leo, letype, leo_is_superior)
|
||||
|
||||
## @brief Remove a link (and attributes) between two LeObject
|
||||
# @param lesup LeType : LeType child instance
|
||||
# @param lesub LeType : LeType child instance
|
||||
# @return True if a link has been deleted
|
||||
# @throw LeObjectError if the relation between the two LeObject is not possible
|
||||
#
|
||||
# @todo Code factorisation on relation check
|
||||
# @todo unit tests
|
||||
@classmethod
|
||||
def link_remove(cls, lesup, lesub):
|
||||
if lesub.__class__ not in lesup._linked_types.keys():
|
||||
raise LeObjectError("Relation errorr : %s cannot be linked with %s"%(lesup.__class__.__name__, lesub.__class__.__name__))
|
||||
|
||||
return cls._datasource.del_related(lesup, lesub)
|
||||
|
||||
## @brief Prepare a field_list
|
||||
# @param field_list list : List of string representing fields
|
||||
# @param letype LeType : LeType child class
|
||||
|
|
|
|||
|
|
@ -138,6 +138,13 @@ class LeType(object):
|
|||
def linked_subordinates(self, letype):
|
||||
return leobject.lefactory.LeFactory.leobj_from_name('LeObject').linked_together(self, letype, True)
|
||||
|
||||
## @brief Remove a link with a subordinate
|
||||
# @param leo LeType : LeType child instance
|
||||
# @return True if a link has been deleted
|
||||
# @throw LeObjectError if the relation between the two LeObject is not possible
|
||||
def unlink_subordinate(self, leo):
|
||||
return leobject.lefactory.LeFactory.leobj_from_name('LeObject').linked_together(self, leo)
|
||||
|
||||
## @brief Remove a link bewteen this object and another
|
||||
# @param leo LeType : LeType child class instance
|
||||
# @todo unit tests
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue