Object.actor_link: add sized kwarg

pull/676/head
Ryan Barrett 2023-10-12 10:19:59 -07:00
rodzic 7e56f9e115
commit 8f4c353936
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 6BE31FDF4776E9D4
2 zmienionych plików z 24 dodań i 3 usunięć

Wyświetl plik

@ -843,8 +843,16 @@ class Object(StringIdModel):
protocol = PROTOCOLS.get(self.source_protocol) or Protocol
return protocol.subdomain_url(f'convert/web/{id}')
def actor_link(self):
"""Returns a pretty actor link with their name and profile picture."""
def actor_link(self, sized=False):
"""Returns a pretty HTML link with the actor's name and picture.
Args:
sized (bool): if True, sets an explicit size (``width=32``) on the
profile picture ``img` tag
Returns:
str:
"""
attrs = {'class': 'h-card u-author'}
if (self.source_protocol in ('web', 'webmention', 'ui') and g.user
@ -877,7 +885,7 @@ class Object(StringIdModel):
return f"""\
<a class="h-card u-author" href="{url}" title="{name}">
<img class="profile" src="{image}" />
<img class="profile" src="{image}" {'width="32"' if sized else ''}/>
{util.ellipsize(name, chars=40)}
</a>"""

Wyświetl plik

@ -422,6 +422,19 @@ class ObjectTest(TestCase):
obj = Object(id='x', source_protocol='fake', our_as1={'actor': 'fake:alice'})
self.assertIn('Alice', obj.actor_link())
def test_actor_link_sized(self):
obj = Object(id='x', our_as1={
'actor': {
'displayName': 'Alice',
'image': 'foo.jpg',
},
})
self.assert_multiline_equals("""\
<a class="h-card u-author" href="" title="Alice">
<img class="profile" src="foo.jpg" width="32"/>
Alice
</a>""", obj.actor_link(sized=True))
def test_put_updates_load_cache(self):
obj = Object(id='x', as2={})
obj.put()