changeset 283:593fb6dbd449

Fixing #125. Developed a forums navigation template tag to consistently display forum navigation.
author Brian Neal <bgneal@gmail.com>
date Mon, 04 Oct 2010 00:57:58 +0000
parents 39664e661c69
children df2c81f705a8
files gpp/forums/templatetags/forum_tags.py gpp/templates/forums/edit_post.html gpp/templates/forums/favorite_status.html gpp/templates/forums/forum_index.html gpp/templates/forums/forum_query.html gpp/templates/forums/manage_topics.html gpp/templates/forums/mod_forum.html gpp/templates/forums/mod_split_topic.html gpp/templates/forums/move_topic.html gpp/templates/forums/new_post.html gpp/templates/forums/new_topic.html gpp/templates/forums/new_topic_thanks.html gpp/templates/forums/post_list.html gpp/templates/forums/subscription_status.html gpp/templates/forums/topic.html gpp/templates/forums/topic_list.html media/css/base.css
diffstat 17 files changed, 56 insertions(+), 93 deletions(-) [+]
line wrap: on
line diff
--- 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)
--- 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 %}
-<h2>Forums: Edit Post</h2>
-
-<h3>
-   <a href="{% url forums-index %}">SurfGuitar101 Forum Index</a> &raquo;
-   <a href="{% url forums-forum_index slug=forum.slug %}">{{ forum.name }}</a> &raquo;
-   <a href="{% url forums-topic_index id=topic.id %}">{{ topic.name }}</a>
-</h3>
+{% forum_navigation topic "Edit Post" %}
 
 <div class="forum-block">
 <table class="forum-topic" id="forum-topic">
--- 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 %}
-<h2>Forums: Favorite Topics</h2>
-<h3>
-   <a href="{% url forums-index %}">SurfGuitar101 Forum Index</a> &raquo;
-   <a href="{% url forums-forum_index slug=topic.forum.slug %}">{{ topic.forum.name }}</a> &raquo;
-   <a href="{% url forums-topic_index id=topic.id %}">{{ topic.name }}</a>
-</h3>
+{% forum_navigation topic "Favorite Topics Updated" %}
 <p>
 {% if is_favorite %}
 The forum topic <a href="{{ topic.get_absolute_url }}">{{ topic.name }}</a> has been added to your 
--- 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 %}
-<h2>Forums: {{ forum.name }}
-   {% if feed %}
-   <a href="{{ feed.feed }}"><img src="{{ MEDIA_URL }}icons/feed.png" alt="RSS Feed" title="Feed for this forum" /></a>
-   {% endif %}
-</h2>
-
-<h3>
-   <a href="{% url forums-index %}">SurfGuitar101 Forum Index</a> &raquo;
-   <a href="{% url forums-forum_index slug=forum.slug %}">{{ forum.name }}</a>
-</h3>
+{% forum_navigation forum %}
 
 <div class="forum-block">
 {% if user.is_authenticated %}
--- 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 @@
 <form action="." method="get" id="forum-query-form">
    <select id="forum-query-select">
       <option value="{% url forums-unread_topics %}">Show topics with unread posts</option>
-      <option value="{% url forums-unanswered_topics %}">Show unanswered posts</option>
+      <option value="{% url forums-unanswered_topics %}">Show unanswered topics</option>
       {% if user.is_authenticated %}
       <option value="{% url forums-my_posts %}">Show my posts</option>
       <option value="{% url forums-manage_favorites %}">Show my favorite topics</option>
--- a/gpp/templates/forums/manage_topics.html	Mon Oct 04 00:56:54 2010 +0000
+++ b/gpp/templates/forums/manage_topics.html	Mon Oct 04 00:57:58 2010 +0000
@@ -1,4 +1,5 @@
 {% extends 'base.html' %}
+{% load forum_tags %}
 {% block title %}Forums: {{ page_title }}{% endblock %}
 {% block custom_js %}
 <script type="text/javascript">
@@ -27,11 +28,7 @@
 {% include "forums/forum_query.js" %}
 {% endblock %}
 {% block content %}
-<h2>Forums: {{ page_title }}</h2>
-
-<h3>
-   <a href="{% url forums-index %}">SurfGuitar101 Forum Index</a> &raquo; {{ page_title }}
-</h3>
+{% forum_navigation page_title %}
 {% include "forums/forum_query.html" %}
 <p>{{ description }}</p>
 {% include 'forums/pagination.html' %}
--- a/gpp/templates/forums/mod_forum.html	Mon Oct 04 00:56:54 2010 +0000
+++ b/gpp/templates/forums/mod_forum.html	Mon Oct 04 00:57:58 2010 +0000
@@ -5,12 +5,7 @@
 <script type="text/javascript" src="{{ MEDIA_URL }}js/forums_mod.js"></script>
 {% endblock %}
 {% block content %}
