Exemple #1
0
    def create(self):
        """POST /mapfiles: Create a new item."""
        # get json content from POST request
        content = request.environ['wsgi.input'].read(int(request.environ['CONTENT_LENGTH']))
        #content = content.decode('utf8')   mapfile interface don't like unicode strings... bad...

        # load mapfile
        mapfile = Mapfile()
        dict = simplejson.loads(content)
        mapfile.from_dict(dict)

        # create mapfile
        mapname = mapfile.get_name()
        map_pathname = h.gen_mapname()
        mapfile.to_file(os.path.join(config['mapfiles_dir'], map_pathname))

        # create map in db
        map = self._new_map_from_user(c.user, mapname, map_pathname)

        response.status = 201

        href = h.url_for(controller="mapfiles", action="show", id=map.id)
        wmsproxyurl = h.url_for(controller='mapfiles', action='wms_proxy', id=map.id)
        wmsurl = "%s?%s" %(config['mapserver_url'], urlencode({'map':os.path.join(config['mapfiles_dir'], map.filepath)}))
        return {'name': map.name, 'id': map.id, 'href': href, 'wmsurl': wmsurl, 'wmsproxyurl': wmsproxyurl}
Exemple #2
0
def create_mapfile(mapfile_name, pathname, user_id=2):
    # copy test mapfile dummy_mapfile.map and change fontset and symbolset paths
    # so that it matches user environnement
    mapfile = Mapfile()
    mapfile.from_file(os.path.join(config['mapserver_dir'], 'dummy_mapfile.map'))
    mapfile.set_name(mapfile_name)
    mapfile = change_mapfile_paths(mapfile)
    mapfile.to_file(os.path.join(config['mapfiles_dir'], pathname))
    assert os.path.exists(os.path.join(config['mapfiles_dir'], pathname))
    # db insertion of new mapfile
    map = Map(mapfile_name, pathname, user_id)
    meta.Session.add(map)
    meta.Session.commit()
    return map
Exemple #3
0
    def update(self, id):
        """PUT /mapfiles/id: Update an existing item."""
        map = self._get_map_from_user_by_id(c.user, id)
        if map is None:
            abort(404)

        # get json content from PUT request
        content = request.environ['wsgi.input'].read(int(request.environ['CONTENT_LENGTH']))
        #content = content.decode('utf8')

        # update mapfile
        mapfile = Mapfile()
        dict = simplejson.loads(content)
        mapfile.from_dict(dict)
        mapfile.to_file(os.path.join(config['mapfiles_dir'], map.filepath))
        if mapfile.get_name() != map.name:
            self._update_map(map, name=mapfile.get_name())

        response.status = 201
        return
Exemple #4
0
    def update(self, id):
        """PUT /mapfiles/id: Update an existing item."""
        map = self._get_map_from_user_by_id(c.user, id)
        if map is None:
            abort(404)

        # get json content from PUT request
        content = request.environ['wsgi.input'].read(
            int(request.environ['CONTENT_LENGTH']))
        #content = content.decode('utf8')

        # update mapfile
        mapfile = Mapfile()
        dict = simplejson.loads(content)
        mapfile.from_dict(dict)
        mapfile.to_file(os.path.join(config['mapfiles_dir'], map.filepath))
        if mapfile.get_name() != map.name:
            self._update_map(map, name=mapfile.get_name())

        response.status = 201
        return
Exemple #5
0
    def create(self):
        """POST /mapfiles: Create a new item."""
        # get json content from POST request
        content = request.environ['wsgi.input'].read(
            int(request.environ['CONTENT_LENGTH']))
        #content = content.decode('utf8')   mapfile interface don't like unicode strings... bad...

        # load mapfile
        mapfile = Mapfile()
        dict = simplejson.loads(content)
        mapfile.from_dict(dict)

        # create mapfile
        mapname = mapfile.get_name()
        map_pathname = h.gen_mapname()
        mapfile.to_file(os.path.join(config['mapfiles_dir'], map_pathname))

        # create map in db
        map = self._new_map_from_user(c.user, mapname, map_pathname)

        response.status = 201

        href = h.url_for(controller="mapfiles", action="show", id=map.id)
        wmsproxyurl = h.url_for(controller='mapfiles',
                                action='wms_proxy',
                                id=map.id)
        wmsurl = "%s?%s" % (
            config['mapserver_url'],
            urlencode(
                {'map': os.path.join(config['mapfiles_dir'], map.filepath)}))
        return {
            'name': map.name,
            'id': map.id,
            'href': href,
            'wmsurl': wmsurl,
            'wmsproxyurl': wmsproxyurl
        }