modification of initsitedomain command and migration to work when the web_url doesn't start with 'http://'
authorgrandjoncl
Mon, 03 Dec 2012 11:03:40 +0100
changeset 1002 f0948f50816b
parent 1001 c558d677ee52
child 1004 a7b268e93413
modification of initsitedomain command and migration to work when the web_url doesn't start with 'http://'
src/ldt/ldt/ldt_utils/migrations/0025_chg_site_domain.py
src/ldt/ldt/management/commands/initsitedomain.py
--- a/src/ldt/ldt/ldt_utils/migrations/0025_chg_site_domain.py	Mon Dec 03 10:43:13 2012 +0100
+++ b/src/ldt/ldt/ldt_utils/migrations/0025_chg_site_domain.py	Mon Dec 03 11:03:40 2012 +0100
@@ -11,8 +11,11 @@
         Sites = orm['sites.Site']
         site = Sites.objects.get(id=settings.SITE_ID)
         web_url = settings.WEB_URL
-        domain_area = web_url.split("//",1)
-        domain = domain_area[1]
+        if (web_url.startswith("http://")):
+            domain_area = web_url.split("//",1)
+            domain = domain_area[1]
+        else :
+            domain=web_url
         if site.domain!=domain:
             site.domain = domain
             site.save()
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ldt/ldt/management/commands/initsitedomain.py	Mon Dec 03 11:03:40 2012 +0100
@@ -0,0 +1,24 @@
+from django.core.management.base import BaseCommand
+from ldt.ldt_utils.models import Content, Project
+from ldt.ldt_utils.contentindexer import ContentIndexer, ProjectIndexer
+from django.conf import settings
+from django.db import models
+from django.contrib.sites.models import Site
+
+class Command(BaseCommand):
+    help = 'set the site domain to the right value according to the django settings'
+    
+    def handle(self, *args, **options):
+        site = Site.objects.get(id=settings.SITE_ID)
+        web_url = settings.WEB_URL
+        if (web_url.startswith("http://")):
+            domain_area = web_url.split("//",1)
+            domain = domain_area[1]
+        else:
+            domain=web_url
+        if site.domain!=domain:
+            site.domain = domain
+            site.save()
+        if site.name!=domain:
+            site.name=domain
+            site.save()
\ No newline at end of file