# Path: gitcms/blog/models.py
# class BlogPost(models.Model):
#     title = models.CharField(u'title', max_length=255)
#     slug = models.CharField(u'slug', max_length=255)
#     timestamp = models.DateTimeField(u'timestamp')
#     tags = models.ManyToManyField(Tag)
#     content = models.TextField(u'content')
#     status = models.CharField(u'status', max_length=255)
#     author = models.CharField(u'author', max_length=255)
#     keywords = models.CharField(u'keywords', max_length=255)
#     description = models.CharField(u'description', max_length=255)
# 
#     def __unicode__(self):
#         return '%s (%s)' % (self.slug, self.title)
# 
#     @models.permalink
#     def get_absolute_url(self):
#         return ('blog-post', [self.timestamp.year, self.timestamp.month, self.slug])


from django.contrib.syndication.views import Feed
from gitcms.blog.models import BlogPost
from django.conf import settings


class LatestFeed(Feed):
    title = getattr(settings, 'GITCMS_BLOG_FEED_NAME', 'Blog RSS channel')
    link = '/rss/'
    description = 'Updates on blog and items of interesting content'

    def items(self):
        limit = getattr(settings, 'LIMIT_RSS_ITEMS', 20)
        return BlogPost.objects.exclude(status='draft').order_by('-timestamp')[:limit]

    def item_title(self, post):
        return post.title

    def item_description(self, post):
        return post.content

    def item_link(self, post):

# Path: gitcms/blog/models.py
# class BlogPost(models.Model):
#     title = models.CharField(u'title', max_length=255)
#     slug = models.CharField(u'slug', max_length=255)
#     timestamp = models.DateTimeField(u'timestamp')
#     tags = models.ManyToManyField(Tag)
#     content = models.TextField(u'content')
#     status = models.CharField(u'status', max_length=255)
#     author = models.CharField(u'author', max_length=255)
#     keywords = models.CharField(u'keywords', max_length=255)
#     description = models.CharField(u'description', max_length=255)
# 
#     def __unicode__(self):
#         return '%s (%s)' % (self.slug, self.title)
# 
#     @models.permalink
#     def get_absolute_url(self):
#         return ('blog-post', [self.timestamp.year, self.timestamp.month, self.slug])


# Path: gitcms/blog/feeds.py
from django.contrib.syndication.views import Feed
from gitcms.blog.models import BlogPost
from django.conf import settings



class LatestFeed(Feed):
    title = getattr(settings, 'GITCMS_BLOG_FEED_NAME', 'Blog RSS channel')
    link = '/rss/'
    description = 'Updates on blog and items of interesting content'

    def items(self):
        limit = getattr(settings, 'LIMIT_RSS_ITEMS', 20)
        return BlogPost.objects.exclude(status='draft').order_by('-timestamp')[:limit]

    def item_title(self, post):
        return post.title

    def item_description(self, post):
        return post.content

    def item_link(self, post):

        return post.get_absolute_url()