diff options
author | Evgeny Fadeev <evgeny.fadeev@gmail.com> | 2014-08-29 09:19:01 +0700 |
---|---|---|
committer | Evgeny Fadeev <evgeny.fadeev@gmail.com> | 2014-08-29 09:19:01 +0700 |
commit | 7f6223ed9ea000e1c940f597adbf46efd9098d6e (patch) | |
tree | ad779a3a4d26fe61346d2a33c1716285e02e386d /askbot/management | |
parent | 490243b93e7237312ee913eff9b1b296f764df8d (diff) | |
download | askbot-7f6223ed9ea000e1c940f597adbf46efd9098d6e.tar.gz askbot-7f6223ed9ea000e1c940f597adbf46efd9098d6e.tar.bz2 askbot-7f6223ed9ea000e1c940f597adbf46efd9098d6e.zip |
merged with the master branch
Diffstat (limited to 'askbot/management')
6 files changed, 74 insertions, 7 deletions
diff --git a/askbot/management/commands/askbot_award_badges.py b/askbot/management/commands/askbot_award_badges.py new file mode 100644 index 00000000..b8a618f4 --- /dev/null +++ b/askbot/management/commands/askbot_award_badges.py @@ -0,0 +1,37 @@ +"""WARNING: +This command is incomplete, current awards only +Civic Duty badge +""" + +from askbot.models import badges +from askbot.models import User +from askbot.models import Vote +from askbot.utils.console import ProgressBar +import datetime +from django.core.management.base import NoArgsCommand + +class Command(NoArgsCommand): + def handle_noargs(self, *args, **kwargs): + now = datetime.datetime.now() + awarded_count = 0 + + users = User.objects.all() + count = users.count() + message = 'Awarding badges for each user' + for user in ProgressBar(users.iterator(), count, message): + try: + #get last vote + vote = Vote.objects.filter(user=user).order_by('-id')[0] + except IndexError: + #user did not vote + continue + else: + cd = badges.CivicDuty() + awarded = cd.consider_award( + actor=user, + context_object=vote.voted_post, + timestamp=now + ) + awarded_count += int(awarded) + + print 'Awarded %d badges' % awarded_count diff --git a/askbot/management/commands/askbot_clear_moderation_queue.py b/askbot/management/commands/askbot_clear_moderation_queue.py new file mode 100644 index 00000000..c767e670 --- /dev/null +++ b/askbot/management/commands/askbot_clear_moderation_queue.py @@ -0,0 +1,16 @@ +from django.core.management.base import NoArgsCommand +from askbot import const +from askbot.models import Activity + +ACTIVITY_TYPES = ( + const.TYPE_ACTIVITY_MODERATED_NEW_POST, + const.TYPE_ACTIVITY_MODERATED_POST_EDIT, + const.TYPE_ACTIVITY_MARK_OFFENSIVE +) + +class Command(NoArgsCommand): + help = 'deletes all items from the moderation queue' + def handle_noargs(self, *args, **kwargs): + acts = Activity.objects.filter(activity_type__in=ACTIVITY_TYPES) + acts.delete() + diff --git a/askbot/management/commands/delete_unused_tags.py b/askbot/management/commands/delete_unused_tags.py index 4a0a9925..90a4154f 100644 --- a/askbot/management/commands/delete_unused_tags.py +++ b/askbot/management/commands/delete_unused_tags.py @@ -14,8 +14,18 @@ class Command(NoArgsCommand): deleted_tags = list() for tag in ProgressBar(tags, total, message): if not tag.threads.exists(): - deleted_tags.append(tag.name) - tag.delete() + #if any user subscribed for the tag and + #the user is not blocked, skip deleting the tag + marks = tag.user_selections.all() + do_delete = True + for mark in marks: + if not mark.user.is_blocked(): + do_delete = False + break + + if do_delete: + deleted_tags.append(tag.name) + tag.delete() if deleted_tags: found_count = len(deleted_tags) diff --git a/askbot/management/commands/fix_question_tags.py b/askbot/management/commands/fix_question_tags.py index 48168ee8..6cfab806 100644 --- a/askbot/management/commands/fix_question_tags.py +++ b/askbot/management/commands/fix_question_tags.py @@ -27,7 +27,7 @@ def get_valid_tag_name(tag): first_char_regex = re.compile('^%s+' % const.TAG_FORBIDDEN_FIRST_CHARS) return first_char_regex.sub('', name) -class Command(Command): +class Command(NoArgsCommand): def handle_noargs(self, *args, **options): signal_data = signals.pop_all_db_signal_receivers() languages = models.Tag.objects.values_list('language_code').distinct() diff --git a/askbot/management/commands/rename_tags_id.py b/askbot/management/commands/rename_tags_id.py index 7926d28d..2f6e666f 100644 --- a/askbot/management/commands/rename_tags_id.py +++ b/askbot/management/commands/rename_tags_id.py @@ -106,7 +106,7 @@ rename_tags, but using tag id's to_tags = get_tags_by_ids(to_tag_ids) #all tags must belong to the same language - lang_codes = {tag.language_code for tag in (from_tags + to_tags)} + lang_codes = set(tag.language_code for tag in (from_tags + to_tags)) if len(lang_codes) != 1: langs = ', '.join(lang_codes) raise CommandError('all tags must belong to the same language, have: %s' % langs) diff --git a/askbot/management/commands/send_unanswered_question_reminders.py b/askbot/management/commands/send_unanswered_question_reminders.py index c428881d..54d06996 100644 --- a/askbot/management/commands/send_unanswered_question_reminders.py +++ b/askbot/management/commands/send_unanswered_question_reminders.py @@ -63,14 +63,18 @@ class Command(NoArgsCommand): threads = Thread.objects.filter(id__in=[qq.thread_id for qq in final_question_list]) tag_summary = Thread.objects.get_tag_summary_from_threads(threads) + if question_count == 1: + unanswered_questions_phrase = askbot_settings.WORDS_UNANSWERED_QUESTION_SINGULAR + else: + unanswered_questions_phrase = askbot_settings.WORDS_UNANSWERED_QUESTION_PLURAL + subject_line = ungettext( - '%(question_count)d %(unanswered_question)s about %(topics)s', + '%(question_count)d %(unanswered_questions)s about %(topics)s', '%(question_count)d %(unanswered_questions)s about %(topics)s', question_count ) % { 'question_count': question_count, - 'unanswered_question': askbot_settings.WORDS_UNANSWERED_QUESTION_SINGULAR, - 'unanswered_questions': askbot_settings.WORDS_UNANSWERED_QUESTION_PLURAL, + 'unanswered_questions': unanswered_questions_phrase, 'topics': tag_summary } |