Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[bug 778160] Topic page

  • Loading branch information...
commit a91b6b95e2f1897a344a26f6727c114914188e08 1 parent cd2374f
@rlr rlr authored
View
2  apps/landings/templates/landings/home.html
@@ -13,7 +13,7 @@
<ul>
{% for topic in topics[:6] %}
<li>
- <a href="{# TODO: add reverse url to topic page when we have it #}#">
+ <a href="{{ url('topics.topic', slug=topic.slug)|urlparams(selectproduct=1) }}">
<img src="{{ topic.image_url }}" alt="" />
{{ topic.title }}
</a>
View
32 apps/topics/templates/topics/topic.html
@@ -0,0 +1,32 @@
+{# vim: set ts=2 et sts=2 sw=2: #}
+{% extends "base.html" %}
+{% from 'products/includes/product_macros.html' import product_list %}
+{% set title = _(topic.title) %}
+{% set crumbs = [(None, title)] %}
+{# TODO: scripts and styles #}
+
+{% block content %}
+ <h1>{{ title }}</h1>
+
+ {% if products %}
+ <h2>{{ _('Select a product') }}</h2>
+ <section id="products-and-services">
+ {{ product_list(products) }}
+ </section>
+ {% endif %}
+
+ {% if documents %}
+ <section id="topic-documents">
+ <ul>
+ {% for document in documents %}
+ <li>
+ <a href="{{ document['url'] }}">
+ {{ document['document_title'] }}
+ </a>
+ </li>
+ {% endfor %}
+ </section>
+ {% endif %}
+{% endblock %}
+
+{% block for_contributors %}{% endblock %}
View
65 apps/topics/tests/test_templates.py
@@ -0,0 +1,65 @@
+import mock
+import waffle
+from nose.tools import eq_
+from pyquery import PyQuery as pq
+
+from products.tests import product
+from search.tests.test_es import ElasticTestCase
+from sumo.helpers import urlparams
+from sumo.urlresolvers import reverse
+from topics.tests import topic
+from wiki.tests import revision
+
+
+class TopicViewsTestCase(ElasticTestCase):
+ @mock.patch.object(waffle, 'flag_is_active')
+ def test_topic_select_product(self, flag_is_active):
+ """Verify that /topics/<slug>?selectproduct=1 renders products."""
+ flag_is_active.return_value = True
+
+ # Create a topic
+ t = topic(save=True)
+
+ # Create 3 products
+ prods = []
+ for i in range(3):
+ prods.append(product(save=True))
+
+ # Create a document and assign the topic and two products.
+ doc = revision(is_approved=True, save=True).document
+ doc.topics.add(t)
+ doc.products.add(prods[0])
+ doc.products.add(prods[1])
+
+ self.refresh()
+
+ # GET the topic page and verify the content
+ url = reverse('topics.topic', args=[t.slug])
+ url = urlparams(url, selectproduct=1)
+ r = self.client.get(url, follow=True)
+ eq_(200, r.status_code)
+ doc = pq(r.content)
+ eq_(2, len(doc('#products-and-services li')))
+
+ @mock.patch.object(waffle, 'flag_is_active')
+ def test_topic_document_listing(self, flag_is_active):
+ """Verify that /topics/<slug> renders articles."""
+ flag_is_active.return_value = True
+
+ # Create a topic
+ t = topic(save=True)
+
+ # Create 3 documents with the topic and one without
+ for i in range(3):
+ doc = revision(is_approved=True, save=True).document
+ doc.topics.add(t)
+ doc = revision(is_approved=True, save=True).document
+
+ self.refresh()
+
+ # GET the topic page and verify the content
+ url = reverse('topics.topic', args=[t.slug])
+ r = self.client.get(url, follow=True)
+ eq_(200, r.status_code)
+ doc = pq(r.content)
+ eq_(3, len(doc('#topic-documents li')))
View
5 apps/topics/urls.py
@@ -0,0 +1,5 @@
+from django.conf.urls.defaults import patterns, url
+
+urlpatterns = patterns('topics.views',
+ url(r'^/(?P<slug>[^/]+)$', 'topic_landing', name='topics.topic'),
+)
View
35 apps/topics/views.py
@@ -0,0 +1,35 @@
+from django.conf import settings
+from django.http import HttpResponseRedirect
+from django.shortcuts import get_object_or_404
+
+import jingo
+
+from landings.utils import show_ia
+from products.models import Product
+from sumo.urlresolvers import reverse
+from topics.models import Topic
+from wiki.facets import products_for, documents_for
+from wiki.models import Document
+
+
+def topic_landing(request, slug):
+ """The topic landing page.
+
+ If `selectproduct=1` query param is passed, shows the product picker.
+ Else, shows the list of articles.
+ """
+ if not show_ia(request):
+ # User should only be able to get here in new IA.
+ # Redirect to home page
+ return HttpResponseRedirect(reverse('home'))
+
+ topic = get_object_or_404(Topic, slug=slug)
+
+ data = dict(topic=topic)
+ if request.GET.get('selectproduct') == '1':
+ data.update(products=products_for(topics=[topic]))
+ else:
+ data.update(documents=documents_for(
+ locale=request.locale, topics=[topic]))
+
+ return jingo.render(request, 'topics/topic.html', data)
View
1  urls.py
@@ -30,6 +30,7 @@
(r'^karma', include('karma.urls')),
(r'^kpi/', include('kpi.urls')),
(r'^products', include('products.urls')),
+ (r'^topics', include('topics.urls')),
# Kitsune admin (not Django admin).
(r'^admin/', include(admin.site.urls)),
Please sign in to comment.
Something went wrong with that request. Please try again.