forked from kiwitcms/Kiwi
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add management command to change Base URL. Closes kiwitcms#971
- Loading branch information
1 parent
a881646
commit bcacfe9
Showing
1 changed file
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.') |