Skip to content

Commit

Permalink
atom: tweak author name rendering in attachments
Browse files Browse the repository at this point in the history
...specifically, use a smaller version that doesn't include picture
  • Loading branch information
snarfed committed Mar 24, 2017
1 parent 8bc5b79 commit 8652ef6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
4 changes: 3 additions & 1 deletion granary/atom.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ def activities_to_atom(activities, actor, title=None, request_url=None,
html = microformats2.render_content(att)
author = att.get('author')
if author:
html = '%s: %s' % (microformats2.object_to_html(author).strip(), html)
name = microformats2.maybe_linked_name(
microformats2.object_to_json(author).get('properties', []))
html = '%s: %s' % (name.strip(), html)
obj['rendered_children'].append(_encode_ampersands(html))

# Emulate Django template behavior that returns a special default value that
Expand Down
16 changes: 10 additions & 6 deletions granary/test/test_atom.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,15 @@ def test_attachments(self):
got = atom.activities_to_atom([{'object': {'attachments': [
{'objectType': 'note', 'url': 'http://p', 'content': 'note content'},
{'objectType': 'x', 'url': 'http://x'},
{'objectType': 'article', 'url': 'http://a', 'content': 'article content',
'author': {'displayName': 'Mr. Foo', 'url': 'http://x/', 'objectType': 'person'},
{'objectType': 'article',
'url': 'http://a',
'content': 'article content',
'author': {
'displayName': 'Mr. Foo',
'url': 'http://x/',
# image shouldn't be included
'image': {'url': 'http://x/avatar.jpg'},
},
},
]}}], None)
self.assert_multiline_in("""
Expand All @@ -184,10 +191,7 @@ def test_attachments(self):
""", got)
self.assert_multiline_in("""
<blockquote>
<span class="h-card">
<a class="p-name u-url" href="http://x/">Mr. Foo</a>
</span>: article content
<a class="p-name u-url" href="http://x/">Mr. Foo</a>: article content
</blockquote>
""", got)

Expand Down

0 comments on commit 8652ef6

Please sign in to comment.