Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add RSS feed for recipes by tag #15

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions feed/urls.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from django.conf.urls import *
from views import RecentRecipesFeed,TopRecipesFeed
from views import RecentRecipesFeed,TopRecipesFeed,TaggedRecipesFeed

urlpatterns = patterns('',
(r'^recent/$', RecentRecipesFeed()),
(r'^top/$', TopRecipesFeed()),
)
(r'^tag/(?P<tag>[-\w]+)/$', TaggedRecipesFeed()),
)
31 changes: 30 additions & 1 deletion feed/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from django.conf import settings
from django.utils.translation import ugettext as _
from recipe.models import Recipe
from taggit.models import Tag, TaggedItem


class RecentRecipesFeed(Feed):
Expand Down Expand Up @@ -32,4 +33,32 @@ def item_title(self, item):
return item.title

def item_description(self, item):
return item.info
return item.info

class TaggedRecipesFeed(Feed):

def get_object(self, request, tag):
return tag

def title(self, tag):
return settings.OETITLE + _(" Recipes tagged %s") % tag

def link(self, tag):
return "/tags/recipe/" + tag + "/"

def description(self, tag):
return _("New recipes tagged %s added to %s") % (tag, settings.OETITLE)

def items(self, tag):
try:
recipe_tag = Tag.objects.get(slug=tag)
except Tag.DoesNotExist:
return []
recipes_tagged = TaggedItem.objects.filter(tag=recipe_tag).order_by('-id')[:10]
return [recipe.content_object for recipe in recipes_tagged]

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

def item_description(self, item):
return item.info
5 changes: 4 additions & 1 deletion tags/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,7 @@ def recipeTags(request, tag):
for recipe in recipes_tagged:
recipe_list.append(recipe.content_object)

return render_to_response('tags/recipe_tags.html', {'recipe_list': recipe_list}, context_instance=RequestContext(request))
return render_to_response('tags/recipe_tags.html', {
'recipe_list': recipe_list,
'recipe_tag': tag
}, context_instance=RequestContext(request))
1 change: 1 addition & 0 deletions templates/tags/recipe_tags.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<script type="text/javascript" src="{{ STATIC_URL }}js/jquery.ui.stars/jquery.ui.stars.js"></script>
<link href="{{ STATIC_URL }}js/jquery.ui.stars/crystal-stars.css" rel="stylesheet" />
{% endblock %}
{% block feeds %}<link href="/feed/tag/{{ recipe_tag }}" rel="alternate" type="application/rss+xml" title="{{ OETITLE }}{% blocktrans %} Feed: Recipes tagged {{ recipe_tag }}{% endblocktrans %}" />{% endblock %}

{% block content %}
{% autopaginate recipe_list %}
Expand Down