Changeset - 6a2918c288c2
[Not reviewed]
0 2 0
Bradley Kuhn (bkuhn) - 10 years ago 2014-07-14 14:49:29
bkuhn@ebb.org
In Django 1.2, feed_dict was deprecated.

Therefore, change this to use the method explained at:

https://docs.djangoproject.com/en/dev/releases/1.2/#feed-in-django-contrib-syndication-feeds
2 files changed with 3 insertions and 10 deletions:
0 comments (0 inline, 0 general)
www/conservancy/feeds.py
Show inline comments
...
 
@@ -49,209 +49,202 @@ class OmnibusFeedType(Rss201rev2Feed):
 
    def root_attributes(self):
 
        attrs = super(OmnibusFeedType, self).root_attributes()
 
        attrs['xmlns:itunes'] = 'http://www.itunes.com/dtds/podcast-1.0.dtd'
 
        attrs['xmlns:atom'] = 'http://www.w3.org/2005/Atom'
 
        attrs['xmlns:media'] = 'http://search.yahoo.com/mrss/'
 
        attrs['xmlns:dc'] = "http://purl.org/dc/elements/1.1/"
 
        return attrs
 

	
 
    def add_root_elements(self, handler):
 
        super(OmnibusFeedType, self).add_root_elements(handler)
 

	
 
    def add_item_elements(self, handler, item):
 
        super(OmnibusFeedType, self).add_item_elements(handler, item)
 
        # Block things that don't have an enclosure from iTunes in
 
        # case someone uploads this feed there.
 
        handler.addQuickElement("itunes:block", 'Yes')
 

	
 
class OmnibusFeed(ConservancyFeedBase):
 
    feed_type = OmnibusFeedType
 
    link ="/news/"
 
    title = "The Software Freedom Conservancy"
 
    description = "An aggregated feed of all RSS content available from the Software Freedom Conservancy, including both news items and blogs."
 
    title_template = "feeds/omnibus_title.html"
 
    description_template = "feeds/omnibus_description.html"
 
    author_email = "info@sfconservancy.org"
 
    author_link = "https://sfconservancy.org/"
 
    author_name = "Software Freedom Conservancy"
 

	
 
    def item_enclosure_mime_type(self): return "audio/mpeg"
 

	
 
    def item_enclosure_url(self, item):
 
        if hasattr(item, 'mp3_path'):
 
            return "https://sfconservancy.org" + item.mp3_path
 
    def item_enclosure_length(self, item):
 
        if hasattr(item, 'mp3_path'):
 
            return item.mp3_length
 

	
 
    def item_pubdate(self, item):
 
        return item.pub_date
 

	
 
    def item_author_name(self, item):
 
        if item.omnibus_type == "blog":
 
            return item.author.formal_name
 
        else:
 
            return "Software Freedom Conservancy"
 

	
 
    def item_author_link(self, obj):
 
        return "https://sfconservancy.org"
 

	
 
    def item_author_email(self, item):
 
        if item.omnibus_type == "news":
 
            return "info@sfconservancy.org"
 
        elif hasattr(item, 'author'):
 
            return "%s@sfconservancy.org" % item.author
 
        else:
 
            return "info@sfconservancy.org"
 

	
 
    def item_pubdate(self, item):
 
        if item.omnibus_type == "event":
 
            return item.date_created
 
        else:
 
            return item.pub_date
 

	
 
    def item_link(self, item):
 
        return item.get_absolute_url()
 

	
 
# http://groups.google.ca/group/django-users/browse_thread/thread/d22e8a8f378cf0e2
 

	
 
    def items(self):
 
        blogs = BlogEntry.objects.filter(pub_date__lte=datetime.now()).order_by('-pub_date')[:25]
 
        for bb in blogs:
 
            bb.omnibus_type = "blog"
 
            bb.omnibus_feed_description_template = "feeds/blog_description.html"
 
            bb.omnibus_feed_title_template = "feeds/blog_title.html"
 

	
 
        news = PressRelease.objects.filter(pub_date__lte=datetime.now(),
 
                                           sites__id__exact=settings.SITE_ID).order_by('-pub_date')[:25]
 
        for nn in news:
 
            nn.omnibus_type = "news"
 
            nn.omnibus_feed_description_template = "feeds/news_description.html"
 
            nn.omnibus_feed_title_template = "feeds/news_title.html"
 

	
 
        a  = [ ii for ii in itertools.chain(blogs, news)]
 
        a.sort(key=operator.attrgetter('pub_date'), reverse=True)
 
        return a
 

	
 

	
 
    def item_extra_kwargs(self, item):
 
        return super(OmnibusFeed, self).item_extra_kwargs(item)
 

	
 
