Merge remote branch 'rhelmer/migrate-recommended-rss-bug-584189'
This commit is contained in:
Коммит
450ccc01ee
|
@ -193,6 +193,31 @@
|
|||
"addon": 1003
|
||||
}
|
||||
},
|
||||
{
|
||||
"pk": 2,
|
||||
"model": "addons.feature",
|
||||
"fields": {
|
||||
"application": 1,
|
||||
"end": "2037-12-02 00:00:00",
|
||||
"created": "2007-10-09 15:34:20",
|
||||
"locale": null,
|
||||
"modified": "2009-12-07 11:00:58",
|
||||
"start": "2007-10-09 15:34:20",
|
||||
"addon": 1001
|
||||
}
|
||||
},
|
||||
{
|
||||
"pk": 1001,
|
||||
"model": "versions.version",
|
||||
"fields": {
|
||||
"license": null,
|
||||
"created": "2006-10-23 12:57:41",
|
||||
"approvalnotes": "",
|
||||
"modified": "2006-10-23 19:22:18",
|
||||
"version": "1.0.42",
|
||||
"addon": 1001
|
||||
}
|
||||
},
|
||||
{
|
||||
"pk": 1003,
|
||||
"model": "versions.version",
|
||||
|
@ -205,6 +230,22 @@
|
|||
"addon": 1003
|
||||
}
|
||||
},
|
||||
{
|
||||
"pk": 1001,
|
||||
"model": "files.file",
|
||||
"fields": {
|
||||
"status": 4,
|
||||
"codereview": 0,
|
||||
"hash": "sha256:5b5a",
|
||||
"created": "2007-03-05 13:19:15",
|
||||
"modified": "2007-04-04 12:30:11",
|
||||
"filename": "yahoo_toolbar-10.0.42-fx.xpi",
|
||||
"platform": 1,
|
||||
"version": 1001,
|
||||
"datestatuschanged": null,
|
||||
"size": 169
|
||||
}
|
||||
},
|
||||
{
|
||||
"pk": 1003,
|
||||
"model": "files.file",
|
||||
|
|
|
@ -138,7 +138,7 @@ def currencyfmt(num, currency):
|
|||
return _get_format().currency(num, currency)
|
||||
|
||||
|
||||
def _page_name(app=None):
|
||||
def page_name(app=None):
|
||||
"""Determine the correct page name for the given app (or no app)."""
|
||||
if app:
|
||||
return _(u'Add-ons for {0}').format(app.pretty)
|
||||
|
@ -164,7 +164,7 @@ def login_link(context):
|
|||
@jinja2.contextfunction
|
||||
def page_title(context, title):
|
||||
app = context['request'].APP
|
||||
return u'%s :: %s' % (title, _page_name(app))
|
||||
return u'%s :: %s' % (title, page_name(app))
|
||||
|
||||
|
||||
@register.function
|
||||
|
@ -176,7 +176,7 @@ def breadcrumbs(context, items=list(), add_default=True):
|
|||
"""
|
||||
if add_default:
|
||||
app = context['request'].APP
|
||||
crumbs = [(urlresolvers.reverse('home'), _page_name(app))]
|
||||
crumbs = [(urlresolvers.reverse('home'), page_name(app))]
|
||||
else:
|
||||
crumbs = []
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import urllib
|
||||
import urllib, random
|
||||
|
||||
from django.contrib.syndication.views import Feed
|
||||
from django.shortcuts import get_object_or_404
|
||||
|
@ -7,8 +7,8 @@ from tower import ugettext as _
|
|||
|
||||
import amo
|
||||
from amo.urlresolvers import reverse
|
||||
from amo.helpers import absolutify, url, _page_name
|
||||
from addons.models import Category
|
||||
from amo.helpers import absolutify, url, page_name
|
||||
from addons.models import Addon, Category
|
||||
from .views import addon_listing
|
||||
|
||||
|
||||
|
@ -30,7 +30,7 @@ class CategoriesRss(Feed):
|
|||
|
||||
def title(self, category):
|
||||
"""Title for the feed as a whole"""
|
||||
return u'%s :: %s' % (category.name, _page_name(self.request.APP))
|
||||
return u'%s :: %s' % (category.name, page_name(self.request.APP))
|
||||
|
||||
def link(self, category):
|
||||
"""Link for the feed as a whole"""
|
||||
|
@ -64,11 +64,52 @@ class CategoriesRss(Feed):
|
|||
|
||||
def item_author_name(self, addon):
|
||||
"""Author for a particuar review (<item><dc:creator>)"""
|
||||
|
||||
class FeaturedRss(Feed):
|
||||
|
||||
def get_object(self, request):
|
||||
self.app = request.APP
|
||||
self.appname = unicode(request.APP.pretty)
|
||||
|
||||
def title(self):
|
||||
"""Title for the feed"""
|
||||
return _('Featured Add-ons :: %s') % page_name(self.app)
|
||||
|
||||
def link(self):
|
||||
"""Link for the feed"""
|
||||
return absolutify(url('home'))
|
||||
|
||||
def description(self):
|
||||
"""Description for the feed"""
|
||||
# L10n: %s is an app name.
|
||||
return _("Here's a few of our favorite add-ons to help you get"
|
||||
" started customizing %s.") % self.appname
|
||||
|
||||
def items(self):
|
||||
"""Return the Addons to be output as RSS <item>'s"""
|
||||
addons = list(Addon.objects.featured(self.app))
|
||||
random.shuffle(addons)
|
||||
return addons
|
||||
|
||||
def item_title(self, addon):
|
||||
return u'%s %s' % (addon.name, addon.current_version)
|
||||
|
||||
def item_description(self, addon):
|
||||
"""Description for particular add-on (<item><description>)"""
|
||||
return unicode(addon.description) or ''
|
||||
|
||||
def item_author_name(self, addon):
|
||||
"""Author for a particuar add-on (<item><dc:creator>)"""
|
||||
if addon.listed_authors:
|
||||
return addon.listed_authors[0].display_name
|
||||
else:
|
||||
return ''
|
||||
|
||||
def item_pubdate(self, addon):
|
||||
"""Pubdate for a particuar review (<item><pubDate>)"""
|
||||
"""Pubdate for a particuar add-on (<item><pubDate>)"""
|
||||
return addon.created
|
||||
|
||||
def item_guid(self, addon):
|
||||
"""Guid for a particuar version (<item><guid>)"""
|
||||
return reverse('addons.versions',
|
||||
args=[addon.id, addon.current_version])
|
||||
|
|
|
@ -255,6 +255,7 @@ class TestLegacyRedirects(test_utils.TestCase):
|
|||
redirects('/search-engines', '/search-tools/')
|
||||
# redirects('/browse/type:7', '/plugins/')
|
||||
redirects('/recommended', '/featured')
|
||||
redirects('/recommended/format:rss', '/featured/format:rss')
|
||||
|
||||
class TestFeaturedPage(amo.test_utils.ExtraSetup, test_utils.TestCase):
|
||||
fixtures = ('base/apps', 'addons/featured')
|
||||
|
@ -263,10 +264,9 @@ class TestFeaturedPage(amo.test_utils.ExtraSetup, test_utils.TestCase):
|
|||
"""Make sure that only featured add-ons are shown"""
|
||||
|
||||
response = self.client.get(reverse('browse.featured'))
|
||||
eq_([1003], [a.id for a in response.context['addons']])
|
||||
eq_([1001,1003], [a.id for a in response.context['addons']])
|
||||
|
||||
|
||||
class TestFeed(test_utils.TestCase):
|
||||
class TestCategoriesFeed(test_utils.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.feed = feeds.CategoriesRss()
|
||||
|
@ -292,3 +292,29 @@ class TestFeed(test_utils.TestCase):
|
|||
def test_item_guid(self):
|
||||
t = self.feed.item_guid(self.addon)
|
||||
assert t.endswith(u'/addon/2/versions/v%s' % urllib.urlquote(self.u))
|
||||
|
||||
class TestFeaturedFeed(amo.test_utils.ExtraSetup, test_utils.TestCase):
|
||||
fixtures = ('base/apps', 'addons/featured')
|
||||
|
||||
def test_feed_elements_present(self):
|
||||
"""specific elements are present and reasonably well formed"""
|
||||
url = reverse('browse.featured.rss')
|
||||
r = self.client.get(url, follow=True)
|
||||
doc = pq(r.content)
|
||||
eq_(doc('rss channel title')[0].text,
|
||||
'Featured Add-ons :: Add-ons for Firefox')
|
||||
assert doc('rss channel link')[0].text.endswith('/en-US/firefox/')
|
||||
eq_(doc('rss channel description')[0].text,
|
||||
"Here's a few of our favorite add-ons to help you get " \
|
||||
"started customizing Firefox.")
|
||||
assert len(doc('rss channel item title')[0].text) > 0
|
||||
item_link = doc('rss channel item link')[0]
|
||||
assert item_link.text.endswith('/addon/1003/') \
|
||||
or item_link.text.endswith('/addon/1001/')
|
||||
item_pubdate = doc('rss channel item pubDate')[0]
|
||||
assert item_pubdate.text == 'Tue, 17 Jan 2006 07:28:30 -0800' \
|
||||
or item_pubdate.text == 'Tue, 02 Jan 2007 16:57:55 -0800'
|
||||
item_guid = doc('rss channel item guid')[0]
|
||||
print doc
|
||||
assert item_guid.text.endswith('/versions/1.0.42') or \
|
||||
item_guid.text.endswith('/versions/1.0.43')
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
from django.conf.urls.defaults import patterns, url
|
||||
from browse.feeds import CategoriesRss
|
||||
from . import views
|
||||
from browse.feeds import FeaturedRss
|
||||
|
||||
|
||||
urlpatterns = patterns('',
|
||||
|
@ -29,4 +30,6 @@ urlpatterns = patterns('',
|
|||
|
||||
url('^search-tools/(?P<category>[^/]+)?$', views.search_tools,
|
||||
name='browse.search-tools'),
|
||||
|
||||
url('^featured/format:rss$', FeaturedRss(), name='browse.featured.rss'),
|
||||
)
|
||||
|
|
3
urls.py
3
urls.py
|
@ -105,6 +105,9 @@ urlpatterns = patterns('',
|
|||
('^recommended$',
|
||||
lambda r: redirect('browse.featured', permanent=True)),
|
||||
|
||||
('^recommended/format:rss$',
|
||||
lambda r: redirect('browse.featured.rss', permanent=True)),
|
||||
|
||||
)
|
||||
|
||||
if settings.DEBUG:
|
||||
|
|
Загрузка…
Ссылка в новой задаче