How to use the geonode.layers.models.Layer.objects.all 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 / geoserver / tests.py View on Github external
def test_feature_edit_check(self):
        """Verify that the feature_edit_check view is behaving as expected
        """

        # Setup some layer names to work with
        layer = Layer.objects.all()[0]
        valid_layer_typename = layer.alternate
        layer.set_default_permissions()
        invalid_layer_typename = "n0ch@nc3"

        # Test that an invalid layer.typename is handled for properly
        response = self.client.post(
            reverse(
                'feature_edit_check',
                args=(
                    invalid_layer_typename,
                )))
        self.assertEquals(response.status_code, 200)
        response_json = json.loads(response.content)
        self.assertEquals(response_json['authorized'], False)

        # First test un-authenticated
github GeoNode / geonode / geonode / monitoring / tests.py View on Github external
def test_gn_error(self):
        """
        Test if we get geonode errors logged
        """
        Layer.objects.all().first()
        self.client.login(username=self.user, password=self.passwd)
        self.client.get(
            reverse('layer_detail', args=('nonex',)), **{"HTTP_USER_AGENT": self.ua})

        RequestEvent.objects.get()
        self.assertEqual(RequestEvent.objects.all().count(), 1)

        self.assertEqual(ExceptionEvent.objects.all().count(), 1)
        eq = ExceptionEvent.objects.get()
        self.assertEqual('django.http.response.Http404', eq.error_type)
github GeoNode / geonode / geonode / api / tests.py View on Github external
password='pbkdf2_sha256$12000$UE4gAxckVj4Z$N\
            6NbOXIQWWblfInIoq/Ta34FdRiPhawCIZ+sOO3YQs=')
        self.api_client.client.login(username='imnew', password='thepwd')
        resp = self.api_client.get(self.list_url)
        self.assertValidJSONResponse(resp)
        self.assertEqual(len(self.deserialize(resp)['objects']), 8)

        # with delayed security
        if check_ogc_backend(geoserver.BACKEND_PACKAGE):
            _ogc_geofence_enabled = settings.OGC_SERVER
            try:
                _ogc_geofence_enabled['default']['GEOFENCE_SECURITY_ENABLED'] = True
                with self.settings(DELAYED_SECURITY_SIGNALS=True,
                                   OGC_SERVER=_ogc_geofence_enabled,
                                   DEFAULT_ANONYMOUS_VIEW_PERMISSION=True):
                    layer = Layer.objects.all()[0]
                    layer.set_default_permissions()
                    layer.refresh_from_db()
                    self.assertTrue(layer.dirty_state)

                    self.client.login(username=self.user, password=self.passwd)
                    resp = self.client.get(self.list_url)
                    self.assertEqual(len(self.deserialize(resp)['objects']), 8)

                    self.client.logout()
                    resp = self.client.get(self.list_url)
                    self.assertEqual(len(self.deserialize(resp)['objects']), 7)

                    self.client.login(username='imnew', password='thepwd')
                    resp = self.client.get(self.list_url)
                    self.assertEqual(len(self.deserialize(resp)['objects']), 7)
            finally:
github GeoNode / geonode / geonode / base / populate_test_data.py View on Github external
if not type:
        remove_models(None, type='map')
        remove_models(None, type='layer')
        remove_models(None, type='document')

    if type == 'map':
        try:
            m_ids = obj_ids or [m.id for m in Map.objects.all()]
            for id in m_ids:
                m = Map.objects.get(pk=id)
                m.delete()
        except BaseException:
            pass
    elif type == 'layer':
        try:
            l_ids = obj_ids or [l.id for l in Layer.objects.all()]
            for id in l_ids:
                layer = Layer.objects.get(pk=id)
                layer.delete()
        except BaseException:
            pass
    elif type == 'document':
        try:
            d_ids = obj_ids or [d.id for d in Document.objects.all()]
            for id in d_ids:
                d = Document.objects.get(pk=id)
                d.delete()
        except BaseException:
            pass