class BlogFeed(ConservancyFeedBase):
 
    link = "/blog/"
 

	
 
    def title(self):
 
        answer = "The Software Freedom Conservancy Blog"
 

	
 
        GET = self.request.GET
 
        tags = []
 
        if 'author' in GET:
 
            tags = GET.getlist('author')
 
        if 'tag' in GET:
 
            tags += GET.getlist('tag')
 

	
 
        if len(tags) == 1:
 
            answer += " (" + tags[0] + ")"
 
        elif len(tags) > 1:
 
            firstTime = True
 
            done = {}
 
            for tag in tags:
 
                if done.has_key(tag): continue
 
                if firstTime:
 
                    answer += " ("
 
                    firstTime = False
 
                else:
 
                    answer += ", "
 
                answer += tag
 
                done[tag] = tag
 
            answer += ")"
 
        else:
 
            answer += "."
 
        return answer
 
        
 
    def description(self):
 
        answer = "Blogs at the Software Freedom Conservancy"
 

	
 
        GET = self.request.GET
 
        tags = []
 
        if 'author' in GET: tags = GET.getlist('author')
 
        if 'tag' in GET:    tags += GET.getlist('tag')
 

	
 
        done = {}
 
        if len(tags) == 1:
 
            answer += " tagged with " + tags[0]
 
        elif len(tags) > 1:
 
            firstTime = True
 
            for tag in tags:
 
                if done.has_key(tag): continue
 
                if firstTime:
 
                    answer += " tagged with "
 
                    firstTime = False
 
                else:
 
                    answer += " or "
 
                answer += tag
 
                done[tag] = tag
 
        else:
 
            answer = "All blogs at the Software Freedom Conservancy"
 
        answer += "."
 

	
 
        return answer
 
        
 
    def item_author_name(self, item):
 
        return item.author.formal_name
 

	
 
    def item_author_email(self, item):
 
        GET = self.request.GET
 
        if not 'author' in GET:
 
            return "%s@sfconservancy.org" % item.author
 
        else:
 
            answer = ""
 
            authors = GET.getlist('author')
 
            firstTime = True
 
            for author in authors:
 
                if not firstTime:
 
                    answer = "%s@sfconservancy.org" % author
 
                    firstTime = False
 
                else:
 
                    answer += ",%s@sfconservancy.org" % author
 

	
 
    def item_pubdate(self, item):
 
        return item.pub_date
 
    def items(self):
 
        GET = self.request.GET
 

	
 
        def OR_filter(field_name, subfield_name, objs):
 
            from django.db.models import Q
 
            return reduce(lambda x, y: x | y,
 
                          [Q(**{'%s__%s' % (field_name, subfield_name): x})
 
                           for x in objs])
 

	
 
        queryset = BlogEntry.objects.filter(pub_date__lte=datetime.now())
 

	
 
        if 'author' in GET:
 
            authors = GET.getlist('author')
 
            queryset = queryset.filter(OR_filter('author', 'username', authors))
 

	
 
        if 'tag' in GET:
 
            tags = GET.getlist('tag')
 
            queryset = queryset.filter(OR_filter('tags', 'slug', tags))
 

	
 
        return queryset.order_by('-pub_date')[:10]
 

	
 

	
 
feed_dict = {
 
    'blog': BlogFeed,
 
    'news': PressReleaseFeed,
 
    'omnibus': OmnibusFeed,
 
#    'event-media': RecentEventMediaFeed,
 
}
 
# make each feed know its canonical url
 

	
 
for k, v in feed_dict.items():
 
    v.get_absolute_url = '/feeds/%s/' % k
 

	
 
def view(request):
 
    """Listing of all available feeds
 
    """
 

	
 
    feeds = feed_dict.values()
 
    return render_to_response("feeds.html", {'feeds': feeds})
www/conservancy/urls.py
Show inline comments
 
# Copyright 2005-2008, James Garrison
 
# Copyright 2010, 2012 Bradley M. Kuhn
 

	
 
# This software's license gives you freedom; you can copy, convey,
 
# propagate, redistribute, modify and/or redistribute modified versions of
 
# this program under the terms of the GNU Affero General Public License
 
# (AGPL) as published by the Free Software Foundation (FSF), either
 
# version 3 of the License, or (at your option) any later version of the
 
# AGPL published by the FSF.
 
#
 
# This program is distributed in the hope that it will be useful, but
 
# WITHOUT ANY WARRANTY; without even the implied warranty of
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero
 
# General Public License for more details.
 
#
 
# You should have received a copy of the GNU Affero General Public License
 
# along with this program in a file in the toplevel directory called
 
# "AGPLv3".  If not, see <http://www.gnu.org/licenses/>.
 

	
 
from django.conf.urls.defaults import *
 
from conservancy.feeds import feed_dict
 
from django.contrib import admin
 

	
 
handler404 = 'modpythoncustom.view404'
 

	
 
admin.autodiscover()
 

	
 
urlpatterns = patterns('',
 
    (r'^admin/doc/', include('django.contrib.admindocs.urls')),
 
    (r'^admin/(.*)', admin.site.urls),
 
    (r'^$', 'conservancy.frontpage.view'),
 
    (r'^feeds/(?P<url>.*)/?$', 'django.contrib.syndication.views.Feed',
 
     {'feed_dict': feed_dict}),
 
    (r'^feeds/blog/?$', 'django.contrib.syndication.views.Feed', BlogFeed()),
 
    (r'^feeds/news/?$', 'django.contrib.syndication.views.Feed', PressReleaseFeed()),
 
    (r'^feeds/omnibus/?$', 'django.contrib.syndication.views.Feed', OmnibusFeed()),
 
    (r'^feeds/?$', 'conservancy.feeds.view'),
 
    (r'^news(/|$)', include('conservancy.apps.news.urls')),
 
    (r'^blog(/|$)', include('conservancy.apps.blog.urls')),
 
)
0 comments (0 inline, 0 general)