summaryrefslogtreecommitdiff
path: root/blog/feeds.py
blob: cfdf4cc0545ab9325964691e4e2946eddc5f3c79 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from django.contrib.syndication.views import Feed
from django.core.urlresolvers import reverse
from django.utils.html import strip_tags as st
from .models import Post

def truncate_words(content, length=100, suffix='...'):
    if len(content) <= length:
        return content
    else:
        return content[:length].rsplit(' ',1)[0] + suffix

class PostFeed(Feed):
    title = "Mark Weiman's Blog"
    link = "/blog/"
    description = "Mark Weiman's blog of his opinions on mostly software"
  
    def items(self):
        return Post.objects.order_by('-created')
  
    def item_title(self, item):
        return item.title
  
    def item_description(self, item):
        return truncate_words(st(item.body))
  
    def item_link(self, item):
        return 'https://markzz.com/blog/post/' + str(item.id)

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