How to use the geonode.maps.models.Map.objects.get 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 / maps / tests_populate_maplayers.py View on Github external
if 'geonode.geoserver' in settings.INSTALLED_APPS:
        from django.db.models import signals
        from geonode.geoserver.signals import geoserver_pre_save_maplayer
        from geonode.geoserver.signals import geoserver_post_save_map
        signals.pre_save.disconnect(
            geoserver_pre_save_maplayer,
            sender=MapLayer)
        signals.post_save.disconnect(geoserver_post_save_map, sender=Map)

    for ml in maplayers:
        MapLayer.objects.create(
            fixed=ml['fixed'],
            group=ml['group'],
            name=ml['name'],
            layer_params=ml['layer_params'],
            map=Map.objects.get(title=ml['map']),
            source_params=ml['source_params'],
            stack_order=ml['stack_order'],
            opacity=ml['opacity'],
            transparent=ml['stack_order'],
            visibility=ml['stack_order'],
        )
github GeoNode / geonode / geonode / maps / tests.py View on Github external
def test_map_fetch(self):
        """/maps/[id]/data -> Test fetching a map in JSON"""
        map_obj = Map.objects.get(id=1)
        map_obj.set_default_permissions()
        response = self.client.get(reverse('map_json', args=(map_obj.id,)))
        self.assertEquals(response.status_code, 200)
        cfg = json.loads(response.content)
        self.assertEquals(
            cfg["about"]["abstract"],
            'GeoNode default map abstract')
        self.assertEquals(cfg["about"]["title"], 'GeoNode Default Map')
        self.assertEquals(len(cfg["map"]["layers"]), 5)
github GeoNode / geonode / geonode / maps / tests.py View on Github external
def test_map_to_json(self):
        """ Make some assertions about the data structure produced for serialization
            to a JSON map configuration"""
        map_obj = Map.objects.get(id=1)
        cfg = map_obj.viewer_json(None, None)
        self.assertEquals(
            cfg['about']['abstract'],
            'GeoNode default map abstract')
        self.assertEquals(cfg['about']['title'], 'GeoNode Default Map')

        def is_wms_layer(x):
            if 'source' in x:
                return cfg['sources'][x['source']]['ptype'] == 'gxp_wmscsource'
            return False
        layernames = [x['name']
                      for x in cfg['map']['layers'] if is_wms_layer(x)]
        self.assertEquals(layernames, ['geonode:CA', ])
github GeoNode / geonode / geonode / maps / tests.py View on Github external
self.client.login(username='admin', password='admin')

        try:
            response = self.client.post(url, {'layer': layer_name})
            # Should not accept the request
            self.assertEqual(response.status_code, 400)

            # Test POST method with map data in json format
            response = self.client.post(
                url,
                data=self.viewer_config,
                content_type="text/json")
            self.assertEqual(response.status_code, 200)
            map_id = int(json.loads(response.content)['id'])
            # Check new map saved
            map_obj = Map.objects.get(id=map_id)
            # Check
            # BBox format: [xmin, xmax, ymin, ymax
            bbox_str = [
                '-90.193207913954200', '-79.206792062465500',
                '9.059219904470890', '16.540780092025600', 'EPSG:4326']

            self.assertEqual(
                bbox_str,
                [str(c) for c in map_obj.bbox])
            bbox_long_str = '-90.193207913954200,9.059219904470890,' \
                            '-79.206792062465500,16.540780092025600'
            self.assertEqual(bbox_long_str, map_obj.bbox_string)

            # Test methods other than GET or POST and no layer in params
            response = self.client.put(url)
            self.assertEqual(response.status_code, 405)
