Mercurial > public > sg101
changeset 112:d1b0b86441c0
Forums: added a sync() function on the forum model. Created javascript for the moderate forum function to drive the master topic select checkbox.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Wed, 30 Sep 2009 00:42:13 +0000 |
parents | e5faf9f0c11a |
children | d97ceb95ce02 |
files | gpp/forums/forms.py gpp/forums/models.py gpp/forums/views.py gpp/templates/forums/mod_forum.html media/js/forums_mod.js |
diffstat | 5 files changed, 29 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/gpp/forums/forms.py Mon Sep 28 03:57:09 2009 +0000 +++ b/gpp/forums/forms.py Wed Sep 30 00:42:13 2009 +0000 @@ -124,5 +124,4 @@ if hide_label: self.fields['forums'].label = '' self.fields['forums'].required = required - print '#############', required
--- a/gpp/forums/models.py Mon Sep 28 03:57:09 2009 +0000 +++ b/gpp/forums/models.py Wed Sep 30 00:42:13 2009 +0000 @@ -108,6 +108,14 @@ else: self.last_post = None + def sync(self): + """ + Call to notify the forum that it needs to recompute its + denormalized fields. + """ + self.topic_count_update() + self.post_count_update() + def last_post_pre_delete(self): """ Call this function prior to deleting the last post in the forum.
--- a/gpp/forums/views.py Mon Sep 28 03:57:09 2009 +0000 +++ b/gpp/forums/views.py Wed Sep 30 00:42:13 2009 +0000 @@ -558,11 +558,9 @@ topic.forum = new_forum topic.save() # Have to adjust foreign keys to last_post, denormalized counts, etc.: - old_forum.topic_count_update() - old_forum.post_count_update() + old_forum.sync() old_forum.save() - new_forum.topic_count_update() - new_forum.post_count_update() + new_forum.sync() new_forum.save()
--- a/gpp/templates/forums/mod_forum.html Mon Sep 28 03:57:09 2009 +0000 +++ b/gpp/templates/forums/mod_forum.html Wed Sep 30 00:42:13 2009 +0000 @@ -1,6 +1,9 @@ {% extends 'base.html' %} {% load forum_tags %} {% block title %}Moderate Forum: {{ forum.name }}{% endblock %} +{% block custom_js %} +<script type="text/javascript" src="{{ MEDIA_URL }}js/forums_mod.js"></script> +{% endblock %} {% block content %} <h2>Moderate Forum: {{ forum.name }}</h2> @@ -34,7 +37,7 @@ <td class="forum-index_last_post"> {% last_post_info topic.last_post MEDIA_URL %} </td> - <td class="forum-index_select"><input type="checkbox" name="topic_ids" value="{{ topic.id }}" /></td> + <td class="forum-index_select"><input type="checkbox" name="topic_ids" value="{{ topic.id }}" class="forums-topic_check" /></td> </tr> {% empty %} <tr>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/media/js/forums_mod.js Wed Sep 30 00:42:13 2009 +0000 @@ -0,0 +1,15 @@ +$(document).ready(function() { + var master = $('#forums-master-topic'); + var topics = $('.forums-topic_check'); + master.click(function() { + var state = this.checked; + topics.each(function() { + this.checked = state; + }); + }); + topics.click(function() { + if (master[0].checked && !this.checked) { + master[0].checked = false; + } + }); +});