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

fix author byline handling #323

Merged
merged 1 commit into from
Oct 1, 2024
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
6 changes: 5 additions & 1 deletion server/cp/set_byline_on_publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ def set_byline_on_publish(sender, item, updates, **kwargs):
if updated.get("byline") or not updated.get("authors"):
return

byline = ", ".join([author["name"] for author in item.get("authors", [])])
byline = ", ".join([get_author_name(author) for author in item.get("authors", [])])

item["byline"] = updates["byline"] = byline


def get_author_name(author) -> str:
return author.get("sub_label") or author.get("name")


def init_app(app):
item_publish.connect(set_byline_on_publish)
17 changes: 17 additions & 0 deletions server/tests/set_byline_on_publish_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,20 @@ def test_set_byline_on_publish():
set_byline_on_publish(None, item, updates)
assert item["byline"] == "foo"
assert "byline" not in updates

item = {
"authors": [
{
"_id": ["64d13ff3446949ccb5348bdc", "writer"],
"role": "writer",
"name": "Writer",
"parent": "64d13ff3446949ccb5348bdc",
"sub_label": "foo bar",
}
]
}

updates = {}
set_byline_on_publish(None, item, updates)
assert item["byline"] == "foo bar"
assert updates["byline"] == item["byline"]