| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
from django.http import Http404 |
|---|
| 4 |
from django.contrib.syndication.feeds import Feed |
|---|
| 5 |
|
|---|
| 6 |
from sphene.community.middleware import get_current_group |
|---|
| 7 |
from sphene.sphblog.models import BlogPostExtension |
|---|
| 8 |
from sphene.sphblog.views import get_board_categories, get_blog_posts_queryset |
|---|
| 9 |
from sphene.sphboard.models import Post |
|---|
| 10 |
|
|---|
| 11 |
class LatestBlogPosts(Feed): |
|---|
| 12 |
|
|---|
| 13 |
description = 'Latest Blog Posts' |
|---|
| 14 |
|
|---|
| 15 |
link = '/blog/' |
|---|
| 16 |
|
|---|
| 17 |
title_template = 'sphene/sphblog/feeds/latestposts_title.html' |
|---|
| 18 |
description_template = 'sphene/sphblog/feeds/latestposts_description.html' |
|---|
| 19 |
|
|---|
| 20 |
def get_object(self, bits): |
|---|
| 21 |
group = get_current_group() |
|---|
| 22 |
categories = get_board_categories(group) |
|---|
| 23 |
if len(bits) != 1: |
|---|
| 24 |
return categories |
|---|
| 25 |
category_id = int(bits[0]) |
|---|
| 26 |
categories = [category for category in categories \ |
|---|
| 27 |
if category.id == category_id] |
|---|
| 28 |
if not categories: |
|---|
| 29 |
raise Http404 |
|---|
| 30 |
return categories |
|---|
| 31 |
|
|---|
| 32 |
def title(self, obj): |
|---|
| 33 |
if len(obj) == 1: |
|---|
| 34 |
return obj[0].name |
|---|
| 35 |
group = get_current_group() |
|---|
| 36 |
return group.get_name() |
|---|
| 37 |
|
|---|
| 38 |
def items(self, obj): |
|---|
| 39 |
group = get_current_group() |
|---|
| 40 |
categories = obj |
|---|
| 41 |
threads = get_blog_posts_queryset(group, categories ) |
|---|
| 42 |
return threads |
|---|
| 43 |
|
|---|
| 44 |
def item_pubdate(self, item): |
|---|
| 45 |
return item.post.postdate |
|---|
| 46 |
|
|---|
| 47 |
def item_link(self, item): |
|---|
| 48 |
return item.get_absolute_url() |
|---|
| 49 |
|
|---|
| 50 |
def item_categories(self, item): |
|---|
| 51 |
return item.get_tag_labels() |
|---|
| 52 |
|
|---|