remakemisagochecksums.py 1.1 KB

123456789101112131415161718192021222324252627282930
  1. from django.core.management.base import BaseCommand
  2. from django.utils.encoding import force_str
  3. from django.utils.six.moves import input
  4. from ...signals import secret_key_changed
  5. class Command(BaseCommand):
  6. help = 'Regenerates Misago checksums after SECRET_KEY changed.'
  7. def add_arguments(self, parser):
  8. parser.add_argument(
  9. '--force',
  10. action='store_true',
  11. dest='force',
  12. default=False,
  13. help='Do not ask for confirmation',
  14. )
  15. def handle(self, *args, **options):
  16. message = force_str("This will replace all checksums "
  17. "in database with new ones, marking "
  18. "all data as trusted. Are you sure "
  19. "you wish to continue? [Y/n]")
  20. if options['force'] or input(message).strip().lower() == "y":
  21. self.stdout.write("\nRegenerating checksums...")
  22. secret_key_changed.send(self)
  23. self.stdout.write("\nDone!")
  24. else:
  25. self.stdout.write("\nAborted!")