From c1c5b015c782f93ebe7db8951871c9e9b896572a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89lie=20Bouttier?= Date: Sat, 12 Aug 2017 22:25:17 +0200 Subject: [PATCH] suffixdomains command for dev purpose --- ponyconf/management/commands/suffixdomains.py | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 ponyconf/management/commands/suffixdomains.py diff --git a/ponyconf/management/commands/suffixdomains.py b/ponyconf/management/commands/suffixdomains.py new file mode 100644 index 0000000..7968aa4 --- /dev/null +++ b/ponyconf/management/commands/suffixdomains.py @@ -0,0 +1,27 @@ +from django.core.management.base import BaseCommand +from django.contrib.sites.models import Site + + +class Command(BaseCommand): + help = 'Add a suffix to all site domains.' + + def add_arguments(self, parser): + parser.add_argument('suffix') + + def handle(self, *args, **options): + answer = input("""You are about to change all site domains. +Are you sure you want to do this? + + Type 'yes' to continue, or 'no' to cancel: """) + + self.stdout.write('\n') + + if answer != "yes": + self.stdout.write(self.style.NOTICE('Action cancelled.')) + return + + for site in Site.objects.all(): + site.domain = site.domain + options['suffix'] + site.save() + + self.stdout.write(self.style.SUCCESS('All domains modified.'))