diff --git a/server/cp/set_byline_on_publish.py b/server/cp/set_byline_on_publish.py index 50727b18..b00dbbe9 100644 --- a/server/cp/set_byline_on_publish.py +++ b/server/cp/set_byline_on_publish.py @@ -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) diff --git a/server/tests/set_byline_on_publish_test.py b/server/tests/set_byline_on_publish_test.py index 93de5df4..12f9e2d7 100644 --- a/server/tests/set_byline_on_publish_test.py +++ b/server/tests/set_byline_on_publish_test.py @@ -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"]