# HG changeset patch # User Brian Neal # Date 1286153878 0 # Node ID 593fb6dbd449cea3844842d9c6846bc8c391e5f1 # Parent 39664e661c6938e835dc4450bf3f0da611f79bac Fixing #125. Developed a forums navigation template tag to consistently display forum navigation. diff -r 39664e661c69 -r 593fb6dbd449 gpp/forums/templatetags/forum_tags.py --- a/gpp/forums/templatetags/forum_tags.py Mon Oct 04 00:56:54 2010 +0000 +++ b/gpp/forums/templatetags/forum_tags.py Mon Oct 04 00:57:58 2010 +0000 @@ -9,6 +9,7 @@ from django.core.cache import cache from django.contrib.auth.models import User +from forums.models import Forum from forums.models import Topic from forums.models import Post from core.models import Statistic @@ -169,3 +170,33 @@ return { 'topic': topic, } + + +@register.inclusion_tag('forums/navigation_tag.html') +def forum_navigation(obj, subtitle=None): + """ + Generates forum navigation links based upon the arguments passed. + If obj is: + * a string: Index >> String Text + * a forum: Index >> Forum Name + * a topic: Index >> Forum Name >> Topic Name + + If the optional subtitle argument is passed, it is assumed to be + a string, and is added as one more "level" in the navigation. + + """ + nav_list = [] + + if isinstance(obj, str) or isinstance(obj, unicode): + nav_list.append(dict(name=obj, url=None)) + elif isinstance(obj, Forum): + nav_list.append(dict(name=obj.name, url=obj.get_absolute_url())) + elif isinstance(obj, Topic): + forum = obj.forum + nav_list.append(dict(name=forum.name, url=forum.get_absolute_url())) + nav_list.append(dict(name=obj.name, url=obj.get_absolute_url())) + + if subtitle: + nav_list.append(dict(name=subtitle, url=None)) + + return dict(nav_list=nav_list, MEDIA_URL=settings.MEDIA_URL) diff -r 39664e661c69 -r 593fb6dbd449 gpp/templates/forums/edit_post.html --- a/gpp/templates/forums/edit_post.html Mon Oct 04 00:56:54 2010 +0000 +++ b/gpp/templates/forums/edit_post.html Mon Oct 04 00:57:58 2010 +0000 @@ -3,13 +3,7 @@ {% block title %}Forums: Edit Post{% endblock %} {% block custom_js %}{{ form.media }}{% endblock %} {% block content %} -

Forums: Edit Post

- -

- SurfGuitar101 Forum Index » - {{ forum.name }} » - {{ topic.name }} -

+{% forum_navigation topic "Edit Post" %}
diff -r 39664e661c69 -r 593fb6dbd449 gpp/templates/forums/favorite_status.html --- a/gpp/templates/forums/favorite_status.html Mon Oct 04 00:56:54 2010 +0000 +++ b/gpp/templates/forums/favorite_status.html Mon Oct 04 00:57:58 2010 +0000 @@ -1,12 +1,8 @@ {% extends 'base.html' %} +{% load forum_tags %} {% block title %}Forums: Favorite Topics{% endblock %} {% block content %} -

Forums: Favorite Topics

-

- SurfGuitar101 Forum Index » - {{ topic.forum.name }} » - {{ topic.name }} -

+{% forum_navigation topic "Favorite Topics Updated" %}

{% if is_favorite %} The forum topic {{ topic.name }} has been added to your diff -r 39664e661c69 -r 593fb6dbd449 gpp/templates/forums/forum_index.html --- a/gpp/templates/forums/forum_index.html Mon Oct 04 00:56:54 2010 +0000 +++ b/gpp/templates/forums/forum_index.html Mon Oct 04 00:57:58 2010 +0000 @@ -7,16 +7,7 @@ {% endblock %} {% block title %}Forums: {{ forum.name }}{% endblock %} {% block content %} -

Forums: {{ forum.name }} - {% if feed %} - RSS Feed - {% endif %} -

- -

- SurfGuitar101 Forum Index » - {{ forum.name }} -

+{% forum_navigation forum %}
{% if user.is_authenticated %} diff -r 39664e661c69 -r 593fb6dbd449 gpp/templates/forums/forum_query.html --- a/gpp/templates/forums/forum_query.html Mon Oct 04 00:56:54 2010 +0000 +++ b/gpp/templates/forums/forum_query.html Mon Oct 04 00:57:58 2010 +0000 @@ -1,7 +1,7 @@