-<h2>Moderate Forum: {{ forum.name }}</h2>
-
-<h3>
-   <a href="{% url forums-index %}">SurfGuitar101 Forum Index</a> &raquo;
-   <a href="{% url forums-forum_index slug=forum.slug %}">{{ forum.name }}</a>
-</h3>
+{% forum_navigation forum "Moderate Forum" %}
 
 <div class="forum-block">
 {{ page_nav }}
--- a/gpp/templates/forums/mod_split_topic.html	Mon Oct 04 00:56:54 2010 +0000
+++ b/gpp/templates/forums/mod_split_topic.html	Mon Oct 04 00:57:58 2010 +0000
@@ -1,14 +1,9 @@
 {% extends 'base.html' %}
+{% load forum_tags %}
 {% block title %}Forums: Split Topic{% endblock %}
 {% block custom_js %}{{ form.media }}{% endblock %}
 {% block content %}
-<h2>Forums: Split Topic {{ topic.name }}</h2>
-
-<h3>
-   <a href="{% url forums-index %}">SurfGuitar101 Forum Index</a> &raquo;
-   <a href="{% url forums-forum_index slug=forum.slug %}">{{ forum.name }}</a> &raquo;
-   <a href="{% url forums-topic_index id=topic.id %}">{{ topic.name }}</a>
-</h3>
+{% forum_navigation topic "Split Topic" %}
 
 <div class="forum-block">
    <p>
--- a/gpp/templates/forums/move_topic.html	Mon Oct 04 00:56:54 2010 +0000
+++ b/gpp/templates/forums/move_topic.html	Mon Oct 04 00:57:58 2010 +0000
@@ -1,13 +1,8 @@
 {% extends 'base.html' %}
+{% load forum_tags %}
 {% block title %}Forums: Move Topic{% endblock %}
 {% block content %}
-<h2>Forums: Move Topic</h2>
-
-<h3>
-   <a href="{% url forums-index %}">SurfGuitar101 Forum Index</a> &raquo;
-   <a href="{% url forums-forum_index slug=forum.slug %}">{{ forum.name }}</a> &raquo;
-   <a href="{% url forums-topic_index id=topic.id %}">{{ topic.name }}</a>
-</h3>
+{% forum_navigation topic "Move Topic" %}
 
 <div class="forum-block">
 <form action="." method="post">{% csrf_token %}
--- a/gpp/templates/forums/new_post.html	Mon Oct 04 00:56:54 2010 +0000
+++ b/gpp/templates/forums/new_post.html	Mon Oct 04 00:57:58 2010 +0000
@@ -3,13 +3,7 @@
 {% block title %}Forums: New Post{% endblock %}
 {% block custom_js %}{{ form.media }}{% endblock %}
 {% block content %}
-<h2>Forums: New Post</h2>
-
-<h3>
-   <a href="{% url forums-index %}">SurfGuitar101 Forum Index</a> &raquo;
-   <a href="{% url forums-forum_index slug=forum.slug %}">{{ forum.name }}</a> &raquo;
-   <a href="{% url forums-topic_index id=topic.id %}">{{ topic.name }}</a>
-</h3>
+{% forum_navigation topic "New Post" %}
 
 {% if can_post %}
 <div class="forum-block">
--- a/gpp/templates/forums/new_topic.html	Mon Oct 04 00:56:54 2010 +0000
+++ b/gpp/templates/forums/new_topic.html	Mon Oct 04 00:57:58 2010 +0000
@@ -3,12 +3,7 @@
 {% block title %}Forums: New Topic{% endblock %}
 {% block custom_js %}{{ form.media }}{% endblock %}
 {% block content %}
-<h2>{{ forum.name }} - New Topic</h2>
-
-<h3>
-   <a href="{% url forums-index %}">SurfGuitar101 Forum Index</a> &raquo;
-   <a href="{% url forums-forum_index slug=forum.slug %}">{{ forum.name }}</a>
-</h3>
+{% forum_navigation forum "New Topic" %}
 
 {% show_form "New Topic" form "Submit" 0 MEDIA_URL %}
 {% endblock %}
--- a/gpp/templates/forums/new_topic_thanks.html	Mon Oct 04 00:56:54 2010 +0000
+++ b/gpp/templates/forums/new_topic_thanks.html	Mon Oct 04 00:57:58 2010 +0000
@@ -1,16 +1,11 @@
 {% extends 'base.html' %}
+{% load forum_tags %}
 {% block title %}Forums: New Topic Created{% endblock %}
 {% block content %}
