Skip to content

Commit

Permalink
fix author byline handling (#323)
Browse files Browse the repository at this point in the history
when used with author roles

SDCP-772
  • Loading branch information
petrjasek authored Oct 1, 2024
1 parent e63dacb commit 0741926
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
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"]

0 comments on commit 0741926

Please sign in to comment.