Skip to content

Commit

Permalink
Add management command to change Base URL. Closes kiwitcms#971
Browse files Browse the repository at this point in the history
  • Loading branch information
schwarzkrieger committed Apr 28, 2020
1 parent a881646 commit bcacfe9
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions tcms/management/management/commands/baseurl.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from django.core.management.base import BaseCommand
from django.contrib.sites.models import Site


class Command(BaseCommand):
help = "Sets the base URL of KiwiTCMS instance. " \
"If no arguments given returns current base URL."

def add_arguments(self, parser):
parser.add_argument(
'baseurl', nargs='?', default=None,
help='Base URL of KiwiTCMS instance',
)
parser.add_argument(
'basename', nargs='?', default='KiwiTCMS',
help='Optional site name. Defaults to "KiwiTCMS"',
)

def handle(self, *args, **kwargs):
if not kwargs['baseurl']:
try:
site = Site.objects.get(id=1)
self.stdout.write('URL: "%s", name: "%s"' % (site.domain, site.name))
except Site.DoesNotExist:
self.stdout.write('Base URL is not defined')
return
site, created = Site.objects.update_or_create(
id=1,
defaults={
'domain': kwargs['baseurl'],
'name': kwargs['basename'],
}
)
self.stdout.write('Base URL updated successfully.')

0 comments on commit bcacfe9

Please sign in to comment.