Skip to content

Instantly share code, notes, and snippets.

@dwins
Created September 9, 2011 13:54
Show Gist options
  • Save dwins/1206268 to your computer and use it in GitHub Desktop.
Save dwins/1206268 to your computer and use it in GitHub Desktop.
from django.core.management.base import BaseCommand
from django.db import transaction
from geonode.maps.models import MapLayer
import json
class Command(BaseCommand):
help = """
Changes the OWS url for all layers in geonode maps, useful for when a map
server changes. If you use an absolute URL for the GEOSERVER_URL setting
this simplifies the process of changing the hostname for your GeoNode site.
"""
args = '{old_prefix} {new_prefix}'
@transaction.commit_on_success()
def handle(self, *args, **keywordargs):
assert len(args) == 2, "Both old and new OWS URL needed."
old_url, new_url = args
for ml in MapLayer.objects.filter(ows_url__startswith=old_url):
ml.ows_url = ml.ows_url.replace(old_url, new_url, 1)
ml.source_params = json.dumps({
'restUrl': '/gs/rest/',
'ptype': "gxp_wmscsource",
'id': 0,
'baseParams': {
"VERSION": "1.1.1",
"REQUEST": "GetCapabilities",
"TILED": True,
"SERVICE": "WMS"
}})
ml.save()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment