Skip to content

Commit

Permalink
Add set_site command
Browse files Browse the repository at this point in the history
  • Loading branch information
skatsaounis committed May 12, 2020
1 parent 7c6b37e commit c41444e
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions patchman/management/commands/set_site.py
Original file line number Diff line number Diff line change
@@ -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))

0 comments on commit c41444e

Please sign in to comment.