diff options
author | Evgeny Fadeev <evgeny.fadeev@gmail.com> | 2012-07-26 01:56:43 -0400 |
---|---|---|
committer | Evgeny Fadeev <evgeny.fadeev@gmail.com> | 2012-07-26 01:56:43 -0400 |
commit | 5e3f78086073f73e8bf938a9ec196f2e897fb03b (patch) | |
tree | 5443c90a533b8b304d2446f8dc3762bfd41d4660 | |
parent | 5c000a1fb83a3940776682f94c9809fd746878f5 (diff) | |
download | askbot-5e3f78086073f73e8bf938a9ec196f2e897fb03b.tar.gz askbot-5e3f78086073f73e8bf938a9ec196f2e897fb03b.tar.bz2 askbot-5e3f78086073f73e8bf938a9ec196f2e897fb03b.zip |
added cache clear upon content moderation toggle
-rw-r--r-- | askbot/conf/moderation.py | 9 | ||||
-rw-r--r-- | askbot/models/__init__.py | 2 | ||||
-rw-r--r-- | askbot/models/post.py | 17 | ||||
-rw-r--r-- | askbot/models/question.py | 2 |
4 files changed, 24 insertions, 6 deletions
diff --git a/askbot/conf/moderation.py b/askbot/conf/moderation.py index 9f8e24c7..8e77385f 100644 --- a/askbot/conf/moderation.py +++ b/askbot/conf/moderation.py @@ -4,8 +4,16 @@ from askbot.conf.settings_wrapper import settings from askbot.conf.super_groups import DATA_AND_FORMATTING from askbot.deps.livesettings import ConfigurationGroup from askbot.deps.livesettings import BooleanValue +from django.core.cache import cache from django.utils.translation import ugettext as _ +def empty_cache_callback(old_value, new_value): + """used to clear cache on change of certain values""" + if old_value != new_value: + #todo: change this to warmup cache + cache.clear() + return new_value + MODERATION = ConfigurationGroup( 'MODERATION', _('Content moderation'), @@ -18,5 +26,6 @@ settings.register( 'ENABLE_CONTENT_MODERATION', default = False, description = _('Enable content moderation'), + update_callback = empty_cache_callback ) ) diff --git a/askbot/models/__init__.py b/askbot/models/__init__.py index 98813e22..914f1c11 100644 --- a/askbot/models/__init__.py +++ b/askbot/models/__init__.py @@ -2844,7 +2844,7 @@ def send_instant_notifications_about_activity_in_post( newly mentioned users are carried through to reduce database hits """ - if askbot_settings.ENABLE_CONTENT_MODERATION and post.approved == False: + if post.is_approved() is False: return if recipients is None: diff --git a/askbot/models/post.py b/askbot/models/post.py index 1d5afc13..25b3f47a 100644 --- a/askbot/models/post.py +++ b/askbot/models/post.py @@ -513,8 +513,18 @@ class Post(models.Model): def is_reject_reason(self): return self.post_type == 'reject_reason' + def is_approved(self): + """``False`` only when moderation is ``True`` and post + ``self.approved is False`` + """ + if askbot_settings.ENABLE_CONTENT_MODERATION: + if self.approved == False: + return False + return True + def needs_moderation(self): - return self.approved == False + #todo: do we need this, can't we just use is_approved()? + return self.approved is False def get_absolute_url(self, no_slug = False, question_post=None, thread=None): from askbot.utils.slug import slugify @@ -1207,9 +1217,8 @@ class Post(models.Model): def _question__assert_is_visible_to(self, user): """raises QuestionHidden""" - if askbot_settings.ENABLE_CONTENT_MODERATION: - if self.approved == False: - raise exceptions.QuestionHidden() + if self.is_approved() is False: + raise exceptions.QuestionHidden() if self.deleted: message = _( 'Sorry, this question has been ' diff --git a/askbot/models/question.py b/askbot/models/question.py index c9749749..0fd02bf0 100644 --- a/askbot/models/question.py +++ b/askbot/models/question.py @@ -580,7 +580,7 @@ class Thread(models.Model): #pass through only deleted question posts if post.deleted and post.post_type != 'question': continue - if post.approved == False:#hide posts on the moderation queue + if post.is_approved() is False:#hide posts on the moderation queue continue post_to_author[post.id] = post.author_id |