from django.contrib.syndication.views import Feed
from django.utils.feedgenerator import Atom1Feed
from blog.models import BlogEntry
from django.conf import settings

class LatestBlogEntriesRss(Feed):
    title = settings.BLOG_TITLE
    description = u'Updates on %s' %(title,)
    link = settings.BLOG_ROOT

    title_template = 'blog/feeds/title.html'
    description_template = 'blog/feeds/description.html'

    def items(self):
        try:
            return BlogEntry.objects.filter(islive=True).order_by('-publish_date')[:20]
        except:
            return BlogEntry.objects.filter(islive=True).order_by('-publish_date')

    def author_name(self, obj):
        return "Brett Parker"

    def author_email(self, obj):
        return "iDunno@sommitrealweird.co.uk"

    def item_author_name(self, obj):
        return "Brett Parker"

    def item_author_email(self, obj):
        return "iDunno@sommitrealweird.co.uk"

    def item_pubdate(self, obj):
        return obj.publish_date

class LatestBlogEntries(LatestBlogEntriesRss):
    feed_type = Atom1Feed
    subtitle = LatestBlogEntriesRss.description
