# HG changeset patch # User Brian Neal # Date 1251000269 0 # Node ID bc3978f023c235022430b9c8b7580aef38f0dcce # Parent e356ea79a7a2ae6cab90a477270cceeae793f7af Forums: started the ability to display topics inside a forum. diff -r e356ea79a7a2 -r bc3978f023c2 gpp/forums/models.py --- 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 diff -r e356ea79a7a2 -r bc3978f023c2 gpp/forums/urls.py --- 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\d+)/$', 'topic_index', name='forums-topic_index'), url(r'^(?P[\w\d-]+)/$', 'forum_index', name='forums-forum_index'), ) diff -r e356ea79a7a2 -r bc3978f023c2 gpp/forums/views.py --- 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 diff -r e356ea79a7a2 -r bc3978f023c2 gpp/templates/forums/forum_index.html --- /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 %} +

Forums: {{ forum.name }}

+ +

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

+ +
+ + + + + + + + + + + + {% for topic in topics %} + + + + + + + + {% empty %} + + + + {% endfor %} + +
TopicsRepliesAuthorViewsLast Post

{{ topic.name }}

{{ topic.post_count }}{{ topic.user.username }}{{ topic.view_count }} + {% if topic.last_post %} + {{ topic.last_post.update_date|date }}
+ {{ topic.last_post.user.username }} + {% else %} + No Posts + {% endif %} +
+ No topics available. +
+
+{% endblock %}