github cholmes / mapstory / tests.py View on Github external
bobby_layer = Layer.objects.create(owner=self.bobby, name='layer2', typename='layer2')
        # no activity yet, still Private
        self.assertFalse(self.bobby.actor_actions.all())
        
        # lets publish it
        bobby_layer.publish.status = 'Public'
        bobby_layer.publish.save()
        actions = self.bobby.actor_actions.all()
        # there should be a single action
        self.assertEqual(1, len(actions))
        self.assertEqual('bobby published layer2 Layer 0 minutes ago', str(actions[0]))
        
        # now create a map
        admin_map = Map.objects.create(owner=self.admin, zoom=1, center_x=0, center_y=0, title='map1')
        # have to use a 'dummy' map to create the appropriate JSON
        dummy = Map.objects.get(id=admin_map.id)
        dummy.id += 1
        dummy.save()
        MapLayer.objects.create(name = 'layer1', ows_url='layer1', map=dummy, stack_order=1)
        # and 'add' the layer
        admin_map.update_from_viewer(dummy.viewer_json())
        # no activity yet, still Private
        self.assertFalse(self.admin.actor_actions.all())
        
        # lets publish it and ensure things work
        self.bobby.useractivity.other_actor_actions.clear()
        admin_map.publish.status = 'Public'
        admin_map.publish.save()
        # there should be a single 'public' action (the other exists so it can hang on bobby)
        actions = self.admin.actor_actions.public()
        self.assertEqual(1, len(actions))
        self.assertEqual('admin published map1 by admin 0 minutes ago', str(actions[0]))
github GeoNode / geonode / geonode / maps / tests.py View on Github external
def test_fix_baselayers(self):
        """Test fix_baselayers function, used by the fix_baselayers command
        """
        map_id = 1
        map_obj = Map.objects.get(id=map_id)

        # number of base layers (we remove the local geoserver entry from the total)
        n_baselayers = len(settings.MAP_BASELAYERS) - 1

        # number of local layers
        n_locallayers = map_obj.layer_set.filter(local=True).count()

        fix_baselayers(map_id)

        self.assertEquals(map_obj.layer_set.all().count(), n_baselayers + n_locallayers)
github GeoNode / geonode / geonode / maps / tests.py View on Github external
self.client.logout()

        url = reverse('map_embed', args=(map_id,))
        url_no_id = reverse('map_embed')

        # Now test with a map id
        self.client.login(username=self.user, password=self.passwd)
        response = self.client.get(url)
        self.assertEqual(response.status_code, 200)

        # The embedded map is exempt from X-FRAME-OPTIONS restrictions.
        if hasattr(response, 'xframe_options_exempt'):
            self.assertTrue(response.xframe_options_exempt)

        # Config equals to that of the map whose id is given
        map_obj = Map.objects.get(id=map_id)
        config_map = map_obj.viewer_json(None)
        response_config_dict = json.loads(response.context['config'])
        self.assertEqual(
            config_map['about']['abstract'],
            response_config_dict['about']['abstract'])
        self.assertEqual(
            config_map['about']['title'],
            response_config_dict['about']['title'])

        # Now test without a map id
        response = self.client.get(url_no_id)
        self.assertEqual(response.status_code, 200)
        # Config equals to that of the default map
        config_default = default_map_config(None)[0]
        response_config_dict = json.loads(response.context['config'])
        self.assertEqual(
github cga-harvard / worldmap / worldmap / certification / tests.py View on Github external
def test_certify_map(self):
        """
        Tests creation, removal, and retrieval of map certifications
        """
        user_obj = User.objects.get(id=1)
        map_obj = Map.objects.get(id=1)
        obj_type = ContentType.objects.get_for_model(map_obj)
        newcert = Certification.objects.certify(user_obj,map_obj)

        # Verify that the certification is for the correct model type (map)
        self.assertEquals(obj_type, newcert.object_ct)

        # Verify that the certification is for the correct map id
        self.assertEquals(map_obj.id, newcert.object_id)

        # Verify that there is only 1 certification for this map
        self.assertEquals(1, len(Certification.objects.filter(object_ct=obj_type, object_id=map_obj.id)))

        #Verify that the is_certified methods returns true for this map & user
        self.assertTrue(Certification.objects.is_certified(user_obj,map_obj))

        #Verify that the certifications_object methods returns 1 cert. for this map
github GeoNode / geonode / geonode / maps / qgis_server_views.py View on Github external
def get_object(self):
        return Map.objects.get(id=self.kwargs.get("mapid"))
github GeoNode / geonode / src / geonode / maps / views.py View on Github external
def view_js(request, mapid):
    map = Map.objects.get(pk=mapid)
    config = build_map_config(map)
    return HttpResponse(json.dumps(config), mimetype="application/javascript")