- def add(self, key, *args, **kwargs):
- r"add(key, ...) -> None :: Add an item to the dict."
- item = self._dict_subhandler_class(key, *args, **kwargs)
- if key in self._dict():
- raise ItemAlreadyExistsError(key)
- self._dict()[key] = item
+ def add(self, cont, *args, **kwargs):
+ r"add(cont, ...) -> None :: Add an item to the list."
+ if not cont in self._cont():
+ raise ContainerNotFoundError(cont)
+ item = self._comp_subhandler_class(*args, **kwargs)
+ if hasattr(item, '_add'):
+ item._add = True
+ key = item
+ if isinstance(self._attr(cont), dict):
+ key = item.as_tuple()[0]
+ # do we have the same item? then raise an error
+ if key in self._vattr(cont):
+ raise ItemAlreadyExistsError(item)
+ # do we have the same item, but logically deleted? then update flags
+ if key in self._attr(cont):
+ index = key
+ if not isinstance(self._attr(cont), dict):
+ index = self._attr(cont).index(item)
+ if hasattr(item, '_add'):
+ self._attr(cont)[index]._add = False
+ if hasattr(item, '_delete'):
+ self._attr(cont)[index]._delete = False
+ else: # it's *really* new
+ if isinstance(self._attr(cont), dict):
+ self._attr(cont)[key] = item
+ else:
+ self._attr(cont).append(item)
+ if hasattr(self._cont()[cont], '_update'):
+ self._cont()[cont]._update = True