Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

article feeds handle tag intersection queries

  • Loading branch information...
commit 7a082c971e2ab130a722135f085af23b6e49413f 1 parent 957879e
@ryanpitts ryanpitts authored
Showing with 16 additions and 11 deletions.
  1. +16 −11 source/base/feeds.py
View
27 source/base/feeds.py
@@ -11,9 +11,13 @@ class ArticleFeed(Feed):
def get_object(self, request, *args, **kwargs):
self.section = kwargs.get('section', None)
self.category = kwargs.get('category', None)
- self.tag_slug = kwargs.get('tag_slug', None)
- if self.tag_slug:
- self.tag = get_object_or_404(Tag, slug=self.tag_slug)
+ self.tags = None
+ self.tag_slugs = kwargs.get('tag_slugs', None)
+ self.tag_slug_list = []
+ if self.tag_slugs:
+ self.tag_slug_list = self.tag_slugs.split('+')
+ # need to fail if any item in slug list references nonexistent tag
+ self.tags = [get_object_or_404(Tag, slug=tag_slug) for tag_slug in self.tag_slug_list]
return ''
def title(self, obj):
@@ -21,8 +25,8 @@ def title(self, obj):
return "Source: %s" % SECTION_MAP[self.section]['name']
elif self.category:
return "Source: Articles in the category %s" % CATEGORY_MAP[self.category]['name']
- elif self.tag_slug:
- return "Source: Articles tagged with '%s'" % self.tag.name
+ elif self.tag_slugs:
+ return "Source: Articles tagged with '%s'" % "+".join([tag.name for tag in self.tags])
return "Source"
def link(self, obj):
@@ -30,8 +34,8 @@ def link(self, obj):
return reverse('article_list_by_section', kwargs={'section': self.section})
elif self.category:
return reverse('article_list_by_category', kwargs={'category': self.category})
- elif self.tag_slug:
- return reverse('article_list_by_tag', kwargs={'tag_slug': self.tag_slug})
+ elif self.tag_slugs:
+ return reverse('article_list_by_tag', kwargs={'tag_slugs': self.tag_slugs})
return reverse('homepage')
def description(self, obj):
@@ -40,8 +44,8 @@ def description(self, obj):
identifier = "in the %s section" % SECTION_MAP[self.section]['name']
elif self.category:
identifier = "in the %s category" % CATEGORY_MAP[self.category]['name']
- elif self.tag_slug:
- identifier = "tagged with '%s'" % self.tag.name
+ elif self.tag_slugs:
+ identifier = "tagged with '%s'" % "+".join([tag.name for tag in self.tags])
return "Recent articles %s" % identifier
def item_title(self, item):
@@ -56,8 +60,9 @@ def items(self, obj):
queryset = queryset.filter(article_type__in=SECTION_MAP[self.section]['article_types'])
elif self.category:
queryset = queryset.filter(article_type=self.category)
- elif self.tag_slug:
- queryset = queryset.filter(tags__slug=self.tag_slug)
+ elif self.tag_slugs:
+ for tag_slug in self.tag_slug_list:
+ queryset = queryset.filter(tags__slug=tag_slug)
return queryset[:20]
class CodeFeed(Feed):
Please sign in to comment.
Something went wrong with that request. Please try again.