Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: mozilla/kuma
...
head fork: darkwing/kuma
compare: update-parent-background
Checking mergeability… Don't worry, you can still create the pull request.
  • 3 commits
  • 4 files changed
  • 0 commit comments
  • 2 contributors
Commits on Aug 30, 2012
@ubernostrum ubernostrum Bug 785212: Method for getting all children of a page
This is a somewhat naive recursive implementation that descends
through children, grandchildren, etc. and builds up a data structure
that clearly shows the relationships and sub-trees and so forth.

It is naive in the sense that A) it does not attempt to minimize the
number of DB queries involved in building the tree, and B) currently
has no way at all of detecting a circular dependency.
f36b371
Commits on Sep 10, 2012
@darkwing darkwing Merge branch 'page-children-785212' of https://github.com/ubernostrum… cb3e25d
Commits on Sep 11, 2012
@darkwing darkwing Improve translation parent styling 7a430a9
View
31 apps/wiki/models.py
@@ -1127,6 +1127,37 @@ def parents(self):
parents.insert(0, current_parent.parent_topic)
current_parent = current_parent.parent_topic
return parents
+
+ # This is a method, not a property, because it can do a lot of DB
+ # queries and so should look scarier. It's not just named
+ # 'children' because that's taken already by the reverse relation
+ # on parent_topic.
+ def get_all_children(self):
+ """
+ Return a tree of documents which have this one as their
+ topical parent.
+
+ The returned data structure is a list of dictionaries, like
+ so:
+
+ [
+ { 'document': <Document object>,
+ 'children': [] },
+ ]
+
+ Where 'children' is another data structure in the same
+ format. This allows not only walking through all child
+ documents, but specific sub-trees.
+
+ If there are no children, returns an empty list.
+ """
+ results = []
+ immediate_children = self.children.all()
+ if immediate_children.count():
+ for child in immediate_children:
+ results.append({'document': child,
+ 'children': child.get_all_children()})
+ return results
def has_voted(self, request):
"""Did the user already vote for this document?"""
View
6 apps/wiki/templates/wiki/edit_document.html
@@ -116,12 +116,10 @@
{% if show_translation_parent_block %}
<li class="metadata-choose-parent">
{% include 'wiki/includes/title_autosuggest_url.html' %}
- {{_('The translation source of this article is not set. To set the translation source ...')}}
+ {{_('Find the translation source with the lookup below and then click "Save Changes."')}}
<br />
- {{_('Search by English title:')}}
- <input type="text" id="parent_text" />
+ <strong>Lookup:</strong> <input type="text" id="parent_text" />
<input type="hidden" name="parent_id" id="parent_id" />
- {{_('Then click "Save Changes"')}}
</li>
{% endif %}
</ul>
View
69 apps/wiki/tests/test_models.py
@@ -1005,3 +1005,72 @@ def test_errors_stored_correctly(self, mock_kumascript_get):
r_rendered, r_errors = self.d1.get_rendered(None, 'http://testserver/')
ok_(errors, r_errors)
+
+
+class PageMoveTests(TestCase):
+ """Tests for page-moving and associated functionality."""
+ def test_children_simple(self):
+ """A basic tree with two direct children and no sub-trees on
+ either."""
+ d1 = document(title='Parent')
+ d2 = document(title='Child')
+ d2.parent_topic = d1
+ d2.save()
+ d3 = document(title='Another child')
+ d3.parent_topic = d1
+ d3.save()
+
+ expected = [
+ {'document': d2, 'children': []},
+ {'document': d3, 'children': []}
+ ]
+ ok_(expected == d1.get_all_children())
+
+ def test_children_complex(self):
+ """A slightly more complex tree, with multiple children, some
+ of which do/don't have their own children."""
+ top = document(title='Parent')
+
+ c1 = document(title='Child 1')
+ c1.parent_topic = top
+ c1.save()
+
+ gc1 = document(title='Child of child 1')
+ gc1.parent_topic = c1
+ gc1.save()
+
+ c2 = document(title='Child 2')
+ c2.parent_topic = top
+ c2.save()
+
+ gc2 = document(title='Child of child 2')
+ gc2.parent_topic = c2
+ gc2.save()
+
+ gc3 = document(title='Another child of child 2')
+ gc3.parent_topic = c2
+ gc3.save()
+
+ ggc1 = document(title='Child of the second child of child 2')
+ ggc1.parent_topic = gc3
+ ggc1.save()
+
+ expected = [
+ {'document': c1,
+ 'children': [
+ {'document': gc1,
+ 'children': []}
+ ]},
+ {'document': c2,
+ 'children': [
+ {'document': gc2,
+ 'children': []},
+ {'document': gc3,
+ 'children': [
+ {'document': ggc1,
+ 'children': []},
+ ]},
+ ]},
+ ]
+
+ ok_(expected == top.get_all_children())
View
4 media/css/wiki-screen.css
@@ -238,8 +238,8 @@ a.edit-section:hover, a.edit-section:active, a.edit-section:focus { color: #333;
.editing ul.metadata li input, .editing ul.metadata li input#id_title { font-size: 1em; padding: 6px 8px; margin: 2px 0px; width: 70%; }
.editing ul.metadata li input[type="checkbox"] { width: auto; margin-left: 6px; }
.editing ul.metadata li .metadataDisplay { display:inline-block; padding: 8px 0 0 3px; }
-.editing ul.metadata li.metadata-choose-parent { padding: 10px; background: lightblue; border-radius: 10px; margin: 0 10px; display: none; }
-.editing ul.metadata li.metadata-choose-parent #parent_text { display:block; margin-top:10px; }
+.editing ul.metadata li.metadata-choose-parent { padding: 10px; border: 1px solid #d4dde4; font-size: 90%; background: #eaeff2; background: linear-gradient(top, #eaeff2, #d4dde4); background: -moz-linear-gradient(top, #eaeff2, #d4dde4); background: -webkit-linear-gradient(top, #eaeff2, #d4dde4); border-radius: 10px; margin: 0 10px; display: none; }
+.editing ul.metadata li.metadata-choose-parent #parent_text { display: inline-block; margin-top:10px; }
.editing .title { float: left; width: 55%; }
.editing .title h1 { display: inline-block; width: auto; float: none; color: #888; float:left; }

No commit comments for this range

Something went wrong with that request. Please try again.