'Publishes local map layers as WMS layer group on local OWS.'

def publish_layer_group(self):

    if ('geonode.geoserver' in settings.INSTALLED_APPS):
        from geonode.geoserver.helpers import gs_catalog
        from geoserver.layergroup import UnsavedLayerGroup as GsUnsavedLayerGroup
    else:
        raise Exception('Cannot    publish    layer    group    if    geonode.geoserver    is    not    in    INSTALLED_APPS')
    if (not self.is_public):
        return 'Only    public    maps    can    be    saved    as    layer    group.'
    map_layers = MapLayer.objects.filter(map=self.id)
    layers = []
    lg_styles = []
    for ml in map_layers:
        if ml.local:
            layer = Layer.objects.get(alternate=ml.name)
            style = (ml.styles or getattr(layer.default_style, 'name', ''))
            layers.append(layer)
            lg_styles.append(style)
    lg_layers = [l.name for l in layers]
    lg_bounds = [str(coord) for coord in self.bbox]
    lg_name = ('%s_%d' % (slugify(self.title), self.id))
    lg = self.layer_group
    if (lg is None):
        lg = GsUnsavedLayerGroup(gs_catalog, lg_name, lg_layers, lg_styles, lg_bounds)
    else:
        (lg.layers, lg.styles, lg.bounds) = (lg_layers, lg_styles, lg_bounds)
    gs_catalog.save(lg)
    return lg_name
