mediatr / feeds.py

from atompub.atom import Feed
from django.contrib.sites.models import Site


from models import Stream

def full_url(location):
    return 'http://%s%s' % (Site.objects.get_current().domain, location)

class StreamFeed(Feed):
    def get_object(self, params):
        if len(params) != 1:
            raise LookupError
        return Stream.objects.get(slug=params[0])

    def feed_id(self, obj):
        return obj.get_absolute_url()

    def feed_title(self, obj):
        return obj.name
    
    def feed_subtitle(self, obj):
        return obj.description
    
    def feed_links(self, obj):
        return [{"rel": "alternate", "href": full_url(obj.get_absolute_url()) }]
    
    def feed_icon(self, obj):
        return obj.icon.url

    def feed_authors(self, obj):
        return [{"name": obj.author.get_full_name()}]
    
    def feed_rights(self, obj):
        return obj.copyright
    
    def items(self, obj):
        return obj.items.order_by('-publish_date')
        
    def item_id(self, item):
        return item.get_absolute_url()
    
    def item_title(self, item):
        return item.name
    
    def item_content(self, item):
        if item.is_image():
            return {"type": "html"}, u"<img src="%s" alt=""/><br/>\n%s" % (item.file.url, item.text)
        else:
            return {"type": "html"}, item.text
    
    def item_updated(self, item):
        return item.publish_date
    
    def item_links(self, item):
        return [{'rel': 'enclosure', 'href': item.file.url, 'length': item.file.size, 'type': item.mime.name},
                {'rel': 'alternate', 'href': full_url(item.get_absolute_url())}]
    

        
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.