# HG changeset patch # User Brian Neal # Date 1250986492 0 # Node ID e356ea79a7a2ae6cab90a477270cceeae793f7af # Parent a4fdc4d23b9e953a11139615fcaf96e84a31417e More work on forums. Committing what we got so far. diff -r a4fdc4d23b9e -r e356ea79a7a2 gpp/forums/admin.py --- 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) diff -r a4fdc4d23b9e -r e356ea79a7a2 gpp/forums/models.py --- 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() diff -r a4fdc4d23b9e -r e356ea79a7a2 gpp/forums/urls.py --- /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[\w\d-]+)/$', 'forum_index', name='forums-forum_index'), +) diff -r a4fdc4d23b9e -r e356ea79a7a2 gpp/forums/views.py --- 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 diff -r a4fdc4d23b9e -r e356ea79a7a2 gpp/templates/forums/index.html --- /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 %} +

Forums

+ +
+{% for iter in cats %} +

{{ iter.cat }}

+ + + + + + + + + + + {% for forum in iter.forums %} + + + + + + + {% endfor %} + +
ForumTopicsPostsLast Post

{{ forum.name }}

+

{{ forum.description }}

{{ forum.topic_count }}{{ forum.post_count }} + {% if forum.last_post %} + {{ forum.last_post.update_date|date }}
+ {{ forum.last_post.user.username }} + {% else %} + No Posts + {% endif %} +
+{% endfor %} +
+{% endblock %} diff -r a4fdc4d23b9e -r e356ea79a7a2 gpp/urls.py --- 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')), diff -r a4fdc4d23b9e -r e356ea79a7a2 media/css/base.css --- 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; +}