← Back to team overview

harvest-dev team mailing list archive

[Merge] lp:~dylanmccall/harvest/bug-775438 into lp:harvest

 

Dylan McCall has proposed merging lp:~dylanmccall/harvest/bug-775438 into lp:harvest.

Requested reviews:
  harvest-dev (harvest-dev)
Related bugs:
  Bug #775438 in harvest: "RSS feeds break with old django (lucid)"
  https://bugs.launchpad.net/harvest/+bug/775438

For more details, see:
https://code.launchpad.net/~dylanmccall/harvest/bug-775438/+merge/59673

This fixes bug #775438, switching to the old syndication API. The code is a little uglier, but the URLs stay the same so when the production server is upgraded we won't be tempted to break everyone's RSS feeds :)
-- 
https://code.launchpad.net/~dylanmccall/harvest/bug-775438/+merge/59673
Your team harvest-dev is requested to review the proposed merge of lp:~dylanmccall/harvest/bug-775438 into lp:harvest.
=== modified file 'harvest/opportunities/feeds.py'
--- harvest/opportunities/feeds.py	2011-05-02 02:39:20 +0000
+++ harvest/opportunities/feeds.py	2011-05-02 16:30:56 +0000
@@ -1,5 +1,7 @@
-from django.contrib.syndication.views import Feed
+from django.contrib.syndication.feeds import Feed
+#When Django 1.2 is available, change to new feed API: from django.contrib.syndication.views import Feed
 from django.core.urlresolvers import reverse
+from django.core.exceptions import ObjectDoesNotExist
 from django.shortcuts import get_object_or_404
 from django.utils.translation import ugettext_lazy as _
 from django.utils.translation import string_concat
@@ -26,6 +28,9 @@
 	
 	def item_guid(self, opp):
 		return opp.url
+	
+	def item_pubdate(self, opp):
+		return opp.since
 
 class NewestOpportunitiesFeed(_OpportunitiesFeed):
 	def title(self):
@@ -42,10 +47,12 @@
 			return []
 
 class SinglePackageFeed(_OpportunitiesFeed):
-	def get_object(self, request, package_name):
-		return get_object_or_404(models.SourcePackage, name=package_name)
+	def get_object(self, bits):
+		if len(bits) != 1:
+			raise ObjectDoesNotExist
+		return get_object_or_404(models.SourcePackage, name=bits[0])
 	
-	def title(self, pkg): 
+	def title(self, pkg):
 		return _("Opportunities for %s in Harvest") % pkg.name
 	
 	def link(self, pkg):
@@ -56,6 +63,3 @@
 	
 	def item_title(self, opp):
 		return opp.description
-	
-	def item_guid(self, opp):
-		return opp.url

=== modified file 'harvest/opportunities/urls.py'
--- harvest/opportunities/urls.py	2011-05-02 02:39:20 +0000
+++ harvest/opportunities/urls.py	2011-05-02 16:30:56 +0000
@@ -2,6 +2,11 @@
 
 import feeds
 
+feed_dict = {
+    'newest25' : feeds.NewestOpportunitiesFeed,
+    'package' : feeds.SinglePackageFeed, 
+}
+
 urlpatterns = patterns('',
     url(r'^$',
         'opportunities.views.filter',
@@ -39,11 +44,8 @@
     url(r'^xhr/opportunity/(?P<opportunity_id>[\d]+)/edit/$',
         'opportunities.views.xhr_opportunity_edit'),
     
-    url(r'^rss/newest25/$',
-        feeds.NewestOpportunitiesFeed(),
-        name='rss_newest_opportunities'),
-    
-    url(r'^rss/package/(?P<package_name>.+)/$',
-        feeds.SinglePackageFeed(),
-        name='rss_single_package'),
+    url(r'^rss/(?P<url>.*)/$',
+        'django.contrib.syndication.views.feed',
+        {'feed_dict': feed_dict},
+        name='feed'),
 )

=== modified file 'harvest/templates/opportunities/filter.html'
--- harvest/templates/opportunities/filter.html	2011-05-02 02:39:20 +0000
+++ harvest/templates/opportunities/filter.html	2011-05-02 16:30:56 +0000
@@ -2,7 +2,7 @@
 {% load i18n %}
 
 {% block extrahead %}
-<link rel="alternate" type="application/rss+xml" title="{% blocktrans %}25 newest opportunities{% endblocktrans %}" href="{% url rss_newest_opportunities %}" />
+<link rel="alternate" type="application/rss+xml" title="{% blocktrans %}25 newest opportunities{% endblocktrans %}" href="{% url feed 'newest25' %}" />
 {% endblock %}
 
 {% block title %}{{ block.super }}{% endblock %}

=== modified file 'harvest/templates/opportunities/include/package_details.html'
--- harvest/templates/opportunities/include/package_details.html	2011-05-02 00:20:31 +0000
+++ harvest/templates/opportunities/include/package_details.html	2011-05-02 16:30:56 +0000
@@ -20,7 +20,7 @@
 <div class="extra">
 	<div class="actions">
 		<a href="{% url single_package package.real.name %}" target="_blank">{% trans "Permalink" %}</a>
-		<a href="{% url rss_single_package package.real.name %}" target="_blank">{% trans "RSS" %}</a>
+		<a href="{% url feed 'package' %}{{package.real.name}}/" target="_blank">{% trans "RSS" %}</a>
 	</div>
 	{% with package.get_hidden_opportunities.count as hidden_count %}
 	{% ifnotequal hidden_count 0 %}

=== modified file 'harvest/templates/opportunities/single_package.html'
--- harvest/templates/opportunities/single_package.html	2011-05-02 01:22:44 +0000
+++ harvest/templates/opportunities/single_package.html	2011-05-02 16:30:56 +0000
@@ -2,7 +2,7 @@
 {% load i18n %}
 
 {% block extrahead %}
-<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 %}" />
+<link rel="alternate" type="application/rss+xml" title="{% blocktrans with package.real.name as name %}Opportunities for {{name}}{% endblocktrans %}" href="{% url feed 'package' %}{{package.real.name}}/" />
 {% endblock %}
 
 {% block title %}{{ block.super }}: {{ package.real.name }}{% endblock %}