delete_expired_contribs.py 991 B

1234567891011121314151617181920212223242526272829303132
  1. """Delete expired contributions
  2. Based on the expiration date that exists on any contrib. Produce no output by
  3. default (cron stuff)
  4. """
  5. from django.conf import settings
  6. from django.core.management.base import BaseCommand
  7. from ...models import Contrib
  8. class Command(BaseCommand):
  9. help = __doc__
  10. def add_arguments(self, parser):
  11. parser.add_argument(
  12. '--dry-run', default=False, action='store_true',
  13. help="Do not actually delete contributions, just print which ones should be")
  14. def handle(self, dry_run, *args, **options):
  15. if dry_run:
  16. self.stderr.write('DRY RUN MODE: we do not actually delete contributions.\n')
  17. for contrib in Contrib.objects.expired():
  18. if not dry_run:
  19. contrib.delete()
  20. else:
  21. self._log_deleted_contrib(contrib)
  22. def _log_deleted_contrib(self, contrib):
  23. self.stderr.write("Would delete expired contribution {}\n".format(contrib))