# HG changeset patch # User Brian Neal # Date 1268274847 0 # Node ID b7ac381996e8da63bc6d62fd916db97aaf00a0ff # Parent 776028f4bced1095e9a969b6f8dda6beaefcbd62 Implement ticket #59; update RSS feeds for Django 1.2. diff -r 776028f4bced -r b7ac381996e8 gpp/core/functions.py --- a/gpp/core/functions.py Wed Mar 03 04:09:42 2010 +0000 +++ b/gpp/core/functions.py Thu Mar 11 02:34:07 2010 +0000 @@ -1,4 +1,5 @@ """This file houses various core utility functions for GPP""" +import datetime import django.core.mail from django.contrib.sites.models import Site @@ -49,3 +50,14 @@ return full_name return user.username + +BASE_YEAR = 2010 + +def copyright_str(): + curr_year = datetime.datetime.now().year + if curr_year == BASE_YEAR: + year_range = str(BASE_YEAR) + else: + year_range = "%d - %d" % (BASE_YEAR, curr_year) + + return 'Copyright (C) %s, SurfGuitar101.com' % year_range diff -r 776028f4bced -r b7ac381996e8 gpp/forums/feeds.py --- a/gpp/forums/feeds.py Wed Mar 03 04:09:42 2010 +0000 +++ b/gpp/forums/feeds.py Thu Mar 11 02:34:07 2010 +0000 @@ -1,26 +1,36 @@ """This file contains the feed class for the forums application.""" -import datetime -from django.contrib.syndication.feeds import Feed +from django.contrib.syndication.views import Feed from django.core.exceptions import ObjectDoesNotExist +from django.shortcuts import get_object_or_404 +from django.utils.decorators import method_decorator +from django.views.decorators.cache import cache_page from forums.models import Forum from forums.models import Post +from core.functions import copyright_str -BASE_YEAR = 2010 class ForumsFeed(Feed): - """The Feed class for the forums application""" + """The Feed class for a specific forum""" - def get_object(self, bits): + ttl = '720' + author_name = 'Brian Neal' + author_email = 'admin@surfguitar101.com' + + @method_decorator(cache_page(15 * 60)) + def __call__(self, request, *args, **kwargs): + return super(ForumsFeed, self).__call__(request, *args, **kwargs) + + def get_object(self, request, forum_slug): # only return public forums - if len(bits) == 1: - forum = Forum.objects.get(slug=bits[0]) + if forum_slug: + forum = get_object_or_404(Forum, slug=forum_slug) if forum.category.groups.count() > 0: raise ObjectDoesNotExist return forum - elif len(bits) == 0: + else: # return None to indicate we want a combined feed return None @@ -45,20 +55,9 @@ return "User posts to SurfGuitar101.com forums." return obj.description - def copyright(self): - curr_year = datetime.datetime.now().year - if curr_year == BASE_YEAR: - year_range = str(BASE_YEAR) - else: - year_range = "%d - %d" % (BASE_YEAR, curr_year) + def feed_copyright(self): + return copyright_str() - return 'Copyright (C) %s, SurfGuitar101.com' % year_range - - ttl = '720' - - title_template = 'forums/feed_title.html' - description_template = 'forums/feed_description.html' - def items(self, obj): if obj is None: # return a combined feed of public forum threads @@ -68,6 +67,15 @@ items = Post.objects.filter(topic__forum__id=obj.id) return items.order_by('-creation_date').select_related()[:10] + def item_title(self, item): + return item.topic.name + + def item_description(self, item): + return item.html + + def item_author_name(self, item): + return item.user.username + def item_pubdate(self, item): return item.creation_date diff -r 776028f4bced -r b7ac381996e8 gpp/news/feeds.py --- a/gpp/news/feeds.py Wed Mar 03 04:09:42 2010 +0000 +++ b/gpp/news/feeds.py Thu Mar 11 02:34:07 2010 +0000 @@ -1,13 +1,13 @@ """ This file contains the feed classes for the news application. """ -import datetime - -from django.contrib.syndication.feeds import Feed +from django.contrib.syndication.views import Feed +from django.utils.decorators import method_decorator +from django.views.decorators.cache import cache_page from news.models import Story - -BASE_YEAR = 2010 +from core.functions import get_full_name +from core.functions import copyright_str class LatestNewsFeed(Feed): @@ -17,22 +17,28 @@ link = '/feeds/news/' description = 'News articles and stories from SurfGuitar101.com' ttl = '720' + author_name = 'Brian Neal' + author_email = 'admin@surfguitar101.com' - title_template = 'news/feed_title.html' - description_template = 'news/feed_description.html' + @method_decorator(cache_page(4 * 60 * 60)) + def __call__(self, request, *args, **kwargs): + return super(LatestNewsFeed, self).__call__(request, *args, **kwargs) - def copyright(self): - curr_year = datetime.datetime.now().year - if curr_year == BASE_YEAR: - year_range = str(BASE_YEAR) - else: - year_range = "%d - %d" % (BASE_YEAR, curr_year) - - return 'Copyright (C) %s, SurfGuitar101.com' % year_range + def feed_copyright(self): + return copyright_str() def items(self): return Story.objects.order_by('-date_published')[:5] + def item_title(self, item): + return item.title + + def item_description(self, item): + return item.short_text + item.long_text + + def item_author_name(self, item): + return get_full_name(item.submitter) + def item_pubdate(self, item): return item.date_published diff -r 776028f4bced -r b7ac381996e8 gpp/templates/forums/feed_description.html --- a/gpp/templates/forums/feed_description.html Wed Mar 03 04:09:42 2010 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -{{ obj.html|safe }} diff -r 776028f4bced -r b7ac381996e8 gpp/templates/forums/feed_title.html --- a/gpp/templates/forums/feed_title.html Wed Mar 03 04:09:42 2010 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -{{ obj.topic.name }} diff -r 776028f4bced -r b7ac381996e8 gpp/templates/home.html --- a/gpp/templates/home.html Wed Mar 03 04:09:42 2010 +0000 +++ b/gpp/templates/home.html Thu Mar 11 02:34:07 2010 +0000 @@ -8,7 +8,7 @@ {% load cache %} {% block title %}Home{% endblock %} {% block custom_head %} - + {% endblock %} {% block custom_css %} diff -r 776028f4bced -r b7ac381996e8 gpp/templates/news/base.html --- a/gpp/templates/news/base.html Wed Mar 03 04:09:42 2010 +0000 +++ b/gpp/templates/news/base.html Thu Mar 11 02:34:07 2010 +0000 @@ -1,13 +1,13 @@ {% extends 'base.html' %} {% block custom_head %} - + {% endblock %} {% block custom_css %} {% block news_css %}{% endblock %} {% endblock %} {% block content %} -

SurfGuitar101 News & Articles News Feed

+

SurfGuitar101 News & Articles News Feed

{% if search_form %}