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

Respect annotation reordering in document detail page (#1438) #1439

Merged
merged 2 commits into from
Aug 25, 2023
Merged
Show file tree
Hide file tree
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
5 changes: 4 additions & 1 deletion geniza/footnotes/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,10 @@ def content_html(self):
# keyed on canvas uri
# handle multiple annotations on the same canvas
html_content = defaultdict(list)
for a in self.annotation_set.all():
# order by optional position property (set by manual reorder in editor), then date
for a in self.annotation_set.all().order_by(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably worth a one-line comment here documenting what this is for

I checked, default ordering is by created; makes sense we wouldn't want to rely on an optional/custom parameter for sort

"content__schema:position", "created"
):
if a.label:
html_content[a.target_source_id].append(f"<h3>{a.label}</h3>")
html_content[a.target_source_id].append(a.body_content)
Expand Down
16 changes: 15 additions & 1 deletion geniza/footnotes/tests/test_footnote_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ def test_content_html(self, annotation, twoauthor_source):
canvas_uri = annotation.content["target"]["source"]["id"]
digital_edition = annotation.footnote
# create a second annotation
Annotation.objects.create(
second_annotation = Annotation.objects.create(
footnote=digital_edition,
content={
**annotation.content,
Expand All @@ -289,6 +289,20 @@ def test_content_html(self, annotation, twoauthor_source):
"<h3>A label</h3>",
"Second annotation!",
]

# should respect reordering
second_annotation.content["schema:position"] = 1
second_annotation.save()
annotation.content["schema:position"] = 2
annotation.save()
# invalidate cache
del digital_edition.content_html
assert digital_edition.content_html[canvas_uri] == [
"<h3>A label</h3>",
"Second annotation!",
"Test annotation",
]

# should return None if there are no associated annotations
edition = Footnote.objects.create(
source=digital_edition.source,
Expand Down
Loading