Skip to content
Closed
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
46 changes: 32 additions & 14 deletions kitsune/products/tests/test_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,16 +154,25 @@ def test_subtopics(self):
url = reverse('products.documents', args=[p.slug, t.slug])
r = self.client.get(url, follow=True)
eq_(200, r.status_code)
doc = pq(r.content)
eq_(0, len(doc('ul.subtopics')))
pqdoc = pq(r.content)
eq_(0, len(pqdoc('ul.subtopics')))

# Create a subtopic and verify it is listed
topic(parent=t, save=True)
url = reverse('products.documents', args=[p.slug, t.slug])
# Create a subtopic, it still shouldn't show up because no
# articles are assigned.
subtopic = topic(parent=t, save=True)
r = self.client.get(url, follow=True)
eq_(200, r.status_code)
doc = pq(r.content)
eq_(1, len(doc('ul.subtopics')))
pqdoc = pq(r.content)
eq_(0, len(pqdoc('ul.subtopics')))

# Add a document to the subtopic, now it should appear.
doc.topics.add(subtopic)
self.refresh()

r = self.client.get(url, follow=True)
eq_(200, r.status_code)
pqdoc = pq(r.content)
eq_(1, len(pqdoc('ul.subtopics')))


class ProductViewsNewTopicsTestCase(ElasticTestCase):
Expand Down Expand Up @@ -312,13 +321,22 @@ def test_subtopics(self):
url = reverse('products.documents', args=[p.slug, t.slug])
r = self.client.get(url, follow=True)
eq_(200, r.status_code)
doc = pq(r.content)
eq_(0, len(doc('ul.subtopics')))
pqdoc = pq(r.content)
eq_(0, len(pqdoc('ul.subtopics')))

# Create a subtopic and verify it is listed
new_topic(parent=t, product=p, save=True)
url = reverse('products.documents', args=[p.slug, t.slug])
# Create a subtopic, it still shouldn't show up because no
# articles are assigned.
subtopic = new_topic(parent=t, product=p, save=True)
r = self.client.get(url, follow=True)
eq_(200, r.status_code)
doc = pq(r.content)
eq_(1, len(doc('ul.subtopics')))
pqdoc = pq(r.content)
eq_(0, len(pqdoc('ul.subtopics')))

# Add a document to the subtopic, now it should appear.
doc.new_topics.add(subtopic)
self.refresh()

r = self.client.get(url, follow=True)
eq_(200, r.status_code)
pqdoc = pq(r.content)
eq_(1, len(pqdoc('ul.subtopics')))
7 changes: 3 additions & 4 deletions kitsune/products/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def product_landing(request, template, slug):
'topics': topics_for(
products=[product],
new_topics=new_topics,
include_subtopics=False),
parent=None),
'hot_docs': hot_docs,
'fallback_hot_docs': fallback_hot_docs,
'search_params': {'product': slug}})
Expand All @@ -59,10 +59,8 @@ def document_listing(request, template, product_slug, topic_slug):

if new_topics:
topic = get_object_or_404(NewTopic, slug=topic_slug, product=product)
subtopics = NewTopic.objects.filter(parent=topic)
else:
topic = get_object_or_404(Topic, slug=topic_slug)
subtopics = Topic.objects.filter(parent=topic)

documents, fallback_documents = documents_for(
locale=request.LANGUAGE_CODE, products=[product], topics=[topic],
Expand All @@ -72,7 +70,8 @@ def document_listing(request, template, product_slug, topic_slug):
'product': product,
'topic': topic,
'topics': topics_for(products=[product], new_topics=new_topics),
'subtopics': subtopics,
'subtopics': topics_for(
products=[product], parent=topic, new_topics=new_topics),
'documents': documents,
'fallback_documents': fallback_documents,
'search_params': {'product': product_slug}})
7 changes: 4 additions & 3 deletions kitsune/wiki/facets.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@


# TODO: Remove the new_topics argument when we remove old topics.
def topics_for(products, include_subtopics=True, new_topics=False):
def topics_for(products, parent=False, new_topics=False):
"""Returns a list of topics that apply to passed in products and topics.

:arg products: a list of Product instances
:arg parent: (optional) limit to topics with the given parent
"""
statsd.incr('wiki.facets.topics_for.db')

Expand All @@ -40,8 +41,8 @@ def topics_for(products, include_subtopics=True, new_topics=False):
.annotate(num_docs=Count('document'))
.distinct())

if not include_subtopics:
qs = qs.filter(parent=None)
if parent or parent is None:
qs = qs.filter(parent=parent)

return qs

Expand Down
4 changes: 4 additions & 0 deletions kitsune/wiki/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -810,6 +810,10 @@ def index(cls, document, **kwargs):
'wiki',
Document.topics.through,
m2m=True)
register_for_indexing(
'wiki',
Document.new_topics.through,
m2m=True)
register_for_indexing(
'wiki',
Document.products.through,
Expand Down