Mercurial > public > sg101
changeset 86:f81226b5e87b
Forums: Some display work for the posts within a topic. Sketched out a post reply form.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Sat, 05 Sep 2009 20:47:08 +0000 |
parents | 531fcc342a03 |
children | 515d1daec811 |
files | gpp/forums/forms.py gpp/forums/views.py gpp/templates/forums/topic.html media/css/base.css |
diffstat | 4 files changed, 94 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- 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'],
--- 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
--- /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 %} +<h2>Forums: {{ topic.name }}</h2> + +<h3> + <a href="{% url forums-index %}">SurfGuitar101 Forum Index</a> » + <a href="{% url forums-forum_index slug=forum.slug %}">{{ forum.name }}</a> » + <a href="{% url forums-topic_index id=topic.id %}">{{ topic.name }}</a> +</h3> + +<div class="forum-block"> +<a href="">New Reply</a> • +<a href="{% url forums-new_topic slug=forum.slug %}">New Topic</a> + +<table class="forum-topic"> +{% for post in posts %} +<tr class="forum-post"> + <td class="forum-post-author"> + <a href="{% url bio-view_profile username=post.user.username %}">{{ post.user.username }}</a><br /> + {% avatar post.user %} + </td> + <td class="forum-post-body"> + <div class="forum-post-info quiet"> + <a href="{{ post.get_absolute_url }}"><img src="{{ MEDIA_URL }}icons/link.png" alt="Link" title="Link to this post" /></a> + Posted on {{ post.creation_date|date:"M d, Y H:i" }} + </div> + <div class="forum-post-body"> + {{ post.html|safe }} + </div> + </td> +</tr> +{% endfor %} +</table> +{% if user.is_authenticated %} +<form action="" method="post"> +<fieldset> +<legend>Reply to Thread</legend> +{{ form.as_p }} +<input type="submit" value="Submit Reply" /> +</fieldset> +</form> +{% endif %} +</div> +{% endblock %}
--- 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; +}