Mercurial > public > sg101
annotate gpp/messages/management/commands/purge_messages.py @ 318:c550933ff5b6
Fix a bug where you'd get an error when trying to delete a forum thread (topic does not exist). Apparently when you call topic.delete() the posts would get deleted, but the signal handler for each one would run, and it would try to update the topic's post count or something, but the topic was gone? Reworked the code a bit and explicitly delete the posts first. I also added a sync() call on the parent forum since post counts were not getting adjusted.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Sat, 05 Feb 2011 21:46:52 +0000 |
parents | dbd703f7d63a |
children | 5171a5e9353b |
rev | line source |
---|---|
gremmie@1 | 1 """ |
gremmie@1 | 2 purge_messages is a custom manage.py command for the messages application. |
gremmie@1 | 3 It is intended to be called from a cron job to purge messages that have been |
gremmie@1 | 4 deleted by both sender and receiver. |
gremmie@1 | 5 """ |
gremmie@1 | 6 |
gremmie@1 | 7 from django.core.management.base import NoArgsCommand |
gremmie@1 | 8 |
gremmie@1 | 9 from messages.models import Message |
gremmie@1 | 10 |
gremmie@1 | 11 |
gremmie@1 | 12 class Command(NoArgsCommand): |
gremmie@1 | 13 help = "Delete messages that have been sent to the trash by both sender and receiver." |
gremmie@1 | 14 |
gremmie@1 | 15 def handle_noargs(self, **options): |
gremmie@1 | 16 Message.objects.filter(sender_delete_date__isnull=False, |
gremmie@1 | 17 receiver_delete_date__isnull=False).delete() |
gremmie@1 | 18 |
gremmie@1 | 19 |
gremmie@1 | 20 # vim: ts=4 sw=4 |