def edit(self, pid=None): """Edit deposit.""" pid = pid or self.pid if 'published' != self['_deposit']['status']: raise PIDInvalidAction() def _edit(record): """Update selected keys.""" data = record.dumps() # Keep current record revision for merging. data['_deposit']['pid']['revision_id'] = record.revision_id data['_deposit']['status'] = 'draft' data['$schema'] = self.build_deposit_schema(record) return data with db.session.begin_nested(): before_record_update.send(self) record_pid, record = self.fetch_published() assert PIDStatus.REGISTERED == record_pid.status assert record['_deposit'] == self['_deposit'] self.model.json = _edit(record) flag_modified(self.model, 'json') db.session.merge(self.model) after_record_update.send(self) return self.__class__(self.model.json, model=self.model)
def edit(self, pid=None): """Edit deposit.""" pid = pid or self.pid def _edit(record): """Update selected keys.""" data = record.dumps() # Keep current record revision for merging. data['_deposit']['pid']['revision_id'] = record.revision_id data['_deposit']['status'] = 'draft' data['$schema'] = self.build_deposit_schema(record) return data with db.session.begin_nested(): before_record_update.send(self) record_pid, record = self.fetch_published() assert PIDStatus.REGISTERED == record_pid.status assert record['_deposit'] == self['_deposit'] self.model.json = _edit(record) flag_modified(self.model, 'json') db.session.merge(self.model) after_record_update.send(self) return self.__class__(self.model.json, model=self.model)
def discard(self, pid=None): """Discard deposit changes.""" pid = pid or self.pid with db.session.begin_nested(): before_record_update.send(self) _, record = self.fetch_published() self.model.json = record.model.json self.model.json['$schema'] = self.build_deposit_schema(record) flag_modified(self.model, 'json') db.session.merge(self.model) after_record_update.send(self) return self.__class__(self.model.json, model=self.model)
def edit(self, pid=None): """Edit deposit. #. The signal :data:`invenio_records.signals.before_record_update` is sent before the edit execution. #. The following meta information are saved inside the deposit: .. code-block:: python deposit['_deposit']['pid'] = record.revision_id deposit['_deposit']['status'] = 'draft' deposit['$schema'] = deposit_schema_from_record_schema #. The signal :data:`invenio_records.signals.after_record_update` is sent after the edit execution. #. The deposit index is updated. Status required: `published`. .. note:: the process fails if the pid has status :attr:`invenio_pidstore.models.PIDStatus.REGISTERED`. :param pid: Force a pid object. (Default: ``None``) :returns: A new Deposit object. """ pid = pid or self.pid with db.session.begin_nested(): before_record_update.send(current_app._get_current_object(), record=self) record_pid, record = self.fetch_published() assert PIDStatus.REGISTERED == record_pid.status assert record['_deposit'] == self['_deposit'] self.model.json = self._prepare_edit(record) flag_modified(self.model, 'json') db.session.merge(self.model) after_record_update.send(current_app._get_current_object(), record=self) return self.__class__(self.model.json, model=self.model)
def edit(self, pid=None): """Edit deposit.""" pid = pid or self.pid with db.session.begin_nested(): before_record_update.send(self) record_pid, record = self.fetch_published() assert PIDStatus.REGISTERED == record_pid.status assert record['_deposit'] == self['_deposit'] self.model.json = self._prepare_edit(record) flag_modified(self.model, 'json') db.session.merge(self.model) after_record_update.send(self) return self.__class__(self.model.json, model=self.model)
def edit(self, pid=None): """Edit deposit. #. The signal :data:`invenio_records.signals.before_record_update` is sent before the edit execution. #. The following meta information are saved inside the deposit: .. code-block:: python deposit['_deposit']['pid'] = record.revision_id deposit['_deposit']['status'] = 'draft' deposit['$schema'] = deposit_schema_from_record_schema #. The signal :data:`invenio_records.signals.after_record_update` is sent after the edit execution. #. The deposit index is updated. Status required: `published`. .. note:: the process fails if the pid has status :attr:`invenio_pidstore.models.PIDStatus.REGISTERED`. :param pid: Force a pid object. (Default: ``None``) :returns: A new Deposit object. """ pid = pid or self.pid with db.session.begin_nested(): before_record_update.send(self) record_pid, record = self.fetch_published() assert PIDStatus.REGISTERED == record_pid.status assert record['_deposit'] == self['_deposit'] self.model.json = self._prepare_edit(record) flag_modified(self.model, 'json') db.session.merge(self.model) after_record_update.send(self) return self.__class__(self.model.json, model=self.model)
def discard(self, pid=None): """Discard deposit changes. #. The signal :data:`invenio_records.signals.before_record_update` is sent before the edit execution. #. It restores the last published version. #. The following meta information are saved inside the deposit: .. code-block:: python deposit['$schema'] = deposit_schema_from_record_schema #. The signal :data:`invenio_records.signals.after_record_update` is sent after the edit execution. #. The deposit index is updated. Status required: ``'draft'``. :param pid: Force a pid object. (Default: ``None``) :returns: A new Deposit object. """ pid = pid or self.pid with db.session.begin_nested(): before_record_update.send(current_app._get_current_object(), record=self) _, record = self.fetch_published() self.model.json = deepcopy(record.model.json) self.model.json['$schema'] = self.build_deposit_schema(record) flag_modified(self.model, 'json') db.session.merge(self.model) after_record_update.send(current_app._get_current_object(), record=self) return self.__class__(self.model.json, model=self.model)
def discard(self, pid=None): """Discard deposit changes. #. The signal :data:`invenio_records.signals.before_record_update` is sent before the edit execution. #. It restores the last published version. #. The following meta information are saved inside the deposit: .. code-block:: python deposit['$schema'] = deposit_schema_from_record_schema #. The signal :data:`invenio_records.signals.after_record_update` is sent after the edit execution. #. The deposit index is updated. Status required: ``'draft'``. :param pid: Force a pid object. (Default: ``None``) :returns: A new Deposit object. """ pid = pid or self.pid with db.session.begin_nested(): before_record_update.send(self) _, record = self.fetch_published() self.model.json = deepcopy(record.model.json) self.model.json['$schema'] = self.build_deposit_schema(record) flag_modified(self.model, 'json') db.session.merge(self.model) after_record_update.send(self) return self.__class__(self.model.json, model=self.model)