How to use the geonode.layers.models.Layer 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 / layers / views.py View on Github external
def batch_permissions(request, ids, model):
    Resource = None
    if model == 'Layer':
        Resource = Layer
    if not Resource or not request.user.is_superuser:
        raise PermissionDenied

    template = 'base/batch_permissions.html'

    if "cancel" in request.POST:
        return HttpResponseRedirect(
            '/admin/{model}s/{model}/'.format(model=model.lower())
        )

    if request.method == 'POST':
        form = BatchPermissionsForm(request.POST)
        if form.is_valid():
            _data = form.cleaned_data
            resources_names = []
            for resource in Resource.objects.filter(id__in=ids.split(',')):
github GeoNode / geonode / geonode / layers / utils.py View on Github external
defaults['bbox_y1'] = defaults.get('bbox_y1', None) or layer.bbox_y1

        defaults['is_approved'] = defaults.get(
            'is_approved', is_approved) or layer.is_approved

        defaults['is_published'] = defaults.get(
            'is_published', is_published) or layer.is_published

        defaults['license'] = defaults.get('license', None) or layer.license

        defaults['category'] = defaults.get('category', None) or layer.category

        try:
            Layer.objects.filter(id=layer.id).update(**defaults)
            layer.refresh_from_db()
        except Layer.DoesNotExist:
            import traceback
            tb = traceback.format_exc()
            logger.error(tb)
            raise

        # Pass the parameter overwrite to tell whether the
        # geoserver_post_save_signal should upload the new file or not
        layer.overwrite = overwrite

        # Blank out the store if overwrite is true.
        # geoserver_post_save_signal should upload the new file if needed
        layer.store = '' if overwrite else layer.store
        layer.save()

        if upload_session:
            upload_session.resource = layer
github GeoNode / geonode / geonode / search / search.py View on Github external
def _get_layer_results(query):

    q = extension.layer_query(query)

    q = _filter_security(q, query.user, Layer, 'view_layer')

    if extension.exclude_patterns:
        name_filter = reduce(operator.or_,[ Q(name__regex=f) for f in extension.exclude_patterns])
        q = q.exclude(name_filter)

    if query.kw:
        q = q.filter(_build_kw_only_query(query.kw))

    if query.exclude:
        q = q.exclude(reduce(operator.or_, [Q(title__contains=ex) for ex in query.exclude]))

    if query.owner:
        q = q.filter(owner__username=query.owner)

    if query.extent:
        q = filter_by_extent(Layer, q, query.extent)
github GeoNode / geonode / geonode / base / management / commands / migrate_baseurl.py View on Github external
print("...done!")

                _cnt = Map.objects.filter(thumbnail_url__icontains=source_address).update(
                    thumbnail_url=Func(
                        F('thumbnail_url'),Value(source_address),Value(target_address),function='replace'))
                print("Updated %s Maps" % _cnt)

                _cnt = MapLayer.objects.filter(ows_url__icontains=source_address).update(
                    ows_url=Func(
                        F('ows_url'),Value(source_address),Value(target_address),function='replace'))
                MapLayer.objects.filter(layer_params__icontains=source_address).update(
                    layer_params=Func(
                        F('layer_params'),Value(source_address),Value(target_address),function='replace'))
                print("Updated %s MapLayers" % _cnt)

                _cnt = Layer.objects.filter(thumbnail_url__icontains=source_address).update(
                    thumbnail_url=Func(
                        F('thumbnail_url'),Value(source_address),Value(target_address),function='replace'))
                print("Updated %s Layers" % _cnt)

                _cnt = Style.objects.filter(sld_url__icontains=source_address).update(
                    sld_url=Func(
                        F('sld_url'),Value(source_address),Value(target_address),function='replace'))
                print("Updated %s Styles" % _cnt)

                _cnt = Link.objects.filter(url__icontains=source_address).update(
                    url=Func(
                        F('url'),Value(source_address),Value(target_address),function='replace'))
                print("Updated %s Links" % _cnt)

                _cnt = ResourceBase.objects.filter(thumbnail_url__icontains=source_address).update(
                    thumbnail_url=Func(
github MapStory / mapstory / mapstory / organizations / models.py View on Github external
is_active = models.BooleanField(default=True)
    created_at = models.DateTimeField(auto_now_add=True)
    last_updated = models.DateTimeField(auto_now=True)

    def __unicode__(self):
        return u'%s - %s' % (self.organization, self.user)

    class Meta:
        verbose_name_plural = 'Memberships'


class OrganizationLayer(models.Model):
    """Represents a Layer that is sponsored by an Organization"""
    membership = models.ForeignKey(OrganizationMembership)
    organization = models.ForeignKey(Organization)
    layer = models.ForeignKey(Layer)
    created_at = models.DateTimeField(auto_now_add=True)
    last_updated = models.DateTimeField(auto_now=True)
    is_featured = models.BooleanField(default=False)

    def __unicode__(self):
        return u'%s' % self.layer


class OrganizationMapStory(models.Model):
    """
    Represents a Mapstory that is sponsored by an Organization
    """
    mapstory = models.ForeignKey(MapStory)
    organization = models.ForeignKey(Organization)
    membership = models.ForeignKey(OrganizationMembership)
    created_at = models.DateTimeField(auto_now_add=True)
github MapStory / mapstory / mapstory / favorite / models.py View on Github external
def bulk_favorite_objects(self, user):
        'get the actual favorite objects for a user as a dict by content_type'
        favs = {}
        for m in (Document, Map, Layer, get_user_model()):
            ct = ContentType.objects.get_for_model(m)
            f = self.favorites_for_user(user).filter(content_type=ct)
            favs[ct.name] = m.objects.filter(id__in=f.values('object_id'))
        return favs
github GeoNode / geonode / geonode / services / serviceprocessors / arcgis.py View on Github external
"""Harvest a single resource from the service

        This method will try to create new ``geonode.layers.models.Layer``
        instance (and its related objects too).

        :arg resource_id: The resource's identifier
        :type resource_id: str
        :arg geonode_service: The already saved service instance
        :type geonode_service: geonode.services.models.Service

        """
        layer_meta = self.get_resource(resource_id)
        if layer_meta:
            resource_fields = self._get_indexed_layer_fields(layer_meta)
            keywords = resource_fields.pop("keywords")
            existance_test_qs = Layer.objects.filter(
                name=resource_fields["name"],
                store=resource_fields["store"],
                workspace=resource_fields["workspace"]
            )
            if existance_test_qs.exists():
                raise RuntimeError(
                    "Resource {!r} has already been harvested".format(resource_id))
            resource_fields["keywords"] = keywords
            resource_fields["is_approved"] = True
            resource_fields["is_published"] = True
            if settings.RESOURCE_PUBLISHING or settings.ADMIN_MODERATE_UPLOADS:
                resource_fields["is_approved"] = False
                resource_fields["is_published"] = False
            geonode_layer = self._create_layer(
                geonode_service, **resource_fields)
            # self._enrich_layer_metadata(geonode_layer)
github GeoNode / geonode / geonode / geoserver / views.py View on Github external
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:
        layer_obj = Layer.objects.get(id=layerid)
        cap_name += layer_obj.title
        layers = Layer.objects.filter(id=layerid)
    elif user is not None:
        layers = Layer.objects.filter(owner__username=user)
        cap_name += user
    elif category is not None:
        layers = Layer.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.layers:
            if layer.local:
                alternates.append(layer.name)
        layers = Layer.objects.filter(alternate__in=alternates)

    for layer in layers:
        if request.user.has_perm('view_resourcebase',
                                 layer.get_self_resource()):