Mercurial > public > sg101
changeset 81:e356ea79a7a2
More work on forums. Committing what we got so far.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Sun, 23 Aug 2009 00:14:52 +0000 |
parents | a4fdc4d23b9e |
children | bc3978f023c2 |
files | gpp/forums/admin.py gpp/forums/models.py gpp/forums/urls.py gpp/forums/views.py gpp/templates/forums/index.html gpp/urls.py media/css/base.css |
diffstat | 7 files changed, 121 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/gpp/forums/admin.py Sun Jul 12 18:25:26 2009 +0000 +++ b/gpp/forums/admin.py Sun Aug 23 00:14:52 2009 +0000 @@ -11,12 +11,16 @@ class CategoryAdmin(admin.ModelAdmin): list_display = ('name', 'position', ) + prepopulated_fields = { 'slug': ('name', ) } + save_on_top = True class ForumAdmin(admin.ModelAdmin): list_display = ('name', 'category', 'position', 'topic_count', 'post_count') prepopulated_fields = { 'slug': ('name', ) } raw_id_fields = ('last_post', ) + save_on_top = True + class TopicAdmin(admin.ModelAdmin): list_display = ('name', 'forum', 'creation_date', 'user', 'sticky', 'locked', @@ -25,6 +29,7 @@ search_fields = ('name', ) date_hierarchy = 'creation_date' list_filter = ('creation_date', 'update_date', ) + save_on_top = True class PostAdmin(admin.ModelAdmin): @@ -34,6 +39,7 @@ search_fields = ('body', ) date_hierarchy = 'creation_date' list_filter = ('creation_date', 'update_date', ) + save_on_top = True admin.site.register(Category, CategoryAdmin)
--- a/gpp/forums/models.py Sun Jul 12 18:25:26 2009 +0000 +++ b/gpp/forums/models.py Sun Aug 23 00:14:52 2009 +0000 @@ -42,6 +42,10 @@ def __unicode__(self): return self.name + @models.permalink + def get_absolute_url(self): + return ('forums-forum_index', [self.slug]) + def topic_count_update(self): """Call to notify the forum that its topic count has been updated.""" self.topic_count = Topic.objects.filter(forum=self).count()
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gpp/forums/urls.py Sun Aug 23 00:14:52 2009 +0000 @@ -0,0 +1,9 @@ +""" +URLs for the forums application. +""" +from django.conf.urls.defaults import * + +urlpatterns = patterns('forums.views', + url(r'^$', 'index', name='forums-index'), + url(r'^(?P<slug>[\w\d-]+)/$', 'forum_index', name='forums-forum_index'), +)
--- a/gpp/forums/views.py Sun Jul 12 18:25:26 2009 +0000 +++ b/gpp/forums/views.py Sun Aug 23 00:14:52 2009 +0000 @@ -1,1 +1,29 @@ -# Create your views here. +""" +Views for the forums application. +""" +from django.shortcuts import render_to_response +from django.template import RequestContext + +from forums.models import Forum + + +def index(request): + forums = Forum.objects.all().select_related() + cats = {} + for forum in forums: + cat = cats.setdefault(forum.category.id, { + 'cat': forum.category, + 'forums': [], + }) + cat['forums'].append(forum) + + cmpdef = lambda a, b: cmp(a['cat'].position, b['cat'].position) + cats = sorted(cats.values(), cmpdef) + + return render_to_response('forums/index.html', { + 'cats': cats, + }, + context_instance=RequestContext(request)) + +def forum_index(request, slug): + pass
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gpp/templates/forums/index.html Sun Aug 23 00:14:52 2009 +0000 @@ -0,0 +1,39 @@ +{% extends 'base.html' %} +{% block title %}Forums{% endblock %} +{% block content %} +<h2>Forums</h2> + +<div class="forum-block"> +{% for iter in cats %} + <h3>{{ iter.cat }}</h3> + <table class="forum-index-table"> + <thead> + <tr> + <th class="forum-title">Forum</th> + <th class="forum-topics">Topics</th> + <th class="forum-posts">Posts</th> + <th class="forum-last_post">Last Post</th> + </tr> + </thead> + <tbody> + {% for forum in iter.forums %} + <tr> + <td><h4><a href="{{ forum.get_absolute_url }}">{{ forum.name }}</a></h4> + <p>{{ forum.description }}</p></td> + <td class="forum-topics">{{ forum.topic_count }}</td> + <td class="forum-posts">{{ forum.post_count }}</td> + <td class="forum-last_post"> + {% if forum.last_post %} + {{ forum.last_post.update_date|date }}<br /> + {{ forum.last_post.user.username }} + {% else %} + <i>No Posts</i> + {% endif %} + </td> + </tr> + {% endfor %} + </tbody> + </table> +{% endfor %} +</div> +{% endblock %}
--- a/gpp/urls.py Sun Jul 12 18:25:26 2009 +0000 +++ b/gpp/urls.py Sun Aug 23 00:14:52 2009 +0000 @@ -23,6 +23,7 @@ 'django.contrib.syndication.views.feed', {'feed_dict': feeds }, 'feeds-news'), + (r'^forums/', include('forums.urls')), (r'^irc/', include('irc.urls')), (r'^links/', include('weblinks.urls')), (r'^member_map/', include('membermap.urls')),
--- a/media/css/base.css Sun Jul 12 18:25:26 2009 +0000 +++ b/media/css/base.css Sun Aug 23 00:14:52 2009 +0000 @@ -153,3 +153,36 @@ #slideshow img.last-active { z-index:9; } +table.forum-index-table { + width:100%; +} +table.forum-index-table thead th { + background:teal; +} +table.forum-index-table th.forum-title { + width:65%; +} +table.forum-index-table th.forum-topics { + width:10%; + text-align:center; +} +table.forum-index-table th.forum-posts { + width:10%; + text-align:center; +} +table.forum-index-table th.forum-last_post { + width:15%; + text-align:center; +} +table.forum-index-table td.forum-topics { + width:10%; + text-align:center; +} +table.forum-index-table td.forum-posts { + width:10%; + text-align:center; +} +table.forum-index-table td.forum-last_post { + width:15%; + text-align:center; +}