Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Only set the domain in site url

Roland Geider13e1b4979164
diff --git a/wger/core/management/commands/set-site-url.py b/wger/core/management/commands/set-site-url.py
index d47f7f876..3ee98c1d7 100644
--- a/wger/core/management/commands/set-site-url.py
+++ b/wger/core/management/commands/set-site-url.py
@@ -1,7 +1,15 @@
+# Standard Library
+from urllib.parse import urlparse
+
# Django
from django.conf import settings
from django.contrib.sites.models import Site
-from django.core.management.base import BaseCommand
+from django.core.exceptions import ValidationError
+from django.core.management.base import (
+ BaseCommand,
+ CommandError,
+)
+from django.core.validators import URLValidator
"""
@@ -10,13 +18,21 @@ Sets the site URL
class Command(BaseCommand):
-
help = 'Sets the site URL from settings.SITE_URL, this is used e.g. for password reset emails'
def handle(self, *args, **options):
+ if not settings.SITE_URL:
+ return
+
+ try:
+ val = URLValidator()
+ val(settings.SITE_URL)
+ except ValidationError:
+ raise CommandError('Please set a valid URL for SITE_URL')
+ domain = urlparse(settings.SITE_URL).netloc
site = Site.objects.get_current()
- site.domain = settings.SITE_URL
+ site.domain = domain
site.name = settings.SITE_URL
site.save()
- self.stdout.write(self.style.SUCCESS(f"Set site URL to {settings.SITE_URL}"))
+ self.stdout.write(self.style.SUCCESS(f"Set site URL to {domain}"))