diff options
Diffstat (limited to 'askbot/models/__init__.py')
-rw-r--r-- | askbot/models/__init__.py | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/askbot/models/__init__.py b/askbot/models/__init__.py index 9f5e8999..05cc44aa 100644 --- a/askbot/models/__init__.py +++ b/askbot/models/__init__.py @@ -1977,8 +1977,26 @@ def downvote(self, post, timestamp=None, cancel=False, force = False): ) @auto_now_timestamp -def flag_post(user, post, timestamp=None, cancel=False, force = False): - if cancel:#todo: can't unflag? +def flag_post(user, post, timestamp=None, cancel=False, cancel_all = False, force = False): + if cancel_all: + # remove all flags + if force == False: + user.assert_can_remove_all_flags_offensive(post = post) + post_content_type = ContentType.objects.get_for_model(post) + all_flags = Activity.objects.filter( + activity_type = const.TYPE_ACTIVITY_MARK_OFFENSIVE, + content_type = post_content_type, object_id=post.id + ) + for flag in all_flags: + auth.onUnFlaggedItem(post, flag.user, timestamp=timestamp) + award_badges_signal.send(None, + event = 'flag_post', + actor = flag.user, + context_object = post, + timestamp = timestamp + ) + + elif cancel:#todo: can't unflag? if force == False: user.assert_can_remove_flag_offensive(post = post) auth.onUnFlaggedItem(post, user, timestamp=timestamp) @@ -1988,6 +2006,7 @@ def flag_post(user, post, timestamp=None, cancel=False, force = False): context_object = post, timestamp = timestamp ) + else: if force == False: user.assert_can_flag_offensive(post = post) |