Permalink
Browse files

Add secondary story paths to the node page.

Not particularly stylish as yet.
  • Loading branch information...
fatbusinessman committed Aug 26, 2011
1 parent 5d2b7ad commit d8bc210c100711c78d1abf66ff970a5e0b2c3def
Showing with 59 additions and 29 deletions.
  1. +39 −29 antler/apps/core/models.py
  2. +20 −0 antler/templates/nodes/_full_story_nav.html
View
@@ -478,38 +478,48 @@ def set_current_node(self, node):
self.current_node = node
def next(self):
+ """Return the next node in this story.
+
+ Return the next node in the primary thread if on the primary thread for
+ this story; fall back to a secondary thread if off the primary.
+
"""
- Returns the next node in this story's primary thread, call
- set_current_node so that this makes sense.
- """
- try:
- nodes = self.current_node.outgoing('primary').filter(story=self).follow()
- except AttributeError:
- return
-
- if len(nodes) > 0:
- return nodes[0]
- else:
- nodes = self.current_node.outgoing('secondary').filter(story=self).follow()
- if len(nodes) > 0:
- return nodes[0]
-
+ return self._successor('primary') or self._successor('secondary')
+
+ def next_primary(self):
+ """Return the next node in this story's primary thread."""
+ return self._successor('primary')
+
+ def next_secondary(self):
+ """Return the next node in this story's secondary thread."""
+ return self._successor('secondary')
+
+ def _successor(self, verb):
+ if not getattr(self, 'current_node'):
+ return None
+ nodes = self.current_node.outgoing(verb).filter(story=self).follow()
+ return nodes[0] if nodes else None
+
def previous(self):
+ """Return the previous node in this story.
+
+ Return the previous node in the primary thread if on the primary thread
+ for this story; fall back to a secondary thread if off the primary.
+
"""
- Returns the previous node in this story's primary thread, call
- set_current_node first so that this make sense.
- """
- try:
- nodes = self.current_node.incoming('primary').filter(story=self).follow()
- except AttributeError:
- return
-
- if len(nodes) > 0:
- return nodes[0]
- else:
- nodes = self.current_node.incoming('secondary').filter(story=self).follow()
- if len(nodes) > 0:
- return nodes[0]
+ return self._predecessor('primary') or self._predecessor('secondary')
+
+ def previous_primary(self):
+ return self._predecessor('primary')
+
+ def previous_secondary(self):
+ return self._predecessor('secondary')
+
+ def _predecessor(self, verb):
+ if not getattr(self, 'current_node'):
+ return None
+ nodes = self.current_node.incoming(verb).filter(story=self).follow()
+ return nodes[0] if nodes else None
def story_content(self):
"""
@@ -22,3 +22,23 @@
{% endif %}
</li>
+<li class="prev alternate">
+ {% if story.prev_secondary and story.prev_primary %}
+ <dl class="secondary">
+ <dt>Also in <span class="story-name">{{ story.name }}</span></dt>
+ <dd class="thread story-name"><a href="{{ story.prev_secondary.url }}?story={{ story.slug }}">{{ story.prev_secondary.name }}</a></dd>
+ </dl>
+ {% else %}
+ <div class="next-disabled"></div>
+ {% endif %}
+</li>
+<li class="next alternate">
+ {% if story.next_secondary and story.next_primary %}
+ <dl class="secondary">
+ <dt>Also in <span class="story-name">{{ story.name }}</span></dt>
+ <dd class="thread story-name"><a href="{{ story.next_secondary.url }}?story={{ story.slug }}">{{ story.next_secondary.name }}</a></dd>
+ </dl>
+ {% else %}
+ <div class="next-disabled"></div>
+ {% endif %}
+</li>

0 comments on commit d8bc210

Please sign in to comment.