# HG changeset patch # User Brian Neal # Date 1252183628 0 # Node ID f81226b5e87b0f6033c2975d6312a70821f932a3 # Parent 531fcc342a0322d7515671f48886584bd8cb9b50 Forums: Some display work for the posts within a topic. Sketched out a post reply form. diff -r 531fcc342a03 -r f81226b5e87b gpp/forums/forms.py --- a/gpp/forums/forms.py Sun Aug 30 19:58:42 2009 +0000 +++ b/gpp/forums/forms.py Sat Sep 05 20:47:08 2009 +0000 @@ -7,20 +7,17 @@ from forums.models import Post -class TopicForm(forms.ModelForm): - """Form for creating a new topic.""" - - class Meta: - model = Topic - fields = ('name', ) +class PostForm(forms.Form): + """Form for creating a new post.""" + body = forms.CharField(label='', widget=forms.Textarea) - -class PostForm(forms.ModelForm): - """Form for creating a new post.""" - - class Meta: - model = Post - fields = ('body', ) + def save(self, topic, user, ip=None): + """ + Creates a new post from the form data and supplied arguments. + """ + post = Post(topic=topic, user=user, body=self.cleaned_data['body'], + user_ip=user_ip) + post.save() class NewTopicForm(forms.Form): @@ -31,7 +28,7 @@ def save(self, forum, user, ip=None): """ Creates the new Topic and first Post from the form data and supplied - forum and user objects. + arguments. """ topic = Topic(forum=forum, name=self.cleaned_data['name'], diff -r 531fcc342a03 -r f81226b5e87b gpp/forums/views.py --- a/gpp/forums/views.py Sun Aug 30 19:58:42 2009 +0000 +++ b/gpp/forums/views.py Sat Sep 05 20:47:08 2009 +0000 @@ -12,6 +12,7 @@ from forums.models import Forum from forums.models import Topic from forums.forms import NewTopicForm +from forums.forms import PostForm def index(request): @@ -54,7 +55,19 @@ """ Displays all the posts in a topic. """ - raise Http404 + topic = get_object_or_404(Topic, pk=id) + topic.view_count += 1 + topic.save() + + posts = topic.posts.select_related() + + return render_to_response('forums/topic.html', { + 'forum': topic.forum, + 'topic': topic, + 'posts': posts, + 'form': PostForm(), + }, + context_instance=RequestContext(request)) @login_required diff -r 531fcc342a03 -r f81226b5e87b gpp/templates/forums/topic.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gpp/templates/forums/topic.html Sat Sep 05 20:47:08 2009 +0000 @@ -0,0 +1,46 @@ +{% extends 'base.html' %} +{% load avatar_tags %} +{% block title %}Forums: {{ topic.name }}{% endblock %} +{% block content %} +

Forums: {{ topic.name }}

+ +

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

+ +
+New Reply • +New Topic + + +{% for post in posts %} + + + + +{% endfor %} +
+ +
+ {{ post.html|safe }} +
+
+{% if user.is_authenticated %} +
+
+Reply to Thread +{{ form.as_p }} + +
+
+{% endif %} +
+{% endblock %} diff -r 531fcc342a03 -r f81226b5e87b media/css/base.css --- a/media/css/base.css Sun Aug 30 19:58:42 2009 +0000 +++ b/media/css/base.css Sat Sep 05 20:47:08 2009 +0000 @@ -194,3 +194,26 @@ width:20%; text-align:center; } +table.forum-topic { + border:1px solid black; + width:100%; + margin-top: 5px; +} +td.forum-post-author { + width:5%; + border-right: 1px solid #ccc; +} +td.forum-post-body { + vertical-align: top; + width:95%; +} +div.forum-post-info { + padding: 2px; + font-size:.8em; + border-bottom: 1px solid #ccc; + margin-bottom: 5px; +} +div.forum-post-info img { + float: left; + margin-right: 5px; +}