Skip to content
Browse files

Merge pull request #879 from darkwing/children-redirects

Don't return null item redirects from children view
  • Loading branch information...
2 parents 5450f78 + 89a97ad commit b3671f1eb47fa625cad9d6c4b737e16fbe509796 @lmorchard lmorchard committed Feb 21, 2013
Showing with 14 additions and 7 deletions.
  1. +2 −1 apps/wiki/tests/__init__.py
  2. +8 −3 apps/wiki/tests/test_views.py
  3. +4 −3 apps/wiki/views.py
View
3 apps/wiki/tests/__init__.py
@@ -36,7 +36,8 @@ def tearDown(self):
def document(save=False, **kwargs):
"""Return an empty document with enough stuff filled out that it can be
saved."""
- defaults = {'category': CATEGORIES[0][0], 'title': str(datetime.now())}
+ defaults = {'category': CATEGORIES[0][0], 'title': str(datetime.now()),
+ 'is_redirect': 0}
defaults.update(kwargs)
if 'slug' not in kwargs:
defaults['slug'] = slugify(defaults['title'])
View
11 apps/wiki/tests/test_views.py
@@ -168,9 +168,13 @@ def test_toc_view(self):
def test_children_view(self):
test_content = '<p>Test <a href="http://example.com">Summary</a></p>'
- def _make_doc(title, slug, parent=None):
- doc = document(title=title, slug=slug, save=True)
- doc.html = test_content
+ def _make_doc(title, slug, parent=None, is_redir=False):
+ doc = document(title=title, slug=slug, save=True, is_redirect=is_redir)
+ if is_redir:
+ content = 'REDIRECT <a class="redirect" href="x">Blah</a>'
+ else:
+ content = test_content
+ doc.html = content
if parent:
doc.parent_topic = parent
doc.save()
@@ -185,6 +189,7 @@ def _make_doc(title, slug, parent=None):
great_grandchild_doc_1 = _make_doc('Great Grandchild 1',
'Root/Child_1/Grandchild_2/Great_Grand_Child_1', grandchild_doc_2)
child_doc_2 = _make_doc('Child 2', 'Root/Child_2', root_doc)
+ child_doc_3 = _make_doc('Child 3', 'Root/Child_3', root_doc, True)
resp = self.client.get(reverse('wiki.get_children', args=['Root'],
locale=settings.WIKI_DEFAULT_LANGUAGE))
View
7 apps/wiki/views.py
@@ -1278,7 +1278,7 @@ def get_children(request, document_slug, document_locale):
try:
def _make_doc_structure(d, level):
if d.is_redirect:
- return
+ return None
res = {
'title': d.title,
@@ -1293,8 +1293,9 @@ def _make_doc_structure(d, level):
descendants = d.get_descendants(1)
descendants.sort(key=lambda item: item.title)
for descendant in descendants:
- res['subpages'].append(_make_doc_structure(descendant,
- level + 1))
+ sp = _make_doc_structure(descendant, level + 1)
+ if sp is not None:
+ res['subpages'].append(sp)
return res
result = _make_doc_structure(Document.objects.

0 comments on commit b3671f1

Please sign in to comment.
Something went wrong with that request. Please try again.