From aee6fa767e4475d6c3d2293ce48683b2f61397f6 Mon Sep 17 00:00:00 2001 From: Evgeny Fadeev Date: Tue, 6 Mar 2012 21:29:19 -0300 Subject: added management command delete_contextless_activities --- askbot/doc/source/changelog.rst | 1 + askbot/doc/source/management-commands.rst | 4 ++++ .../commands/delete_contextless_activities.py | 18 ++++++++++++++++++ 3 files changed, 23 insertions(+) create mode 100644 askbot/management/commands/delete_contextless_activities.py diff --git a/askbot/doc/source/changelog.rst b/askbot/doc/source/changelog.rst index b6880d37..a8e695a6 100644 --- a/askbot/doc/source/changelog.rst +++ b/askbot/doc/source/changelog.rst @@ -19,6 +19,7 @@ Development version (not released yet) * Fixed a file upload issue in FF and IE found by jerry_gzy (Evgeny) * Added test on maximum length of title working for utf-8 text (Evgeny) * Added caching and invalidation to the question page (Evgeny) +* Added a management command delete_contextless_activities (Evgeny) 0.7.39 (Jan 11, 2012) --------------------- diff --git a/askbot/doc/source/management-commands.rst b/askbot/doc/source/management-commands.rst index b857d6f0..f6c5beec 100644 --- a/askbot/doc/source/management-commands.rst +++ b/askbot/doc/source/management-commands.rst @@ -84,6 +84,10 @@ The bulk of the management commands fall into this group and will probably be th | | Deletes Activity objects of type badge award where the | | | related context object is lost. | +---------------------------------+-------------------------------------------------------------+ +| `delete_contextless_activities` | Same as above, but works in a broader sense - when the | +| | related context object does not exist, but the generic | +| | foreign key to that object is still present. | ++---------------------------------+-------------------------------------------------------------+ .. _email-related-commands: diff --git a/askbot/management/commands/delete_contextless_activities.py b/askbot/management/commands/delete_contextless_activities.py new file mode 100644 index 00000000..e16a9957 --- /dev/null +++ b/askbot/management/commands/delete_contextless_activities.py @@ -0,0 +1,18 @@ +from django.core.management.base import NoArgsCommand +from askbot.utils.console import ProgressBar +from askbot.models import Activity +from askbot import const + +class Command(NoArgsCommand): + def handle_noargs(self, **options): + acts = Activity.objects.all() + deleted_count = 0 + message = "Searching for context-less activity objects:" + for act in ProgressBar(acts.iterator(), acts.count(), message): + if act.object_id != None and act.content_object == None: + act.delete() + deleted_count += 1 + if deleted_count: + print "%d activity objects deleted" % deleted_count + else: + print "None found" -- cgit v1.2.3-1-g7c22