How to use the geonode.layers.models.Layer.objects.filter function in GeoNode

To help you get started, we’ve selected a few GeoNode examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github GeoNode / geonode / geonode / services / serviceprocessors / wms.py View on Github external
content_type = response.headers['Content-Type']

        if status == 200 and 'application/json' == content_type:
            try:
                _json_obj = json.loads(content)
                if _json_obj['meta']['total_count'] == 1:
                    _layer = _json_obj['objects'][0]
                    if _layer:
                        r_fields = {}

                        # Update plain fields
                        for field in GeoNodeServiceHandler.LAYER_FIELDS:
                            if field in _layer and _layer[field]:
                                r_fields[field] = _layer[field]
                        if r_fields:
                            Layer.objects.filter(
                                id=geonode_layer.id).update(
                                **r_fields)
                            geonode_layer.refresh_from_db()

                        # Update Thumbnail
                        if "thumbnail_url" in _layer and _layer["thumbnail_url"]:
                            thumbnail_remote_url = _layer["thumbnail_url"]
                            _url = urlsplit(thumbnail_remote_url)
                            if not _url.scheme:
                                thumbnail_remote_url = "{}{}".format(
                                    geonode_layer.remote_service.service_url, _url.path)
                            resp, image = http_client.request(
                                thumbnail_remote_url)
                            if 'ServiceException' in image or \
                               resp.status_code < 200 or resp.status_code > 299:
                                msg = 'Unable to obtain thumbnail: %s' % image
