Beispiel #1
0
def create_test_map():
    if not Map.objects.filter(title='GeoNode Default Map').exists():
        if not TopicCategory.objects.filter(identifier='biota').exists():
            TopicCategory.objects.create(identifier='biota')

        signals.pre_save.disconnect(geoserver_pre_save_maplayer, sender=MapLayer)
        signals.post_save.disconnect(geoserver_post_save_map, sender=Map)
        signals.pre_save.disconnect(geoserver_pre_save, sender=Layer)
        signals.post_save.disconnect(geoserver_post_save, sender=Layer)

        world_extent = [-180, 180, -90, 90]
        biota = TopicCategory.objects.get(identifier='biota')

        map_data = [('GeoNode Default Map', 'GeoNode default map abstract', ('populartag',), world_extent, biota)]
        test_user = get_test_user()

        for md in map_data:
            title, abstract, kws, (bbox_x0, bbox_x1, bbox_y0, bbox_y1), category = md
            m = Map(title=title,
                    abstract=abstract,
                    zoom=4,
                    projection='EPSG:4326',
                    center_x=42,
                    center_y=-73,
                    owner=test_user,
                    bbox_x0=bbox_x0,
                    bbox_x1=bbox_x1,
                    bbox_y0=bbox_y0,
                    bbox_y1=bbox_y1,
                    category=category,
                    )
            m.save()
Beispiel #2
0
def create_test_map():
    if not Map.objects.filter(title='GeoNode Default Map').exists():
        if not TopicCategory.objects.filter(identifier='biota').exists():
            TopicCategory.objects.create(identifier='biota')

        signals.pre_save.disconnect(geoserver_pre_save_maplayer,
                                    sender=MapLayer)
        signals.post_save.disconnect(geoserver_post_save_map, sender=Map)
        signals.pre_save.disconnect(geoserver_pre_save, sender=Layer)
        signals.post_save.disconnect(geoserver_post_save, sender=Layer)

        world_extent = [-180, 180, -90, 90]
        biota = TopicCategory.objects.get(identifier='biota')

        map_data = [('GeoNode Default Map', 'GeoNode default map abstract',
                     ('populartag', ), world_extent, biota)]
        test_user = get_test_user()

        for md in map_data:
            title, abstract, kws, (bbox_x0, bbox_x1, bbox_y0,
                                   bbox_y1), category = md
            m = Map(
                title=title,
                abstract=abstract,
                zoom=4,
                projection='EPSG:4326',
                center_x=42,
                center_y=-73,
                owner=test_user,
                bbox_x0=bbox_x0,
                bbox_x1=bbox_x1,
                bbox_y0=bbox_y0,
                bbox_y1=bbox_y1,
                category=category,
            )
            m.save()
Beispiel #3
0
 def test_create_new_map(self):
     test_map = Map()
     self.assertIsInstance(test_map, Map)
    def add_mapstory(self):
        mapstory = MapStory()
        mapstory.name = "test_case1"
        mapstory.owner = self.admin_user
        mapstory.uuid = str(uuid.uuid1())
        mapstory.save()

        map = Map()
        map.story = mapstory
        map.chapter_index = 0
        map.title = "test_case"
        map.projection = 'EPSG:4326'
        map.owner = mapstory.owner
        map.uuid = str(uuid.uuid1())
        map.zoom = 4
        map.center_x = 0
        map.center_y = 0
        map.save()

        mapstory.chapter_list.add(map)
        mapstory.save()

        # background
        maplayer_background = MapLayer()
        maplayer_background.map = map
        maplayer_background.name = "control-room"
        maplayer_background.stack_order = 4
        maplayer_background.opacity = 1.0
        maplayer_background.fixed = False
        maplayer_background.visibility = True
        maplayer_background.source_params = u'{"hidden": true, "ptype": "gxp_mapboxsource"}'
        maplayer_background.layer_config = ""
        maplayer_background.group = "background"
        maplayer_background.save()

        # map.layers.add(maplayer)

        map.save()
        return mapstory
    def add_mapstory(self):
        mapstory = MapStory()
        mapstory.name = "test_case1"
        mapstory.owner = self.admin_user
        mapstory.uuid = str(uuid.uuid1())
        mapstory.save()

        map = Map()
        map.story = mapstory
        map.chapter_index = 0
        map.title = "test_case"
        map.projection = 'EPSG:4326'
        map.owner = mapstory.owner
        map.uuid = str(uuid.uuid1())
        map.zoom = 4
        map.center_x = 0
        map.center_y = 0
        map.set_bounds_from_center_and_zoom(
            map.center_x,
            map.center_y,
            map.zoom)
        map.save()

        mapstory.chapter_list.add(map)
        mapstory.save()

        # background
        maplayer_background = MapLayer()
        maplayer_background.map = map
        maplayer_background.name = "control-room"
        maplayer_background.stack_order = 4
        maplayer_background.opacity = 1.0
        maplayer_background.fixed = False
        maplayer_background.visibility = True
        maplayer_background.source_params = u'{"hidden": true, "ptype": "gxp_mapboxsource"}'
        maplayer_background.layer_config = ""
        maplayer_background.group = "background"
        maplayer_background.save()

        # map.layers.add(maplayer)

        map.save()
        return mapstory
