Changeset - 3c3de3e61bac
[Not reviewed]
0 1 0
Bradley Kuhn (bkuhn) - 13 years ago 2011-06-13 21:24:42
bkuhn@ebb.org
Link to news page; not perfect but better than other options.
1 file changed with 1 insertions and 1 deletions:
0 comments (0 inline, 0 general)
www/conservancy/feeds.py
Show inline comments
...
 
@@ -20,97 +20,97 @@ class ConservancyFeedBase(Feed):
 
        for attr in ('pub_date', 'date_created', 'date_last_modified'):
 
            if hasattr(item, attr):
 
                if hasattr(getattr(item, attr), 'year'):
 
                    year = getattr(getattr(item, attr), 'year')
 
                    break
 
        return 'Copyright (C) %d, %s.  %s' % (year, self.copyright_holder(), self.license_no_html())
 

	
 
    def item_extra_kwargs(self, item):
 
        year = 2008
 
        for attr in ('pub_date', 'date_created', 'date_last_modified'):
 
            if hasattr(item, attr):
 
                if hasattr(getattr(item, attr), 'year'):
 
                    year = getattr(getattr(item, attr), 'year')
 
                    break
 
        return { 'year' : year }
 

	
 
class PressReleaseFeed(Feed):
 
    title = "Software Freedom Conservancy News"
 
    link = "/news/"
 
    description = ""
 

	
 
    def items(self):
 
        return PressRelease.objects.filter(pub_date__lte=datetime.now(),
 
                                           sites__id__exact=settings.SITE_ID).order_by('-pub_date')[:10]
 

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

	
 
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 ="/omnibus/"
 
    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 = "http://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 "http://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 "http://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
 

	
0 comments (0 inline, 0 general)