diff --git a/apps/devhub/models.py b/apps/devhub/models.py index 8448edf46b..b60f3a65d8 100644 --- a/apps/devhub/models.py +++ b/apps/devhub/models.py @@ -220,8 +220,11 @@ class ActivityLog(amo.models.ModelBase): arg.get_url_path(), arg.name) arguments.remove(arg) if isinstance(arg, Tag) and not tag: - tag = self.f(u'{1}', - arg.get_url_path(), arg.tag_text) + if arg.can_reverse(): + tag = self.f(u'{1}', + arg.get_url_path(), arg.tag_text) + else: + tag = self.f('{0}', arg.tag_text) try: kw = dict(addon=addon, review=review, version=version, collection=collection, tag=tag) diff --git a/apps/devhub/tests/test_models.py b/apps/devhub/tests/test_models.py index 88e07e5ca0..4ec77c4e51 100644 --- a/apps/devhub/tests/test_models.py +++ b/apps/devhub/tests/test_models.py @@ -2,11 +2,13 @@ import jingo import test_utils from nose.tools import eq_ from mock import Mock +from pyquery import PyQuery as pq import amo from addons.models import Addon, AddonUser from bandwagon.models import Collection from devhub.models import ActivityLog +from tags.models import Tag from files.models import File from reviews.models import Review from users.models import UserProfile @@ -125,6 +127,15 @@ class TestActivityLog(test_utils.TestCase): '
<script src="x.js"> role changed to Owner for Delicious Bookmarks.
') + def test_tag_no_match(self): + addon = Addon.objects.get() + tag = Tag.objects.create(tag_text='http://foo.com') + amo.log(amo.LOG.ADD_TAG, addon, tag) + log = ActivityLog.objects.get() + text = jingo.env.from_string('{{ log }}
').render(log=log) + # There should only be one a, the link to the addon, but no tag link. + eq_(len(pq(text)('a')), 1) + class TestVersion(test_utils.TestCase): fixtures = ['base/apps', 'base/users', 'base/addon_3615', diff --git a/apps/tags/models.py b/apps/tags/models.py index 520b3eee5c..57140af74b 100644 --- a/apps/tags/models.py +++ b/apps/tags/models.py @@ -1,4 +1,5 @@ from django.db import models +from django.core.urlresolvers import NoReverseMatch import amo.models from amo.urlresolvers import reverse @@ -30,6 +31,13 @@ class Tag(amo.models.ModelBase): def popularity(self): return self.tagstat.num_addons + def can_reverse(self): + try: + self.get_url_path() + return True + except NoReverseMatch: + return False + def get_url_path(self): return reverse('tags.detail', args=[self.tag_text]) diff --git a/apps/tags/templates/tags/tag_link.html b/apps/tags/templates/tags/tag_link.html index c049ef2bdb..241cac044b 100644 --- a/apps/tags/templates/tags/tag_link.html +++ b/apps/tags/templates/tags/tag_link.html @@ -1 +1,5 @@ -{{ tag.tag_text }} +{% if tag.can_reverse() %} + {{ tag.tag_text }} +{% else %} + {{ tag.tag_text }} +{% endif %} diff --git a/apps/tags/templates/tags/tag_list.html b/apps/tags/templates/tags/tag_list.html index 77a3f5cb35..57dc743c5f 100644 --- a/apps/tags/templates/tags/tag_list.html +++ b/apps/tags/templates/tags/tag_list.html @@ -1,8 +1,12 @@ {% macro tag_li(tag, addon=None, css_class='') -%}