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 index(self):
     """ GET /mapfiles: Get all mapfiles owned by the current user """
     maps = self._get_maps_from_user(c.user)
     serialized_maps = []
     for m in maps:
         serialized_maps.append({
             "id": m.id,
             "name": m.name,
             "href": h.url_for(controller="mapfiles", action="show", id=m.id),
             'wmsproxyurl':h.url_for(controller='mapfiles', action='wms_proxy', id=m.id),
             'wmsurl': "%s?%s" %(config['mapserver_url'], urlencode({'map':os.path.join(config['mapfiles_dir'], m.filepath)}))
         })
     # prevent JSON Array Cross-site Exploits (XSRF/CSRF)
     return {'maps': serialized_maps}
Exemple #3
0
 def index(self, format='html'):
     """GET /datastores: All items in the collection."""
     # url('datastores')
     results = meta.Session.query(DataStore)
     serialized_datastores = [{'id': ds.id, 'text': ds.name, 'href': h.url_for(controller="datastores", action="show", id=ds.id), 'type': ds.type} for ds in results]
     # prevent JSON Array Cross-site Exploits (XSRF/CSRF)
     return {'datastores': serialized_datastores}
Exemple #4
0
 def create(self):
     """POST /layertemplates: Create a new item."""
     # url('layertemplates')
     content = request.environ["wsgi.input"].read(int(request.environ["CONTENT_LENGTH"]))
     content = content.decode("utf8")
     content = simplejson.loads(content)
     lt = self._new_lt_from_user(content["name"], content["comment"], content["json"], c.user)
     response.status = 201
     href = h.url_for(controller="layertemplates", action="show", id=lt.id)
     return {"name": lt.name, "comment": lt.comment, "id": lt.id, "href": href}
Exemple #5
0
 def show(self, id):
     """ GET /mapfiles/id: Get a specific mapfile owned by the current user. """
     map = self._get_map_from_user_by_id(c.user, id)
     if map is None:
         abort(404)
     mapfile = Mapfile()
     mapfile.from_file(os.path.join(config['mapfiles_dir'], map.filepath))
     return {
         'map': mapfile.to_dict(),
         'wmsproxyurl': h.url_for(controller='mapfiles', action='wms_proxy', id=id),
         'wmsurl': "%s?%s" %(config['mapserver_url'], urlencode({'map':os.path.join(config['mapfiles_dir'], map.filepath)}))
     }
Exemple #6
0
 def index(self, datastore_id=None):
     """ GET /datastores/{datastore_id}/datasources: Get all
         datasources within a given datastore."""
     datastore = self._get_datastore_by_id(datastore_id)
     if datastore is None:
         abort(404)
     discovery_result = discover_datasources(datastore.ogrstring)
     for datasource in discovery_result:
         datasource['href'] = h.url_for(controller="datasources",
                                        action="show",
                                        datastore_id=datastore_id,
                                        datasource_id=datasource['id'])
     # prevent JSON Array Cross-site Exploits (XSRF/CSRF)
     return {'datasources': discovery_result}
Exemple #7
0
 def index(self):
     """ GET /mapfiles: Get all mapfiles owned by the current user """
     maps = self._get_maps_from_user(c.user)
     serialized_maps = []
     for m in maps:
         serialized_maps.append({
             "id":
             m.id,
             "name":
             m.name,
             "href":
             h.url_for(controller="mapfiles", action="show", id=m.id),
             'wmsproxyurl':
             h.url_for(controller='mapfiles', action='wms_proxy', id=m.id),
             'wmsurl':
             "%s?%s" %
             (config['mapserver_url'],
              urlencode(
                  {'map': os.path.join(config['mapfiles_dir'], m.filepath)
                   }))
         })
     # prevent JSON Array Cross-site Exploits (XSRF/CSRF)
     return {'maps': serialized_maps}
Exemple #8
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 #9
0
 def create(self):
     """POST /layertemplates: Create a new item."""
     # url('layertemplates')
     content = request.environ['wsgi.input'].read(
         int(request.environ['CONTENT_LENGTH']))
     content = content.decode('utf8')
     content = simplejson.loads(content)
     lt = self._new_lt_from_user(content['name'], content['comment'],
                                 content['json'], c.user)
     response.status = 201
     href = h.url_for(controller="layertemplates", action="show", id=lt.id)
     return {
         'name': lt.name,
         'comment': lt.comment,
         'id': lt.id,
         'href': href
     }
Exemple #10
0
 def index(self, format="html"):
     """GET /layertemplates: All items in the collection."""
     # url('layertemplates')
     lts = meta.Session.query(LayerTemplate)
     # use following query for getting layertemplates owned by current user
     # lts = self._get_lts_from_user(c.user)
     serialized_lts = []
     for lt in lts:
         serialized_lts.append(
             {
                 "id": lt.id,
                 "name": lt.name,
                 "comment": lt.comment,
                 "href": h.url_for(controller="layertemplates", action="show", id=lt.id),
             }
         )
     # prevent JSON Array Cross-site Exploits (XSRF/CSRF)
     return {"layertemplates": serialized_lts}
Exemple #11
0
 def show(self, id):
     """ GET /mapfiles/id: Get a specific mapfile owned by the current user. """
     map = self._get_map_from_user_by_id(c.user, id)
     if map is None:
         abort(404)
     mapfile = Mapfile()
     mapfile.from_file(os.path.join(config['mapfiles_dir'], map.filepath))
     return {
         'map':
         mapfile.to_dict(),
         'wmsproxyurl':
         h.url_for(controller='mapfiles', action='wms_proxy', id=id),
         'wmsurl':
         "%s?%s" %
         (config['mapserver_url'],
          urlencode(
              {'map': os.path.join(config['mapfiles_dir'], map.filepath)}))
     }
Exemple #12
0
 def index(self, format='html'):
     """GET /layertemplates: All items in the collection."""
     # url('layertemplates')
     lts = meta.Session.query(LayerTemplate)
     # use following query for getting layertemplates owned by current user
     #lts = self._get_lts_from_user(c.user)
     serialized_lts = []
     for lt in lts:
         serialized_lts.append({
             'id':
             lt.id,
             'name':
             lt.name,
             'comment':
             lt.comment,
             "href":
             h.url_for(controller="layertemplates", action="show", id=lt.id)
         })
     # prevent JSON Array Cross-site Exploits (XSRF/CSRF)
     return {'layertemplates': serialized_lts}