changeset 82:bc3978f023c2

Forums: started the ability to display topics inside a forum.
author Brian Neal <bgneal@gmail.com>
date Sun, 23 Aug 2009 04:04:29 +0000
parents e356ea79a7a2
children 5b4c812b448e
files gpp/forums/models.py gpp/forums/urls.py gpp/forums/views.py gpp/templates/forums/forum_index.html
diffstat 4 files changed, 77 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/gpp/forums/models.py	Sun Aug 23 00:14:52 2009 +0000
+++ b/gpp/forums/models.py	Sun Aug 23 04:04:29 2009 +0000
@@ -81,6 +81,10 @@
     def __unicode__(self):
         return self.name
 
+    @models.permalink
+    def get_absolute_url(self):
+        return ('forums-topic_index', [self.pk])
+
     def post_count_update(self):
         """
         Call this function to notify the topic instance that its post count
--- a/gpp/forums/urls.py	Sun Aug 23 00:14:52 2009 +0000
+++ b/gpp/forums/urls.py	Sun Aug 23 04:04:29 2009 +0000
@@ -5,5 +5,6 @@
 
 urlpatterns = patterns('forums.views',
     url(r'^$', 'index', name='forums-index'),
+    url(r'^topic/(?P<id>\d+)/$', 'topic_index', name='forums-topic_index'),
     url(r'^(?P<slug>[\w\d-]+)/$', 'forum_index', name='forums-forum_index'),
 )
--- a/gpp/forums/views.py	Sun Aug 23 00:14:52 2009 +0000
+++ b/gpp/forums/views.py	Sun Aug 23 04:04:29 2009 +0000
@@ -1,6 +1,8 @@
 """
 Views for the forums application.
 """
+from django.http import Http404
+from django.shortcuts import get_object_or_404
 from django.shortcuts import render_to_response
 from django.template import RequestContext
 
@@ -8,6 +10,9 @@
 
 
 def index(request):
+    """
+    This view displays all the forums available, ordered in each category.
+    """
     forums = Forum.objects.all().select_related()
     cats = {}
     for forum in forums:
@@ -25,5 +30,23 @@
         },
         context_instance=RequestContext(request))
 
+
 def forum_index(request, slug):
-    pass
+    """
+    Displays all the topics in a forum.
+    """
+    forum = get_object_or_404(Forum, slug=slug)
+    topics = forum.topics.select_related()
+    
+    return render_to_response('forums/forum_index.html', {
+        'forum': forum,
+        'topics': topics,
+        },
+        context_instance=RequestContext(request))
+
+
+def topic_index(request, id):
+    """
+    Displays all the posts in a topic.
+    """
+    raise Http404
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gpp/templates/forums/forum_index.html	Sun Aug 23 04:04:29 2009 +0000
@@ -0,0 +1,48 @@
+{% extends 'base.html' %}
+{% block title %}Forums: {{ forum.name }}{% endblock %}
+{% block content %}
+<h2>Forums: {{ 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>
+
+<div class="forum-block">
+<table class="forum-index-table">
+   <thead>
+      <tr>
+         <th class="forum-index_title">Topics</th>
+         <th class="forum-index_replies">Replies</th>
+         <th class="forum-index_author">Author</th>
+         <th class="forum-index_views">Views</th>
+         <th class="forum-index_last_post">Last Post</th>
+      </tr>
+   </thead>
+   <tbody>
+   {% for topic in topics %}
+      <tr>
+         <td><h4><a href="{{ topic.get_absolute_url }}">{{ topic.name }}</a></h4></td>
+         <td class="forum-index_replies">{{ topic.post_count }}</td>
+         <td class="forum-index_author">{{ topic.user.username }}</td>
+         <td class="forum-index_views">{{ topic.view_count }}</td>
+         <td class="forum-index_last_post">
+            {% if topic.last_post %}
+               {{ topic.last_post.update_date|date }}<br />
+               {{ topic.last_post.user.username }}
+            {% else %}
+               <i>No Posts</i>
+            {% endif %}
+         </td>
+      </tr>
+   {% empty %}
+      <tr>
+         <td colspan="4">
+            <i>No topics available.</i>
+         </td>
+      </tr>
+   {% endfor %}
+   </tbody>
+</table>
+</div>
+{% endblock %}