| 1 |
from django.contrib.syndication.feeds import Feed |
|---|
| 2 |
from blog.models import Entry |
|---|
| 3 |
from tagging.models import Tag, TaggedItem |
|---|
| 4 |
from django.core.exceptions import ObjectDoesNotExist |
|---|
| 5 |
from django.http import Http404 |
|---|
| 6 |
|
|---|
| 7 |
class LatestEntries(Feed): |
|---|
| 8 |
title = "Satchmoproject.com blog entries" |
|---|
| 9 |
link = "http://www.satchmoproject.com/blog/" |
|---|
| 10 |
description = "Updates on the latest postings at the satchmo project web site." |
|---|
| 11 |
|
|---|
| 12 |
def items(self): |
|---|
| 13 |
return Entry.objects.published().order_by('-pub_date')[:5] |
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
class LatestEntriesByTag(Feed): |
|---|
| 17 |
|
|---|
| 18 |
def get_object(self, bits): |
|---|
| 19 |
# In case of "/rss/beats/0613/foo/bar/baz/", or other such clutter, |
|---|
| 20 |
# check that bits has only one member. |
|---|
| 21 |
if len(bits) != 1: |
|---|
| 22 |
raise ObjectDoesNotExist |
|---|
| 23 |
entry_tag = Tag.objects.get(name=bits[0]) |
|---|
| 24 |
return TaggedItem.objects.get_by_model(Entry, entry_tag), bits[0] |
|---|
| 25 |
|
|---|
| 26 |
def title(self, obj): |
|---|
| 27 |
return "Latest satchmo project news by tag" |
|---|
| 28 |
|
|---|
| 29 |
def link(self, obj): |
|---|
| 30 |
try: |
|---|
| 31 |
return "http://www.satchmoproject.com/blog/tag/%s/" % obj[1] |
|---|
| 32 |
except TypeError: |
|---|
| 33 |
return "http://www.satchmoproject.com/blog/tag/" |
|---|
| 34 |
|
|---|
| 35 |
def description(self, obj): |
|---|
| 36 |
try: |
|---|
| 37 |
return "Satchmo items tagged with %s" % obj[1] |
|---|
| 38 |
except TypeError: |
|---|
| 39 |
return "Unknown tag" |
|---|
| 40 |
|
|---|
| 41 |
def items(self, obj): |
|---|
| 42 |
if obj: |
|---|
| 43 |
return obj[0].order_by('-pub_date')[:5] |
|---|
| 44 |
else: |
|---|
| 45 |
raise Http404 |
|---|