All links in bio are now rel="nofollow". [bug 648774]

This commit is contained in:
Ricky Rosario 2011-04-12 15:23:10 -04:00
Родитель 9d91de7ef8
Коммит 26b7148620
5 изменённых файлов: 24 добавлений и 9 удалений

Просмотреть файл

@ -51,7 +51,7 @@ def url(viewname, *args, **kwargs):
@register.function
def unlocalized_url(viewname, *args, **kwargs):
"""Helper for Django's ``reverse`` in templates.
Uses django's default reverse."""
return django_reverse(viewname, args=args, kwargs=kwargs)
@ -87,9 +87,11 @@ def urlparams(url_, hash=None, query_dict=None, **query):
@register.filter
def wiki_to_html(wiki_markup, locale=settings.WIKI_DEFAULT_LANGUAGE):
def wiki_to_html(wiki_markup, locale=settings.WIKI_DEFAULT_LANGUAGE,
nofollow=False):
"""Wiki Markup -> HTML jinja2.Markup object"""
return jinja2.Markup(sumo.parser.wiki_to_html(wiki_markup, locale=locale))
return jinja2.Markup(sumo.parser.wiki_to_html(wiki_markup, locale=locale,
nofollow=nofollow))
class Paginator(object):

Просмотреть файл

@ -35,9 +35,11 @@ IMAGE_PARAM_VALUES = {
}
def wiki_to_html(wiki_markup, locale=settings.WIKI_DEFAULT_LANGUAGE):
def wiki_to_html(wiki_markup, locale=settings.WIKI_DEFAULT_LANGUAGE,
nofollow=False):
"""Wiki Markup -> HTML"""
return WikiParser().parse(wiki_markup, show_toc=False, locale=locale)
return WikiParser().parse(wiki_markup, show_toc=False, locale=locale,
nofollow=nofollow)
def get_object_fallback(cls, title, locale, default=None, **kwargs):
@ -177,7 +179,8 @@ class WikiParser(Parser):
self.registerInternalLinkHook('Image', self._hook_image_tag)
def parse(self, text, show_toc=None, tags=None, attributes=None,
styles=None, locale=settings.WIKI_DEFAULT_LANGUAGE):
styles=None, locale=settings.WIKI_DEFAULT_LANGUAGE,
nofollow=False):
"""Given wiki markup, return HTML.
Pass a locale to get all the hooks to look up Documents or Media
@ -191,7 +194,8 @@ class WikiParser(Parser):
parser_kwargs = {'tags': tags} if tags else {}
return super(WikiParser, self).parse(text, show_toc=show_toc,
attributes=attributes or ALLOWED_ATTRIBUTES,
styles=styles or ALLOWED_STYLES, **parser_kwargs)
styles=styles or ALLOWED_STYLES, nofollow=nofollow,
**parser_kwargs)
def _hook_internal_link(self, parser, space, name):
"""Parses text and returns internal link."""

Просмотреть файл

@ -71,7 +71,7 @@
{% if profile.bio %}
<div id="bio">
<h2>{{ _('About {user}')|f(user=display_name(profile.user)) }}</h2>
{{ profile.bio|wiki_to_html }}
{{ profile.bio|wiki_to_html(nofollow=True) }}
</div>
{% endif %}
</section>

Просмотреть файл

@ -333,6 +333,15 @@ class ViewProfileTests(TestCaseBase):
eq_('Edit my profile', doc('#doc-tabs li:last').text())
self.client.logout()
def test_bio_links_nofollow(self):
profile = Profile.objects.get(user__id=47963)
profile.bio = 'http://getseo.com, [http://getseo.com]'
profile.save()
r = self.client.get(reverse('users.profile', args=[47963]))
eq_(200, r.status_code)
doc = pq(r.content)
eq_(2, len(doc('#bio a[rel="nofollow"]')))
class PasswordChangeTests(TestCaseBase):
fixtures = ['users.json']

2
vendor

@ -1 +1 @@
Subproject commit b52073f9d013b11621133c020e8dbc041b8b3790
Subproject commit c6d0cacfe7edaac8dd2f13bd3f1f1d2466f7a4fb