diff options
author | Evgeny Fadeev <evgeny.fadeev@gmail.com> | 2012-10-19 18:05:33 -0300 |
---|---|---|
committer | Evgeny Fadeev <evgeny.fadeev@gmail.com> | 2012-10-19 18:05:33 -0300 |
commit | cb137e1163e04b5df1cedddea25098e4bea7b3d8 (patch) | |
tree | b2c181f573caba99f961944d6dd24cbbe1f9986d | |
parent | 6575dda739ebbd441afe410552e3fcb0165ef156 (diff) | |
download | askbot-cb137e1163e04b5df1cedddea25098e4bea7b3d8.tar.gz askbot-cb137e1163e04b5df1cedddea25098e4bea7b3d8.tar.bz2 askbot-cb137e1163e04b5df1cedddea25098e4bea7b3d8.zip |
added a management command to find anomalous threads
-rw-r--r-- | askbot/management/commands/find_bodyless_questions.py | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/askbot/management/commands/find_bodyless_questions.py b/askbot/management/commands/find_bodyless_questions.py new file mode 100644 index 00000000..75312620 --- /dev/null +++ b/askbot/management/commands/find_bodyless_questions.py @@ -0,0 +1,44 @@ +"""this management commands will fix corrupted posts +that do not have revisions by creating a fake initial revision +based on the content stored in the post itself +""" +from django.core.management.base import NoArgsCommand +from askbot import models +from askbot import const +from askbot.utils.console import ProgressBar + +def print_results(items): + template = 'id=%d, title=%s' + for thread in items: + print template % (thread.id, thread.title.encode('utf8')) + +class Command(NoArgsCommand): + """Command class for "fix_bodyless_questions" + """ + def handle(self, *arguments, **options): + """function that handles the command job + """ + threads = models.Thread.objects.all() + count = threads.count() + message = 'Looking for body-less questions' + bodyless = list() + multi_body = list() + for thread in ProgressBar(threads.iterator(), count, message): + body_count = models.Post.objects.filter( + thread=thread, + post_type='question', + ).count() + if body_count == 0: + bodyless.append(thread) + elif body_count > 1: + multi_body.append(thread) + + if len(bodyless) + len(multi_body) == 0: + print 'None found.' + else: + if len(bodyless): + print '\nQuestions without body text:' + print_results(bodyless) + if len(multi_body): + print '\nQuestions with >1 instances of body text' + print_results(multi_body) |