-<h2>Forums: {{ forum.name }} - New Topic Created</h2>
-
-<h3>
-   <a href="{% url forums-index %}">SurfGuitar101 Forum Index</a> &raquo;
-   <a href="{% url forums-forum_index slug=forum.slug %}">{{ forum.name }}</a>
-</h3>
+{% forum_navigation topic "New Topic Created" %}
 
 <p>
-New topic created successfully. 
-Click <a href="{{ topic.get_absolute_url }}">here</a> to view your new topic.
+You have successfully created a new topic called &quot;
+<a href="{{ topic.get_absolute_url }}">{{ topic.name }}</a>&quot;.
 </p>
-
 {% endblock %}
--- a/gpp/templates/forums/post_list.html	Mon Oct 04 00:56:54 2010 +0000
+++ b/gpp/templates/forums/post_list.html	Mon Oct 04 00:57:58 2010 +0000
@@ -5,10 +5,7 @@
 {% include "forums/forum_query.js" %}
 {% endblock %}
 {% block content %}
-<h2>Forums: {{ title }}</h2>
-<h3>
-<a href="{% url forums-index %}">SurfGuitar101 Forum Index</a> &raquo; {{ title }}
-</h3>
+{% forum_navigation title %}
 {% include "forums/forum_query.html" %}
 <div class="forum-block">
 {{ page_nav }}
--- a/gpp/templates/forums/subscription_status.html	Mon Oct 04 00:56:54 2010 +0000
+++ b/gpp/templates/forums/subscription_status.html	Mon Oct 04 00:57:58 2010 +0000
@@ -1,13 +1,8 @@
 {% extends 'base.html' %}
+{% load forum_tags %}
 {% block title %}Forums: {% if is_subscribed %}S{% else %}Uns{% endif %}ubscribed to Topic{% endblock %}
 {% block content %}
-<h2>Forums: {% if is_subscribed %}S{% else %}Uns{% endif %}ubscribed to Topic</h2>
-
-<h3>
-   <a href="{% url forums-index %}">SurfGuitar101 Forum Index</a> &raquo;
-   <a href="{% url forums-forum_index slug=topic.forum.slug %}">{{ topic.forum.name }}</a> &raquo;
-   <a href="{% url forums-topic_index id=topic.id %}">{{ topic.name }}</a>
-</h3>
+{% forum_navigation topic "Topic Subscriptions Updated" %}
 <p>
 {% if is_subscribed %}
 You are now subscribed to the forum topic <a href="{{ topic.get_absolute_url }}">{{ topic.name }}</a>.
--- a/gpp/templates/forums/topic.html	Mon Oct 04 00:56:54 2010 +0000
+++ b/gpp/templates/forums/topic.html	Mon Oct 04 00:57:58 2010 +0000
@@ -3,13 +3,7 @@
 {% block title %}Forums: {{ topic.name }}{% endblock %}
 {% block custom_js %}{{ form.media }}{% endblock %}
 {% block content %}
-<h2>Forums: {{ topic.name }}</h2>
-
-<h3>
-   <a href="{% url forums-index %}">SurfGuitar101 Forum Index</a> &raquo;
-   <a href="{% url forums-forum_index slug=forum.slug %}">{{ forum.name }}</a> &raquo;
-   <a href="{% url forums-topic_index id=topic.id %}">{{ topic.name }}</a>
-</h3>
+{% forum_navigation topic %}
 
 <div class="forum-block">
 {% if topic.sticky %}
--- a/gpp/templates/forums/topic_list.html	Mon Oct 04 00:56:54 2010 +0000
+++ b/gpp/templates/forums/topic_list.html	Mon Oct 04 00:57:58 2010 +0000
@@ -5,10 +5,7 @@
 {% include "forums/forum_query.js" %}
 {% endblock %}
 {% block content %}
-<h2>Forums: {{ title }}</h2>
-<h3>
-<a href="{% url forums-index %}">SurfGuitar101 Forum Index</a> &raquo; {{ title }}
-</h3>
+{% forum_navigation title %}
 {% include "forums/forum_query.html" %}
 <div class="forum-block">
 {{ page_nav }}
--- a/media/css/base.css	Mon Oct 04 00:56:54 2010 +0000
+++ b/media/css/base.css	Mon Oct 04 00:57:58 2010 +0000
@@ -382,3 +382,5 @@
 .stranger {
    background:#FFF6BF;
 }
+h2.forum-nav {font-size:1.2em;margin-top:1em;margin-bottom:0.2em;}
+h3.forum-nav {font-size:2em;line-height:1;margin-bottom:1em;margin-left:1em;}