def create_models(type=None, user=None):
    from django.contrib.auth.models import Group
    map_data, user_data, people_data, layer_data, document_data = create_fixtures()
    anonymous_group, created = Group.objects.get_or_create(name='anonymous')

    u = None
    if not user:
        u, _ = get_user_model().objects.get_or_create(username='******', is_superuser=True, first_name='admin')
        u.set_password('admin')
        u.save()
    else:
        u = user

    users = []

    for ud, pd in zip(user_data, cycle(people_data)):
        user_name, password, first_name, last_name = ud
        u, created = get_user_model().objects.get_or_create(username=user_name)
        if created:
            u.first_name = first_name
            u.last_name = last_name
            u.save()
        u.groups.add(anonymous_group)
        users.append(u)

    get_user_model().objects.get(username='******').groups.add(anonymous_group)

    if not type or type == 'map':
        for md, user in zip(map_data, cycle(users)):
            title, abstract, kws, (bbox_x0, bbox_x1, bbox_y0, bbox_y1), category = md
            m = Map(title=title,
                    abstract=abstract,
                    zoom=4,
                    projection='EPSG:4326',
                    center_x=42,
                    center_y=-73,
                    owner=user,
                    bbox_x0=bbox_x0,
                    bbox_x1=bbox_x1,
                    bbox_y0=bbox_y0,
                    bbox_y1=bbox_y1,
                    category=category,
                    )
            m.save()
            for kw in kws:
                m.keywords.add(kw)
                m.save()

    if not type or type == 'document':
        for dd, user in zip(document_data, cycle(users)):
            title, abstract, kws, (bbox_x0, bbox_x1, bbox_y0, bbox_y1), category = dd
            m = Document(title=title,
                         abstract=abstract,
                         owner=user,
                         bbox_x0=bbox_x0,
                         bbox_x1=bbox_x1,
                         bbox_y0=bbox_y0,
                         bbox_y1=bbox_y1,
                         category=category,
                         doc_file=f)
            m.save()
            for kw in kws:
                m.keywords.add(kw)
                m.save()

    if not type or type == 'layer':
        for ld, owner, storeType in zip(layer_data, cycle(users), cycle(('coverageStore', 'dataStore'))):
            title, abstract, name, typename, (bbox_x0, bbox_x1, bbox_y0, bbox_y1), dt, kws, category = ld
            year, month, day = map(int, (dt[:4], dt[4:6], dt[6:]))
            start = datetime(year, month, day)
            end = start + timedelta(days=365)
            l = Layer(title=title,
                      abstract=abstract,
                      name=name,
                      typename=typename,
                      bbox_x0=bbox_x0,
                      bbox_x1=bbox_x1,
                      bbox_y0=bbox_y0,
                      bbox_y1=bbox_y1,
                      uuid=str(uuid4()),
                      owner=owner,
                      temporal_extent_start=start,
                      temporal_extent_end=end,
                      date=start,
                      storeType=storeType,
                      category=category,
                      )
            l.save()
            for kw in kws:
                l.keywords.add(kw)
                l.save()