Skip to content

Commit

Permalink
Merge remote branch 'rhelmer/migrate-recommended-rss-bug-584189'
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeff Balogh committed Aug 18, 2010
2 parents ab16974 + 5f03c72 commit 450ccc0
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 11 deletions.
41 changes: 41 additions & 0 deletions apps/addons/fixtures/addons/featured.json
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
6 changes: 3 additions & 3 deletions apps/amo/helpers.py
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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 = []

Expand Down
51 changes: 46 additions & 5 deletions apps/browse/feeds.py
@@ -1,4 +1,4 @@
import urllib
import urllib, random

from django.contrib.syndication.views import Feed
from django.shortcuts import get_object_or_404
Expand All @@ -7,8 +7,8 @@

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


Expand All @@ -30,7 +30,7 @@ def get_object(self, request, category_name):

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"""
Expand Down Expand Up @@ -64,11 +64,52 @@ def item_guid(self, addon):

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])
32 changes: 29 additions & 3 deletions apps/browse/tests.py
Expand Up @@ -255,6 +255,7 @@ def redirects(from_, to):
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')
Expand All @@ -263,10 +264,9 @@ def test_featured_addons(self):
"""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()
Expand All @@ -292,3 +292,29 @@ def test_item_title(self):
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')
3 changes: 3 additions & 0 deletions apps/browse/urls.py
@@ -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('',
Expand Down Expand Up @@ -29,4 +30,6 @@

url('^search-tools/(?P<category>[^/]+)?$', views.search_tools,
name='browse.search-tools'),

url('^featured/format:rss$', FeaturedRss(), name='browse.featured.rss'),
)
3 changes: 3 additions & 0 deletions urls.py
Expand Up @@ -105,6 +105,9 @@
('^recommended$',
lambda r: redirect('browse.featured', permanent=True)),

('^recommended/format:rss$',
lambda r: redirect('browse.featured.rss', permanent=True)),

)

if settings.DEBUG:
Expand Down

0 comments on commit 450ccc0

Please sign in to comment.