github GeoNode / geonode / geonode / geoserver / management / commands / find_geoserver_broken_layers.py View on Github external
def handle(self, **options):
        if options['layername']:
            layers = Layer.objects.filter(name__icontains=options['layername'])
        else:
            layers = Layer.objects.all()
        if options['owner']:
            layers = layers.filter(owner=Profile.objects.filter(username=options['owner']))

        layers_count = layers.count()
        count = 0

        layer_errors = []
        for layer in layers:
            count += 1
            try:
                print("Checking layer {}/{}: {} owned by {}".format(
                    count,
                    layers_count,
                    layer.alternate,
github GeoNode / geonode / geonode / upload / upload.py View on Github external
# saved_layer = Layer.objects.filter(name=upload_session.append_to_mosaic_name)
            # created = False
            saved_layer, created = Layer.objects.get_or_create(
                name=upload_session.append_to_mosaic_name)
            try:
                if saved_layer.temporal_extent_start and end:
                    if pytz.utc.localize(
                            saved_layer.temporal_extent_start,
                            is_dst=False) < end:
                        saved_layer.temporal_extent_end = end
                        Layer.objects.filter(
                            name=upload_session.append_to_mosaic_name).update(
                            temporal_extent_end=end)
                    else:
                        saved_layer.temporal_extent_start = end
                        Layer.objects.filter(
                            name=upload_session.append_to_mosaic_name).update(
                            temporal_extent_start=end)
            except Exception as e:
                _log(
                    'There was an error updating the mosaic temporal extent: ' +
                    str(e))
    else:
        _has_time = (True if upload_session.time and upload_session.time_info and
                     upload_session.time_transforms else False)
        saved_layer, created = Layer.objects.get_or_create(
            name=task.layer.name,
            defaults=dict(store=target.name,
                          storeType=target.store_type,
                          alternate=alternate,
                          workspace=target.workspace_name,
                          title=title,
github cartologic / cartoview / cartoview / templatetags / cartoview_tags.py View on Github external
title__icontains=title_filter)
        if settings.RESOURCE_PUBLISHING:
            appinstances = appinstances.filter(is_published=True)

        if not settings.SKIP_PERMS_FILTER:
            appinstances = appinstances.filter(id__in=authorized)

        counts = appinstances.values('app__title').annotate(
            count=Count('app__name'))
        facets = dict([(count['app__title'], count['count'])
                       for count in counts])
        return facets

    else:

        layers = Layer.objects.filter(title__icontains=title_filter)

        if settings.RESOURCE_PUBLISHING:
            layers = layers.filter(is_published=True)

        if not settings.SKIP_PERMS_FILTER:
            layers = layers.filter(id__in=authorized)

        counts = layers.values('storeType').annotate(count=Count('storeType'))
        count_dict = dict([(count['storeType'], count['count'])
                           for count in counts])

        facets = {
            'raster': count_dict.get('coverageStore', 0),
            'vector': count_dict.get('dataStore', 0),
            'remote': count_dict.get('remoteStore', 0),
        }
github GeoNode / geonode / geonode / maps / models.py View on Github external
def layer_config(self, user=None):
        # Try to use existing user-specific cache of layer config
        if self.id:
            cfg = cache.get("layer_config" +
                            str(self.id) +
                            "_" +
                            str(0 if user is None else user.id))
            if cfg is not None:
                return cfg

        cfg = GXPLayerBase.layer_config(self, user=user)
        # if this is a local layer, get the attribute configuration that
        # determines display order & attribute labels
        if Layer.objects.filter(alternate=self.name).exists():
            try:
                if self.local:
                    layer = Layer.objects.get(store=self.store, alternate=self.name)
                else:
                    layer = Layer.objects.get(
                        alternate=self.name,
                        remote_service__base_url=self.ows_url)
                attribute_cfg = layer.attribute_config()
                if "getFeatureInfo" in attribute_cfg:
                    cfg["getFeatureInfo"] = attribute_cfg["getFeatureInfo"]
                if not user.has_perm(
                        'base.view_resourcebase',
                        obj=layer.resourcebase_ptr):
                    cfg['disabled'] = True
                    cfg['visibility'] = False
            except BaseException:
github MapStory / mapstory / mapstory / storylayers / views.py View on Github external
try:
            layers = creator.handle(
                configuration_options=configuration_options)

        except UploadError as e:
            errors = True
            error_messages.append(
                (configuration_options['featureType']['name'], e.message))

        if request.is_ajax():
            if errors:
                return HttpResponse(json.dumps({'status': 'failure', 'errors': error_messages}), status=400,
                                    content_type='application/json')
            if layers:
                layer_names = map(lambda layer: {'name': layer.name, 'url': layer.get_absolute_url()},
                                  Layer.objects.filter(name__in=[n[0] for n in layers]))

                return HttpResponse(json.dumps({'status': 'success', 'layers': layer_names}), status=201,
                                    content_type='application/json')

    return render_to_response(template, RequestContext(request, {}))
github GeoNode / geonode / geonode / layers / utils.py View on Github external
def get_valid_name(layer_name):
    """
    Create a brand new name
    """
    name = _clean_string(layer_name)
    proposed_name = name
    count = 1
    while Layer.objects.filter(name=proposed_name).exists():
        proposed_name = "%s_%d" % (name, count)
        count = count + 1
        logger.warning('Requested name already used; adjusting name '
                       '[%s] => [%s]', layer_name, proposed_name)
    else:
        logger.debug("Using name as requested")

    return proposed_name
github GeoNode / geonode / geonode / search / extension.py View on Github external
    layer_query = lambda q: Layer.objects.filter()
github GeoNode / geonode / geonode / base / management / commands / fixgeofencerules.py View on Github external
def handle(self, *args, **options):
        use_geofence = settings.OGC_SERVER['default'].get(
            "GEOFENCE_SECURITY_ENABLED", False)
        if use_geofence:
            profiles = Profile.objects.filter(is_superuser=False)
            authorized = list(get_objects_for_user(profiles[0], 'base.view_resourcebase').values('id'))
            layers = Layer.objects.filter(id__in=[d['id'] for d in authorized])

            for index, layer in enumerate(layers):
                print "[%s / %s] Setting default permissions to Layer [%s] ..." % ((index + 1), len(layers), layer.name)
                try:
                    utils.set_geofence_all(layer)
                except:
                    print "[ERROR] Layer [%s] couldn't be updated" % (layer.name)

            protected_layers = Layer.objects.all().exclude(id__in=[d['id'] for d in authorized])

            for index, layer in enumerate(protected_layers):
                print "[%s / %s] Setting owner permissions to Layer [%s] ..." \
                      % ((index + 1), len(protected_layers), layer.name)
                try:
                    perms = utils.get_users_with_perms(layer)
                    for profile in perms.keys():