Merge lp:~dylanmccall/harvest/rss-feeds into lp:harvest

Proposed by Dylan McCall
Status: Merged
Merged at revision: 300
Proposed branch: lp:~dylanmccall/harvest/rss-feeds
Merge into: lp:harvest
Diff against target: 146 lines (+83/-0)
6 files modified
harvest/media/css/style.css (+3/-0)
harvest/opportunities/feeds.py (+61/-0)
harvest/opportunities/urls.py (+10/-0)
harvest/templates/opportunities/filter.html (+4/-0)
harvest/templates/opportunities/include/package_details.html (+1/-0)
harvest/templates/opportunities/single_package.html (+4/-0)
To merge this branch: bzr merge lp:~dylanmccall/harvest/rss-feeds
Reviewer Review Type Date Requested Status
Daniel Holbach Approve
Review via email: mp+59635@code.launchpad.net

Description of the change

This should cover what we were looking for in bug #247647. It's at least a start on RSS feeds for Harvest :)

Provides two feeds: one for all opportunities in a single package and one for the newest opportunities (arbitrarily limited to 25). Both feeds are linked in HTML metadata and the package-specific one is linked to beside the permalink button.

To post a comment you must log in.
Revision history for this message
Daniel Holbach (dholbach) wrote :

Great work! Thanks a lot!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'harvest/media/css/style.css'
2--- harvest/media/css/style.css 2010-10-12 02:55:53 +0000
3+++ harvest/media/css/style.css 2011-05-02 04:04:27 +0000
4@@ -437,6 +437,9 @@
5 text-align:right;
6 text-transform:lowercase;
7 }
8+.sourcepackage-details > .extra > .actions > a {
9+ margin:0px 0.25em;
10+}
11
12
13 li.sourcepackage > .sourcepackage-details > .opportunity-list {
14
15=== added file 'harvest/opportunities/feeds.py'
16--- harvest/opportunities/feeds.py 1970-01-01 00:00:00 +0000
17+++ harvest/opportunities/feeds.py 2011-05-02 04:04:27 +0000
18@@ -0,0 +1,61 @@
19+from django.contrib.syndication.views import Feed
20+from django.core.urlresolvers import reverse
21+from django.shortcuts import get_object_or_404
22+from django.utils.translation import ugettext_lazy as _
23+from django.utils.translation import string_concat
24+
25+import models
26+from wrappers import get_valid_opportunities
27+
28+class _OpportunitiesFeed(Feed):
29+ def item_title(self, opp):
30+ return _("%s: %s") % (opp.sourcepackage.name, opp.description)
31+
32+ def item_description(self, opp):
33+ #this is equivalent to the template opportunities/include/opportunity.html.
34+ summary_str = ""
35+ if len(opp.summary) > 0:
36+ #join the strings so they are translated at the right time (not now)
37+ summary_str = opp.summary[0]
38+ for s in opp.summary[1:]:
39+ summary_str = string_concat(summary_str, _(", "), s)
40+ return summary_str
41+
42+ def item_link(self, opp):
43+ return opp.url
44+
45+ def item_guid(self, opp):
46+ return opp.url
47+
48+class NewestOpportunitiesFeed(_OpportunitiesFeed):
49+ def title(self):
50+ return _("Newest opportunities in Harvest")
51+
52+ def link(self):
53+ return reverse('filter')
54+
55+ def items(self):
56+ valid_opps = get_valid_opportunities(models.Opportunity.objects.order_by('-last_updated'))[:25]
57+ if (valid_opps):
58+ return valid_opps
59+ else:
60+ return []
61+
62+class SinglePackageFeed(_OpportunitiesFeed):
63+ def get_object(self, request, package_name):
64+ return get_object_or_404(models.SourcePackage, name=package_name)
65+
66+ def title(self, pkg):
67+ return _("Opportunities for %s in Harvest") % pkg.name
68+
69+ def link(self, pkg):
70+ return reverse('single_package', args=[pkg.name])
71+
72+ def items(self, pkg):
73+ return get_valid_opportunities(pkg.opportunity_set.order_by('-last_updated'))
74+
75+ def item_title(self, opp):
76+ return opp.description
77+
78+ def item_guid(self, opp):
79+ return opp.url
80
81=== modified file 'harvest/opportunities/urls.py'
82--- harvest/opportunities/urls.py 2011-01-14 21:32:09 +0000
83+++ harvest/opportunities/urls.py 2011-05-02 04:04:27 +0000
84@@ -1,5 +1,7 @@
85 from django.conf.urls.defaults import *
86
87+import feeds
88+
89 urlpatterns = patterns('',
90 url(r'^$',
91 'opportunities.views.filter',
92@@ -36,4 +38,12 @@
93
94 url(r'^xhr/opportunity/(?P<opportunity_id>[\d]+)/edit/$',
95 'opportunities.views.xhr_opportunity_edit'),
96+
97+ url(r'^rss/newest25/$',
98+ feeds.NewestOpportunitiesFeed(),
99+ name='rss_newest_opportunities'),
100+
101+ url(r'^rss/package/(?P<package_name>.+)/$',
102+ feeds.SinglePackageFeed(),
103+ name='rss_single_package'),
104 )
105
106=== modified file 'harvest/templates/opportunities/filter.html'
107--- harvest/templates/opportunities/filter.html 2010-08-06 20:27:49 +0000
108+++ harvest/templates/opportunities/filter.html 2011-05-02 04:04:27 +0000
109@@ -1,6 +1,10 @@
110 {% extends "base.html" %}
111 {% load i18n %}
112
113+{% block extrahead %}
114+<link rel="alternate" type="application/rss+xml" title="{% blocktrans %}25 newest opportunities{% endblocktrans %}" href="{% url rss_newest_opportunities %}" />
115+{% endblock %}
116+
117 {% block title %}{{ block.super }}{% endblock %}
118
119 {% block content %}
120
121=== modified file 'harvest/templates/opportunities/include/package_details.html'
122--- harvest/templates/opportunities/include/package_details.html 2010-08-11 23:36:17 +0000
123+++ harvest/templates/opportunities/include/package_details.html 2011-05-02 04:04:27 +0000
124@@ -20,6 +20,7 @@
125 <div class="extra">
126 <div class="actions">
127 <a href="{% url single_package package.real.name %}" target="_blank">{% trans "Permalink" %}</a>
128+ <a href="{% url rss_single_package package.real.name %}" target="_blank">{% trans "RSS" %}</a>
129 </div>
130 {% with package.get_hidden_opportunities.count as hidden_count %}
131 {% ifnotequal hidden_count 0 %}
132
133=== modified file 'harvest/templates/opportunities/single_package.html'
134--- harvest/templates/opportunities/single_package.html 2010-08-06 03:34:17 +0000
135+++ harvest/templates/opportunities/single_package.html 2011-05-02 04:04:27 +0000
136@@ -1,6 +1,10 @@
137 {% extends "one_column.html" %}
138 {% load i18n %}
139
140+{% block extrahead %}
141+<link rel="alternate" type="application/rss+xml" title="{% blocktrans with package.real.name as name %}Opportunities for {{name}}{% endblocktrans %}" href="{% url rss_single_package package.real.name %}" />
142+{% endblock %}
143+
144 {% block title %}{{ block.super }}: {{ package.real.name }}{% endblock %}
145
146 {% block pagetitle %}{{ package.real.name }}{% endblock %}

Subscribers

People subscribed via source and target branches

to all changes: