Permalink
Browse files

article list pages handle tag intersection queries

  • Loading branch information...
1 parent 7a082c9 commit 5b72c60cb26add9d76d730dce780958d5ac73e6e @ryanpitts ryanpitts committed Oct 28, 2012
@@ -1,3 +1,3 @@
{% extends "base.html" %}
{% set active_nav = "features" %}
-{% block page_title %}Features{% if tag %} / {{ tag.name }}{% endif %} - {{ super() }}{% endblock %}
+{% block page_title %}Features{% if tags %} tagged: {% for tag in tags %}{{ tag.name }}{% if not loop.last %}, {% endif %}{% endfor %}{% endif %} - {{ super() }}{% endblock %}
@@ -2,7 +2,7 @@
{% block content %}
{% if section %}
-<h1 class="maintopic"><a href="{{ url('article_list_by_section', section.slug) }}">{{ section.name }}</a>{% if category %} / <span class="category">{{ category }}</span>{% endif %}{% if tag %} / <span class="category">{{ tag.name }}</span>{% endif %}</h1>
+<h1 class="maintopic"><a href="{{ url('article_list_by_section', section.slug) }}">{{ section.name }}</a>{% if category %} / <span class="category">{{ category }}</span>{% endif %}{% if tags %} / <span class="category">{% for tag in tags %}{{ tag.name }}{% if not loop.last %}, {% endif %}{% endfor %}</span>{% endif %}</h1>
{% endif %}
{% for article in page.object_list %}
View
@@ -15,13 +15,13 @@
# name = 'article_list',
#,
url(
- regex = '^tags/(?P<tag_slug>[-\w]+)/$',
+ regex = '^tags/(?P<tag_slugs>[-\w\+]+)/$',
view = ArticleList.as_view(),
kwargs = {},
name = 'article_list_by_tag',
),
url(
- regex = '^tags/(?P<tag_slug>[-\w]+)/rss/$',
+ regex = '^tags/(?P<tag_slugs>[-\w\+]+)/rss/$',
view = cache_page(ArticleFeed(), 60*15),
kwargs = {},
name = 'article_list_by_tag_feed',
View
@@ -67,9 +67,9 @@ class ArticleList(ListView):
def dispatch(self, *args, **kwargs):
self.section = kwargs.get('section', None)
self.category = kwargs.get('category', None)
- self.tag_slug = kwargs.get('tag_slug', None)
- self.tag = None
-
+ self.tags = None
+ self.tag_slugs = kwargs.get('tag_slugs', None)
+ self.tag_slug_list = []
return super(ArticleList, self).dispatch(*args, **kwargs)
def get_queryset(self):
@@ -79,9 +79,12 @@ def get_queryset(self):
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:
- self.tag = get_object_or_404(Tag, slug=self.kwargs['tag_slug'])
- queryset = queryset.filter(tags__slug=self.kwargs['tag_slug'])
+ elif 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]
+ for tag_slug in self.tag_slug_list:
+ queryset = queryset.filter(tags__slug=tag_slug)
return queryset
@@ -99,12 +102,12 @@ def get_section_links(self, context):
'active_nav': CATEGORY_MAP[self.category]['parent_slug'],
'rss_link': reverse('article_list_by_category_feed', kwargs={'category': self.category}),
})
- elif self.tag:
+ elif self.tags:
context.update({
'section': SECTION_MAP['articles'],
'active_nav': SECTION_MAP['articles']['slug'],
- 'tag':self.tag,
- 'rss_link': reverse('article_list_by_tag_feed', kwargs={'tag_slug': self.tag_slug}),
+ 'tags':self.tags,
+ 'rss_link': reverse('article_list_by_tag_feed', kwargs={'tag_slugs': self.tag_slugs}),
})
else:
context.update({

0 comments on commit 5b72c60

Please sign in to comment.