github GeoNode / geonode / geonode / search / tests.py View on Github external
def test_bbox_result(self):
        # grab one and set the bounds
        lyr = Layer.objects.all()[0]
        lyr.bbox_x0 = -100
        lyr.bbox_x1 = -90
        lyr.bbox_y0 = 38
        lyr.bbox_y1 = 40
        lyr.save()
        
        response = json.loads(self.request(lyr.title,type='layer').content)
        self.assertEquals({u'minx': u'-100', u'miny': u'38', u'maxx': u'-90', u'maxy': u'40'},
                          response['results'][0]['bbox'])
github GeoNode / geonode / geonode / api / tests.py View on Github external
def test_layer_get_list_layer_private_to_one_user(self):
        """
        Test that if a layer is only visible by admin, then does not appear
        in the unauthenticated list nor in the list when logged is as bobby
        """
        perm_spec = {"users": {"admin": ['view_resourcebase']}, "groups": {}}
        layer = Layer.objects.all()[0]
        layer.set_permissions(perm_spec)
        resp = self.api_client.get(self.list_url)
        self.assertEqual(len(self.deserialize(resp)['objects']), 7)

        self.api_client.client.login(username='bobby', password='bob')
        resp = self.api_client.get(self.list_url)
        self.assertEqual(len(self.deserialize(resp)['objects']), 8)

        self.api_client.client.login(username=self.user, password=self.passwd)
        resp = self.api_client.get(self.list_url)
        self.assertEqual(len(self.deserialize(resp)['objects']), 8)

        layer.is_published = False
        layer.save()

        # with resource publishing
github GeoNode / geonode / geonode / layers / utils.py View on Github external
def set_layers_permissions(permissions_name, resources_names=None,
                           users_usernames=None, groups_names=None, delete_flag=None):
    # Processing information
    if not resources_names:
        # If resources is None we consider all the existing layer
        resources = Layer.objects.all()
    else:
        try:
            resources = Layer.objects.filter(Q(title__in=resources_names) | Q(name__in=resources_names))
        except Layer.DoesNotExist:
            logger.warning(
                'No resources have been found with these names: %s.' % (
                    ", ".join(resources_names)
                )
            )
    if not resources:
        logger.warning("No resources have been found. No update operations have been executed.")
    else:
        # PERMISSIONS
        if not permissions_name:
            logger.error("No permissions have been provided.")
        else:
github GeoNode / geonode / geonode / contrib / geosites / integration.py View on Github external
def test_getcapabilities_filters_by_site(self):
        thefile1 = os.path.join(
            gisdata.VECTOR_DATA,
            'san_andres_y_providencia_poi.shp')
        thefile2 = os.path.join(
            gisdata.VECTOR_DATA,
            'san_andres_y_providencia_administrative.shp')
        file_upload(thefile1, overwrite=True)
        file_upload(thefile2, overwrite=True)

        # remove one layer from the site resources
        SiteResources.objects.get(site=self.slave_site).resources.remove(Layer.objects.all()[0])

        self.assertEqual(SiteResources.objects.get(site=self.slave_site).resources.count(), 1)

        self.client.login(username='bobby', password='bob')
        resp = self.client.get(self.getcaps_url)
        xml = minidom.parseString(resp.content)
        getcaps_layer = xml.getElementsByTagName('Layer')[0]
        self.assertEqual(len(getcaps_layer.getElementsByTagName('Layer')), 1)
github GeoNode / geonode / geonode / documents / forms.py View on Github external
def generate_link_choices(self, resources=None):

        if resources is None:
            resources = list(Layer.objects.all())
            resources += list(Map.objects.all())
            resources.sort(key=lambda x: x.title)

        choices = []
        for obj in resources:
            type_id = ContentType.objects.get_for_model(obj.__class__).id
            choices.append([
                "type:%s-id:%s" % (type_id, obj.id),
                '%s (%s)' % (obj.title, obj.polymorphic_ctype.model)
            ])

        return choices
github SP7-Ritmare / starterkit / geosk / mdtools / forms.py View on Github external
from django import forms
from geonode.layers.models import Layer

class UploadMetadataFileForm(forms.Form):
    layer = forms.ModelChoiceField(queryset=Layer.objects.all(), label="Layer name")
    file  = forms.FileField()