Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

api: return non deleted records #259

Merged
merged 1 commit into from
Oct 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion invenio_drafts_resources/records/systemfields/versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ def parent_id(self):
"""Get versions state management model."""
return self._record.model.parent_id

@property
def record_model_cls(self):
"""Get model cls of the record/draft."""
return self._record.model_cls

@property
def index(self):
"""Get the version index of the record/draft."""
Expand Down Expand Up @@ -94,7 +99,16 @@ def is_latest_draft(self):
@property
def next_index(self):
"""Get the next parent index."""
return self.latest_index + 1 if self.latest_index is not None else 1
latest_index_by_parent = None
with db.session.no_autoflush:
rec_model = (
self.record_model_cls.query.filter_by(parent_id=self.parent_id)
.order_by(self.record_model_cls.index.desc())
.first()
)
if rec_model:
latest_index_by_parent = rec_model.index
return latest_index_by_parent + 1 if latest_index_by_parent is not None else 1

#
# State management methods
Expand Down
Loading