summaryrefslogtreecommitdiffstats
path: root/askbot/management
diff options
context:
space:
mode:
authorEvgeny Fadeev <evgeny.fadeev@gmail.com>2012-09-15 00:02:16 -0400
committerEvgeny Fadeev <evgeny.fadeev@gmail.com>2012-09-15 00:02:16 -0400
commit68777c3cc2c7f5bac163f3e6de4633e9e5c951d6 (patch)
tree41d3c7ea6347671421f1be476b3a6cfb5c7a3d4a /askbot/management
parent7cc222d1faa0a4cefb0ef62753507b64e1b7e58a (diff)
parenta78267c762eb37f14f926435fa665e00d80ceb79 (diff)
downloadaskbot-68777c3cc2c7f5bac163f3e6de4633e9e5c951d6.tar.gz
askbot-68777c3cc2c7f5bac163f3e6de4633e9e5c951d6.tar.bz2
askbot-68777c3cc2c7f5bac163f3e6de4633e9e5c951d6.zip
merged with the tag-editor branch
Diffstat (limited to 'askbot/management')
-rw-r--r--askbot/management/commands/delete_unused_tags.py18
-rw-r--r--askbot/management/commands/rename_tags_id.py16
-rw-r--r--askbot/management/commands/sample_command.py6
3 files changed, 21 insertions, 19 deletions
diff --git a/askbot/management/commands/delete_unused_tags.py b/askbot/management/commands/delete_unused_tags.py
index 9b7c3c1b..bc0b7d69 100644
--- a/askbot/management/commands/delete_unused_tags.py
+++ b/askbot/management/commands/delete_unused_tags.py
@@ -1,26 +1,28 @@
from django.core.management.base import NoArgsCommand
from django.db import transaction
from askbot import models
-from askbot.utils import console
+from askbot.utils.console import ProgressBar
+from askbot.conf import settings as askbot_settings
import sys
class Command(NoArgsCommand):
@transaction.commit_manually
def handle_noargs(self, **options):
tags = models.Tag.objects.all()
- count = 0
- print "Searching for unused tags:",
+ message = 'Searching for unused tags:'
total = tags.count()
+ tags = tags.iterator()
deleted_tags = list()
- for tag in tags:
+ for tag in ProgressBar(tags, total, message):
+ if tag.name == askbot_settings.GLOBAL_GROUP_NAME:#todo: temporary
+ continue
+ if tag.name.startswith('_internal_'):
+ continue
+
if not tag.threads.exists():
deleted_tags.append(tag.name)
tag.delete()
transaction.commit()
- count += 1
- progress = 100*float(count)/float(total)
- console.print_progress('%6.2f%%', progress)
- print '%6.2f%%' % 100
if deleted_tags:
found_count = len(deleted_tags)
diff --git a/askbot/management/commands/rename_tags_id.py b/askbot/management/commands/rename_tags_id.py
index 90dc2916..f6fe05ae 100644
--- a/askbot/management/commands/rename_tags_id.py
+++ b/askbot/management/commands/rename_tags_id.py
@@ -27,8 +27,8 @@ def get_similar_tags_from_strings(tag_strings, tag_name):
"""returns a list of tags, similar to tag_name from a set of questions"""
grab_pattern = r'\b([%(ch)s]*%(nm)s[%(ch)s]*)\b' % \
- {'ch': const.TAG_CHARS, 'nm': from_tag.name}
- grab_re = re.compile(grab_pattern, RE.IGNORECASE)
+ {'ch': const.TAG_CHARS, 'nm': tag_name}
+ grab_re = re.compile(grab_pattern, re.IGNORECASE)
similar_tags = set()
for tag_string in tag_strings:
@@ -103,9 +103,9 @@ rename_tags, but using tag id's
to_tags = get_tags_by_ids(to_tag_ids)
admin = get_admin(options['user_id'])
- questions = models.Question.objects.all()
+ questions = models.Thread.objects.all()
for from_tag in from_tags:
- questions = questions.filter(tags = from_tag)
+ questions = questions.filter(tags=from_tag)
#print some feedback here and give a chance to bail out
question_count = questions.count()
@@ -121,7 +121,7 @@ or repost a bug, if that does not help"""
print "%d questions match." % question_count
print "First 10 are:"
for question in questions[:10]:
- print '* %s' % question.thread.title.strip()
+ print '* %s' % question.title.strip()
from_tag_names = format_tag_name_list(from_tags)
to_tag_names = format_tag_name_list(to_tags)
@@ -145,7 +145,7 @@ or repost a bug, if that does not help"""
tag_names.difference_update(from_tag_names)
admin.retag_question(
- question = question,
+ question = question._question_post(),
tags = u' '.join(tag_names),
#silent = True #do we want to timestamp activity on question
)
@@ -159,8 +159,8 @@ or repost a bug, if that does not help"""
#may need to run assertions on that there are
#print 'Searching for similar tags...',
- #leftover_questions = models.Question.objects.filter(
- # icontains = from_tag.name
+ #leftover_questions = models.Thread.objects.filter(
+ # icontains=from_tag.name
# )
#if leftover_questions.count() > 0:
# tag_strings = leftover_questions.values_list('tagnames', flat=True)
diff --git a/askbot/management/commands/sample_command.py b/askbot/management/commands/sample_command.py
index bcdcb58e..40debe63 100644
--- a/askbot/management/commands/sample_command.py
+++ b/askbot/management/commands/sample_command.py
@@ -1,7 +1,7 @@
from django.core.management.base import NoArgsCommand
-from askbot.models import Comment
+from askbot.models import Post
class Command(NoArgsCommand):
def handle_noargs(self, **options):
- objs = Comment.objects.all()
- print objs \ No newline at end of file
+ objs = Post.objects.all()
+ print objs