Skip to content

Commit

Permalink
Fixes #301
Browse files Browse the repository at this point in the history
  • Loading branch information
capooti committed Mar 30, 2018
1 parent 1be90de commit d518ce2
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
4 changes: 3 additions & 1 deletion geonode/layers/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -601,14 +601,16 @@ def post_delete_layer(instance, sender, **kwargs):
if instance.service is not None and instance.service.method == INDEXED:
return

from urlparse import urlparse
from geonode.maps.models import MapLayer
if instance.alternate:
hostname = urlparse(instance.ows_url).hostname
logger.debug(
"Going to delete associated maplayers for [%s]",
instance.alternate.encode('utf-8'))
MapLayer.objects.filter(
name=instance.alternate,
ows_url=instance.ows_url).delete()
ows_url__icontains=hostname).delete()

if instance.alternate:
logger.debug(
Expand Down
35 changes: 35 additions & 0 deletions geonode/maps/management/commands/remove_broken_layers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# -*- coding: utf-8 -*-
#########################################################################
#
# Copyright (C) 2018 OSGeo
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
#########################################################################

from django.core.management.base import BaseCommand


class Command(BaseCommand):
help = 'Remove broken map layers'

def handle(self, *args, **options):
from geonode.maps.models import MapLayer
from geonode.layers.models import Layer

map_layers = MapLayer.objects.filter(local=True)
for maplayer in map_layers:
if not Layer.objects.filter(alternate=maplayer.name).exists():
print 'Removing broken map layer %s' % maplayer.name
maplayer.delete()

0 comments on commit d518ce2

Please sign in to comment.