Merge branch 'master' of github.com:mozilla/olympia
This commit is contained in:
Коммит
10914bae03
|
@ -8,7 +8,7 @@
|
|||
</tr>
|
||||
<tr class="artist">
|
||||
<th>{{ _('Artist') }}</th>
|
||||
<td>{{ users_list(addon.listed_authors) or
|
||||
<td>{{ users_list(addon.listed_authors, max_text_length=20) or
|
||||
persona.display_username }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
import random
|
||||
|
||||
from django.conf import settings
|
||||
from django.utils.encoding import smart_unicode
|
||||
|
||||
import jinja2
|
||||
|
@ -42,7 +41,7 @@ def user_link(user):
|
|||
|
||||
|
||||
@register.function
|
||||
def users_list(users, size=None):
|
||||
def users_list(users, size=None, max_text_length=None):
|
||||
if not users:
|
||||
return ''
|
||||
|
||||
|
@ -51,7 +50,12 @@ def users_list(users, size=None):
|
|||
users = users[:size]
|
||||
tail = [_('others', 'user_list_others')]
|
||||
|
||||
return jinja2.Markup(', '.join(map(_user_link, users) + tail))
|
||||
if max_text_length:
|
||||
user_list = [_user_link(user, max_text_length) for user in users]
|
||||
else:
|
||||
user_list = map(_user_link, users)
|
||||
|
||||
return jinja2.Markup(', '.join(user_list + tail))
|
||||
|
||||
|
||||
@register.inclusion_tag('users/helpers/addon_users_list.html')
|
||||
|
@ -62,11 +66,17 @@ def addon_users_list(context, addon):
|
|||
return ctx
|
||||
|
||||
|
||||
def _user_link(user):
|
||||
def _user_link(user, max_text_length=None):
|
||||
if isinstance(user, basestring):
|
||||
return user
|
||||
return u'<a href="%s">%s</a>' % (
|
||||
user.get_url_path(), jinja2.escape(smart_unicode(user.name)))
|
||||
|
||||
username = user.name
|
||||
if max_text_length and len(user.name) > max_text_length:
|
||||
username = user.name[:max_text_length].strip() + '...'
|
||||
|
||||
return u'<a href="%s" title="%s">%s</a>' % (
|
||||
user.get_url_path(), user.name,
|
||||
jinja2.escape(smart_unicode(username)))
|
||||
|
||||
|
||||
@register.filter
|
||||
|
|
|
@ -40,7 +40,9 @@ def test_emaillink():
|
|||
|
||||
def test_user_link():
|
||||
u = UserProfile(username='jconnor', display_name='John Connor', pk=1)
|
||||
eq_(user_link(u), '<a href="%s">John Connor</a>' % u.get_url_path())
|
||||
eq_(user_link(u),
|
||||
'<a href="%s" title="%s">John Connor</a>' % (u.get_url_path(),
|
||||
u.name))
|
||||
|
||||
# handle None gracefully
|
||||
eq_(user_link(None), '')
|
||||
|
@ -50,7 +52,8 @@ def test_user_link_xss():
|
|||
u = UserProfile(username='jconnor',
|
||||
display_name='<script>alert(1)</script>', pk=1)
|
||||
html = "<script>alert(1)</script>"
|
||||
eq_(user_link(u), '<a href="%s">%s</a>' % (u.get_url_path(), html))
|
||||
eq_(user_link(u), '<a href="%s" title="%s">%s</a>' % (u.get_url_path(),
|
||||
u.name, html))
|
||||
|
||||
|
||||
def test_users_list():
|
||||
|
@ -72,14 +75,26 @@ def test_short_users_list():
|
|||
eq_(shortlist, ', '.join((user_link(u1), user_link(u2))) + ', others')
|
||||
|
||||
|
||||
def test_users_list_truncate_display_name():
|
||||
u = UserProfile(username='oscar',
|
||||
display_name='Some Very Long Display Name', pk=1)
|
||||
truncated_list = users_list([u], None, 10)
|
||||
eq_(truncated_list,
|
||||
u'<a href="%s" title="%s">Some Very...</a>' % (u.get_url_path(),
|
||||
u.name))
|
||||
|
||||
|
||||
def test_user_link_unicode():
|
||||
"""make sure helper won't choke on unicode input"""
|
||||
u = UserProfile(username=u'jmüller', display_name=u'Jürgen Müller', pk=1)
|
||||
eq_(user_link(u), u'<a href="%s">Jürgen Müller</a>' % u.get_url_path())
|
||||
eq_(user_link(u),
|
||||
u'<a href="%s" title="%s">Jürgen Müller</a>' % (u.get_url_path(),
|
||||
u.name))
|
||||
|
||||
u = UserProfile(username='\xe5\xaf\x92\xe6\x98\x9f', pk=1)
|
||||
eq_(user_link(u),
|
||||
u'<a href="%s">%s</a>' % (u.get_url_path(), u.username))
|
||||
u'<a href="%s" title="%s">%s</a>' % (u.get_url_path(), u.name,
|
||||
u.username))
|
||||
|
||||
|
||||
class TestAddonUsersList(TestPersonas, amo.tests.TestCase):
|
||||
|
|
Загрузка…
Ссылка в новой задаче