(request, layerid=None, user=None,
                     mapid=None, category=None, tolerant=False)
return HttpResponse(status=200)
Compile a GetCapabilities document containing public layers
    filtered by layer, user, map, or category
Compile a GetCapabilities document containing public layers
    filtered by layer, user, map, or category
Compile a GetCapabilities document containing public layers filtered by layer user map or category
def get_capabilities(request, layerid=None, user=None,
                     mapid=None, category=None, tolerant=False):
    """
    Compile a GetCapabilities document containing public layers
    filtered by layer, user, map, or category
    """

    rootdoc = None
    layers = None
    cap_name = ' Capabilities - '
    if layerid is not None:
        dataset_obj = Dataset.objects.get(id=layerid)
        cap_name += dataset_obj.title
        layers = Dataset.objects.filter(id=layerid)
    elif user is not None:
        layers = Dataset.objects.filter(owner__username=user)
        cap_name += user
    elif category is not None:
        layers = Dataset.objects.filter(category__identifier=category)
        cap_name += category
    elif mapid is not None:
        map_obj = Map.objects.get(id=mapid)
        cap_name += map_obj.title
        alternates = []
        for layer in map_obj.maplayers.iterator():
            if layer.local:
                alternates.append(layer.name)
        layers = Dataset.objects.filter(alternate__in=alternates)

    for layer in layers:
        if request.user.has_perm('view_resourcebase',
                                 layer.get_self_resource()):
            access_token = get_or_create_token(request.user)
            if access_token and not access_token.is_expired():
                access_token = access_token.token
            else:
                access_token = None
            try:
                workspace, layername = layer.alternate.split(":") if ":" in layer.alternate else (None, layer.alternate)
                layercap = get_dataset_capabilities(layer, access_token=access_token, tolerant=tolerant)
                if layercap is not None:  # 1st one, seed with real GetCapabilities doc
                    try:
                        namespaces = {'wms': 'http://www.opengis.net/wms',
                                      'xlink': 'http://www.w3.org/1999/xlink',
                                      'xsi': 'http://www.w3.org/2001/XMLSchema-instance'}
                        layercap = dlxml.fromstring(layercap)
                        rootdoc = etree.ElementTree(layercap)
                        format_online_resource(workspace, layername, rootdoc, namespaces)
                        service_name = rootdoc.find('.//wms:Service/wms:Name', namespaces)
                        if service_name is not None:
                            service_name.text = cap_name
                        rootdoc = rootdoc.find('.//wms:Capability/wms:Layer/wms:Layer', namespaces)
                    except Exception as e:
                        import traceback
                        traceback.print_exc()
                        logger.error(
                            f"Error occurred creating GetCapabilities for {layer.typename}: {str(e)}")
                        rootdoc = None
                if layercap is None or not len(layercap) or rootdoc is None or not len(rootdoc):
                    # Get the required info from layer model
                    # TODO: store time dimension on DB also
                    tpl = get_template("geoserver/layer.xml")
                    ctx = {
                        'layer': layer,
                        'geoserver_public_url': ogc_server_settings.public_url,
                        'catalogue_url': settings.CATALOGUE['default']['URL'],
                    }
                    gc_str = tpl.render(ctx)
                    gc_str = gc_str.encode("utf-8", "replace")
                    layerelem = etree.XML(gc_str)
                    rootdoc = etree.ElementTree(layerelem)
            except Exception as e:
                import traceback
                traceback.print_exc()
                logger.error(
                    f"Error occurred creating GetCapabilities for {layer.typename}:{str(e)}")
                rootdoc = None
    if rootdoc is not None:
        capabilities = etree.tostring(
            rootdoc,
            xml_declaration=True,
            encoding='UTF-8',
            pretty_print=True)
        return HttpResponse(capabilities, content_type="text/xml")
    return HttpResponse(status=200)
def get_capabilities ( request , layerid = None , user = None , mapid = None , category = None , tolerant = False ) : rootdoc = None layers = None cap_name = ' Capabilities - ' if layerid is not None : dataset_obj = Dataset . objects . get ( id = layerid ) cap_name += dataset_obj . title layers = Dataset . objects . filter ( id = layerid ) elif user is not None : layers = Dataset . objects . filter ( owner__username = user ) cap_name += user elif category is not None : layers = Dataset . objects . filter ( category__identifier = category ) cap_name += category elif mapid is not None : map_obj = Map . objects . get ( id = mapid ) cap_name += map_obj . title alternates = [ ] for layer in map_obj . maplayers . iterator ( ) : if layer . local : alternates . append ( layer . name ) layers = Dataset . objects . filter ( alternate__in = alternates ) for layer in layers : if request . user . has_perm ( 'view_resourcebase' , layer . get_self_resource ( ) ) : access_token = get_or_create_token ( request . user ) if access_token and not access_token . is_expired ( ) : access_token = access_token . token else : access_token = None try : workspace , layername = layer . alternate . split ( ":" ) if ":" in layer . alternate else ( None , layer . alternate ) layercap = get_dataset_capabilities ( layer , access_token = access_token , tolerant = tolerant ) if layercap is not None : # 1st one, seed with real GetCapabilities doc try : namespaces = { 'wms' : 'http://www.opengis.net/wms' , 'xlink' : 'http://www.w3.org/1999/xlink' , 'xsi' : 'http://www.w3.org/2001/XMLSchema-instance' } layercap = dlxml . fromstring ( layercap ) rootdoc = etree . ElementTree ( layercap ) format_online_resource ( workspace , layername , rootdoc , namespaces ) service_name = rootdoc . find ( './/wms:Service/wms:Name' , namespaces ) if service_name is not None : service_name . text = cap_name rootdoc = rootdoc . find ( './/wms:Capability/wms:Layer/wms:Layer' , namespaces ) except Exception as e : import traceback traceback . print_exc ( ) logger . error ( f"Error occurred creating GetCapabilities for {layer.typename}: {str(e)}" ) rootdoc = None if layercap is None or not len ( layercap ) or rootdoc is None or not len ( rootdoc ) : # Get the required info from layer model # TODO: store time dimension on DB also tpl = get_template ( "geoserver/layer.xml" ) ctx = { 'layer' : layer , 'geoserver_public_url' : ogc_server_settings . public_url , 'catalogue_url' : settings . CATALOGUE [ 'default' ] [ 'URL' ] , } gc_str = tpl . render ( ctx ) gc_str = gc_str . encode ( "utf-8" , "replace" ) layerelem = etree . XML ( gc_str ) rootdoc = etree . ElementTree ( layerelem ) except Exception as e : import traceback traceback . print_exc ( ) logger . error ( f"Error occurred creating GetCapabilities for {layer.typename}:{str(e)}" ) rootdoc = None if rootdoc is not None : capabilities = etree . tostring ( rootdoc , xml_declaration = True , encoding = 'UTF-8' , pretty_print = True ) return HttpResponse ( capabilities , content_type = "text/xml" ) return HttpResponse ( status = 200 )