From c41444ecf8404b0777cd47dc13569458fb6d8830 Mon Sep 17 00:00:00 2001 From: Stamatis Katsaounis Date: Tue, 12 May 2020 13:24:44 +0300 Subject: [PATCH] Add set_site command --- patchman/management/commands/set_site.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 patchman/management/commands/set_site.py diff --git a/patchman/management/commands/set_site.py b/patchman/management/commands/set_site.py new file mode 100644 index 00000000..659bb281 --- /dev/null +++ b/patchman/management/commands/set_site.py @@ -0,0 +1,23 @@ +from django.core.management.base import BaseCommand, CommandError +from django.contrib.sites.models import Site +from django.conf import settings + + +class Command(BaseCommand): + help = 'Set Patchman Site Name' + + def add_arguments(self, parser): + parser.add_argument( + '-n', '--name', dest='site_name', help='Site name') + parser.add_argument( + '--clear-cache', action='store_true', default=False, + dest='clear_cache', help='Clear Site cache') + + def handle(self, *args, **options): + try: + Site.objects.filter(pk=settings.SITE_ID).update( + name=options['site_name'], domain=options['site_name']) + if options['claer_cache']: + Site.objects.clear_cache() + except Exception as e: + raise CommandError('Failed to update Site name', str(e))