def register(self, obj: IBaseObject, new_oid: Optional[str] = None): """We are adding a new object on the DB""" if self.read_only: raise ReadOnlyError() if self.status in (Status.ABORTED, Status.COMMITTED, Status.CONFLICT): raise TransactionClosedException(f"Could not save {obj} to closed transaction", self, obj) if obj.__txn__ is None: obj.__txn__ = self oid = obj.__uuid__ new = False if oid is None: if new_oid is not None: new = True else: new_oid = app_settings["uid_generator"](obj) oid = new_oid obj.__uuid__ = oid if new or obj.__new_marker__: if obj.__parent__ is not None and hasattr(obj, "id"): self.added_children[(obj.__parent__.__uuid__, obj.id)] = obj.__uuid__ self.added[oid] = obj elif oid in self.modified: if id(obj) != id(self.modified[oid]): raise TransactionObjectRegistrationMismatchException(self.modified[oid], obj) elif oid not in self.added: self.modified[oid] = obj
def delete(self, obj: IBaseObject): if self.read_only: raise ReadOnlyError() oid = obj.__uuid__ if oid is not None: if oid in self.modified: del self.modified[oid] elif oid in self.added: del self.added[oid] self.deleted[oid] = obj
def check_read_only(self): if self.request is None: try: self.request = get_current_request() except RequestNotFound: return False if hasattr(self.request, '_db_write_enabled') and not self.request._db_write_enabled: raise Unauthorized('Adding content not permited') # Add the new tid if self._manager._storage._read_only: raise ReadOnlyError()
def register(self, obj: IBaseObject, new_oid: Optional[str] = None): """We are adding a new object on the DB""" if self.read_only: raise ReadOnlyError() if obj.__txn__ is None: obj.__txn__ = self oid = obj.__uuid__ new = False if oid is None: if new_oid is not None: new = True else: new_oid = app_settings['uid_generator'](obj) oid = new_oid obj.__uuid__ = oid if new or obj.__new_marker__: self.added[oid] = obj elif oid not in self.modified and oid not in self.added: self.modified[oid] = obj