Esempio n. 1
0
File: app.py Progetto: MapofLife/MOL
    def get(self):
        
        from ndb import model, query
        from mol.db.layers import Layer, LayerIndex

        limit = self.request.get_range('limit', min_value=1, max_value=100, default=10)
        offset = self.request.get_range('offset', min_value=0, default=0)
        args = {}
        for arg in self.request.arguments():
            if arg in INDEXED_PROPS:
                if arg in POLYGON_PROPS:
                    args['polygon.%s' % arg] = self.request.get(arg, None)
                else:
                    args[arg] = self.request.get(arg, None)
            
        qry = LayerIndex.query()
        if len(args) > 0:
            gql = 'SELECT * FROM LayerIndex WHERE'
            for k,v in args.iteritems():
                gql = "%s \"%s\" = '%s' AND " % (gql, k, v)
            gql = gql[:-5] # Removes trailing AND
            logging.info(gql)
            qry = query.parse_gql(gql)[0]
        # No keyword search yet
        #for keyword in keywords:
        #    qry = qry.filter(RecordIndex.corpus == keyword)        
        logging.info('QUERY='+str(qry))
        layers = model.get_multi(set([x.parent() for x in qry.fetch(limit, offset=offset, keys_only=True)]))
        layers_json = [simplejson.loads(x.json) for x in layers]
        self.response.headers["Content-Type"] = "application/json"
        self.response.out.write(simplejson.dumps(layers_json))
Esempio n. 2
0
File: app.py Progetto: MapofLife/MOL
    def get(self):
        
        from ndb import model, query
        from mol.db.layers import Layer, LayerIndex

        limit = self.request.get_range('limit', min_value=1, max_value=100, default=10)
        offset = self.request.get_range('offset', min_value=0, default=0)
        args = {}
        for arg in self.request.arguments():
            if arg in POLYGON_PROPS:
                args['polygon.%s' % arg] = self.request.get(arg, None)
            
        qry = LayerIndex.query()
        if len(args) > 0:
            gql = 'SELECT * FROM LayerIndex WHERE'
            for k,v in args.iteritems():
                gql = "%s \"%s\" = '%s' AND " % (gql, k, v)
            gql = gql[:-5] # Removes trailing AND
            logging.info(gql)
            qry = query.parse_gql(gql)[0]
        logging.info('QUERY='+str(qry))
        polygons = []
        for x in qry.fetch(limit, offset=offset): #[simplejson.loads(x.json) for x in qry.fetch(limit, offset=offset)]
            p = simplejson.loads(x.json)
            p['layer_index_key'] = str(x.key.id())
            p['layer_key'] = str(x.key.parent().id())
            polygons.append(p)
        self.response.headers["Content-Type"] = "application/json"
        self.response.out.write(simplejson.dumps(polygons))
Esempio n. 3
0
File: app.py Progetto: MapofLife/MOL
 def get(self):
     # Contact.query(Contact.address == Address(city='San Francisco', street='Spear St'))
     from ndb import model
     from mol.db.layers import LayerIndex, LayerPolygon
     s = self.request.get('s')
     p = self.request.get('p')
     a = self.request.get('a')
     r = self.request.get('r')
     #qry = LayerIndex.query(LayerIndex.polygons.specieslatin == 'dry chaco',
     #                       LayerIndex.polygons.polygonid == '2')
     qry = LayerIndex.query(LayerIndex.polygons == LayerPolygon(
             specieslatin='815.02300000000',
             polygonid='14730',
             source='4936.88958455000',
             areaid='9111848.92186000012'))
     #qry = LayerIndex.query(LayerIndex.creator == 'Walter')
     json = simplejson.dumps([simplejson.loads(x.parent().get().json) for x in qry.fetch(keys_only=True)])
     self.response.headers["Content-Type"] = "application/json"
     self.response.out.write(json)