port tag/:tag using existing search interface (bug 581141)

This commit is contained in:
Sam Keen 2010-08-02 16:49:18 -07:00
Родитель a278806abe
Коммит bdf1a00663
4 изменённых файлов: 11 добавлений и 9 удалений

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

@ -80,6 +80,7 @@ class AddonManager(amo.models.ManagerBase):
"""
if not status:
status = [amo.STATUS_PUBLIC]
def q(*args, **kw):
if prefix:
kw = dict((prefix + k, v) for k, v in kw.items())
@ -200,7 +201,7 @@ class Addon(amo.models.ModelBase):
return '%s: %s' % (self.id, self.name)
def flush_urls(self):
urls = ['*/addon/%d/' % self.id, # Doesn't take care of api
urls = ['*/addon/%d/' % self.id, # Doesn't take care of api
'*/addon/%d/developers/' % self.id,
'*/addon/%d/reviews/' % self.id,
'*/addon/%d/versions/*' % self.id,
@ -390,6 +391,7 @@ class Addon(amo.models.ModelBase):
def is_featured(self, app, lang):
"""is add-on globally featured for this app and language?"""
qs = Addon.objects.featured(app)
def _features():
vals = qs.extra(select={'locale': 'features.locale'})
d = collections.defaultdict(list)
@ -417,9 +419,7 @@ class Addon(amo.models.ModelBase):
@amo.cached_property
def tags_partitioned_by_developer(self):
"Returns a tuple of developer tags and user tags for this addon."
# TODO(davedash): We can't cache these tags until /tags/ are moved
# into Zamboni.
tags = self.tags.not_blacklisted().no_cache()
tags = self.tags.not_blacklisted()
if self.is_persona:
return models.query.EmptyQuerySet(), tags
user_tags = tags.exclude(addon_tags__user__in=self.listed_authors)

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

@ -240,7 +240,7 @@ def ajax_search(request):
return HttpResponse(json.dumps(items), mimetype='application/json')
def search(request):
def search(request, tag_name=None):
title = _('Search Add-ons')
# If the form is invalid we still want to have a query.
@ -280,7 +280,7 @@ def search(request):
title = _('Search for %s' % query)
addon_type = form.cleaned_data.get('atype', 0)
tag = form.cleaned_data.get('tag')
tag = tag_name if tag_name is not None else form.cleaned_data.get('tag')
page = form.cleaned_data['page']
last_updated = form.cleaned_data.get('lup')
sort = form.cleaned_data.get('sort')

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

@ -1,7 +1,7 @@
from jingo import register
import jinja2
from access import acl
from cake.urlresolvers import remora_url
from amo.urlresolvers import reverse
@register.inclusion_tag('tags/tag_list.html')
@ -39,5 +39,5 @@ def tag_link(tag, min_count, max_count):
factor = range_convert(tag.tagstat.num_addons, 0, max_count, 1, 10)
hyperlink = u'<a class="tagLevel%d tag" href="%s">%s</a>'
return hyperlink % (factor,
remora_url('/tag/' + tag.tag_text),
reverse('tags.detail', args=[tag.tag_text.lower()]),
tag.tag_text)

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

@ -1,8 +1,10 @@
from django.conf.urls.defaults import patterns, url
from . import views
import search.views as search_views
urlpatterns = patterns('',
url('^tags/top$', views.top_cloud, name='tags.top_cloud'),
url('^tag/(?P<tag>[^/]+)$', lambda: None, name='tags.detail'),
url('^tag/(?P<tag_name>[^/]+)$', search_views.search, name='tags.detail'),
)