From ac58f3b1a2652f1dd990c70cb0550a0902a76846 Mon Sep 17 00:00:00 2001 From: Matheus Fernandes Date: Mon, 27 Nov 2017 15:32:32 -0200 Subject: [PATCH] Fix/update site script (#98) * Update site name and domain on script Signed-off-by: Matheus Fernandes * Add missed function cal Signed-off-by: Matheus Fernandes --- wikilegis/create_admin.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/wikilegis/create_admin.py b/wikilegis/create_admin.py index ce45643c..7fd31905 100644 --- a/wikilegis/create_admin.py +++ b/wikilegis/create_admin.py @@ -25,6 +25,26 @@ def create_superuser(): sys.exit(1) +def update_sites(): + from django.contrib.sites.models import Site + import re + site = Site.objects.get_current() + site_domain = os.environ.get('SITE_DOMAIN', None) + site_name = os.environ.get('SITE_NAME', None) + + if None not in [site_domain, site_name]: + print('Updating site infos...') + site_domain = re.sub('^(http|https)://', '', site_domain) + + site.domain, site.name = site_domain, site_name + site.save() + print('Done!') + else: + print('Missing SITE_DOMAIN or SITE_NAME environment variable.') + sys.exit(2) + + if __name__ == '__main__': django.setup() create_superuser() + update_sites()