Skip to content

Instantly share code, notes, and snippets.

@gregnewman
Created March 24, 2016 14:21
Show Gist options
  • Save gregnewman/38cb5c7d1bb7ca85db60 to your computer and use it in GitHub Desktop.
Save gregnewman/38cb5c7d1bb7ca85db60 to your computer and use it in GitHub Desktop.
def page(self):
modules = self.object.course_instance.published_modules
for index, module in enumerate(modules):
if module == self.object:
prev_i = index - 1
next_i = index + 1
break
previous_module = modules[prev_i] if prev_i >= 0 else None
next_module = modules[next_i] if next_i < len(modules) else None
return {
"previous": previous_module,
"next": next_module,
}
<section>
{% if vew.page.previous %}
<a href="{% url 'courseinstancemodule_detail' courseinstancemodule.course_instance.slug view.page.previous.id %}">Previous</a>
{% else %}
<a href="{% url 'course_instance_detail' courseinstancemodule.course_instance.slug %}">Previous</a>
{% endif %}
{% if vew.page.next %}
<a href="{% url 'courseinstancemodule_detail' courseinstancemodule.course_instance.slug view.page.next.id %}">Next</a>
{% endif %}
</section>
DEBUG:
Previous: <History of the Symphony [initial version]: Lesson One for History of the Symphony>
Next: <History of the Symphony [initial version]: Lesson Three for History of the Symphony>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment