Skip to content

Commit

Permalink
Adding deletion of item in Collection
Browse files Browse the repository at this point in the history
  • Loading branch information
PonteIneptique committed Feb 23, 2017
1 parent 0d32638 commit 1a6fdbb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
2 changes: 1 addition & 1 deletion MyCapytain/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
"""

__version__ = "2.0.0b13"
__version__ = "2.0.0b16"
23 changes: 19 additions & 4 deletions MyCapytain/resources/prototypes/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,16 +200,31 @@ def __add_member__(self, member):
self.children[member.id] = member
#self.graph.add((self.asNode(), NAMESPACES.DTS.child, member.asNode()))

def __getitem__(self, item):
def __getitem__(self, key):
""" Retrieve an item by its ID in the tree of a collection
:param item:
:param key: Key of the object to delete
:return: Collection identified by the item
"""
for obj in self.descendants + [self]:
if obj.id == item:
if obj.id == key:
return obj
raise UnknownCollection("%s is not part of this object" % item)
raise UnknownCollection("%s is not part of this object" % key)

def __delitem__(self, key):
""" Delete a children of the collection
:param key: Key of the object to delete
"""
item = self[key]
# Delete the graph Item
self.graph.remove((item.asNode(), None, None))
self.graph.remove((None, None, item.asNode()))
self.graph.remove((item.metadata.asNode(), None, None))
self.graph.remove((None, None, item.metadata.asNode()))
# Delete the Python item
if len(item.parents) > 0:
del item.parents[0].children[item.id]

def __contains__(self, item):
""" Retrieve an item by its ID in the tree of a collection
Expand Down

0 comments on commit 1a6fdbb

Please sign in to comment.