summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEvgeny Fadeev <evgeny.fadeev@gmail.com>2014-08-20 14:23:10 +0400
committerEvgeny Fadeev <evgeny.fadeev@gmail.com>2014-08-20 14:23:10 +0400
commit081f52a73bf40a859d703e798725d8729026df30 (patch)
tree2ade236e08e31a49815ed74c7521dd420ca0bdd0
parent6b04939c5bd25da3dd195d960ae27de636414120 (diff)
downloadaskbot-081f52a73bf40a859d703e798725d8729026df30.tar.gz
askbot-081f52a73bf40a859d703e798725d8729026df30.tar.bz2
askbot-081f52a73bf40a859d703e798725d8729026df30.zip
when users are blocked, tags created by them are marked as deleted
-rw-r--r--askbot/management/commands/delete_unused_tags.py14
-rw-r--r--askbot/models/__init__.py15
2 files changed, 25 insertions, 4 deletions
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/models/__init__.py b/askbot/models/__init__.py
index efb5d749..70c6628b 100644
--- a/askbot/models/__init__.py
+++ b/askbot/models/__init__.py
@@ -1580,7 +1580,8 @@ def user_delete_question(
question.thread.save()
for tag in list(question.thread.tags.all()):
- if tag.used_count == 1:
+ if tag.used_count <= 1:
+ tag.used_count = 0
tag.deleted = True
tag.deleted_by = self
tag.deleted_at = timestamp
@@ -1612,7 +1613,9 @@ def user_delete_all_content_authored_by_user(self, author, timestamp=None):
#delete questions
questions = Post.objects.get_questions().filter(author=author)
- count += questions.update(deleted_at=timestamp, deleted_by=self, deleted=True)
+ count += questions.count()
+ for question in questions:
+ self.delete_question(question=question, timestamp=timestamp)
threads = Thread.objects.filter(last_activity_by=author)
for thread in threads:
@@ -1631,6 +1634,14 @@ def user_delete_all_content_authored_by_user(self, author, timestamp=None):
count += comments.count()
comments.delete()
+ #delete all unused tags created by this user
+ #tags = author.created_tags.all()
+ #tag_ids = list()
+ #for tag in tags:
+ # if tag.used_count == 0:
+ # tag_ids.append(tag.id)
+ #Tag.objects.filter(id__in=tag_ids).delete()
+
return count