2016-01-22 69 views
0

我有一個工作Flask API,現在我想實現搜索查詢。 我的理解是,過濾器應用於客戶端,Flask API負責處理它。燒瓶搜索查詢不使用過濾器

Flask==0.10.1 
Flask-HTTPAuth==2.7.0 
Flask-Limiter==0.9.1 
Flask-Login==0.3.2 
Flask-Mail==0.9.1 
Flask-Principal==0.4.0 
Flask-Restless==0.17.0 

我按照文檔和執行我的搜索查詢,但仍然只是獲取相同的結果:

http://flask-restless.readthedocs.org/en/latest/searchformat.html

無過濾器:

curl -u aaa:bbb -H "Content-Type: application/json" http://0.0.0.0:8080/api/1.0/job/ 

{ 
    "jobs": [ 
    { 
     "description": "ESXi job completed", 
     "reference": "07FC78BCC0", 
     "status": 1 
    }, 
    { 
     "description": "Server discovery failed. Please verify HTTPS/SSH parameters", 
     "reference": "A6EE28F4C0", 
     "status": -1 
    }] 
} 

搜索查詢的基礎上: http://flask-restless.readthedocs.org/en/latest/searchformat.html

curl -u aaa:bbb -G -H "Content-Type: application/json" -d '{ 
> "filters": [{"name": "description", "op": "like", "val": "%ESXi%"}]}' http://0.0.0.0:8080/api/1.0/job/ 

或者

curl -u aaa:bbb -G -H "Content-Type: application/json" -d '{"filters": [{"name": "status", "op": "eq", "val":0}]}' http://0.0.0.0:8080/api/1.0/job/ 

而且相同的結果顯示。

這是我的瓶端點:

def get_jobs(): 
    """ 

    :return: 
    """ 
    try: 
     log.info(request.remote_addr + ' ' + request.__repr__()) 
     jobs = Model.Job.query.order_by(desc(Model.Job.job_start)).limit(settings.items_per_page).all() 

     # ========================================================= 
     # Get JOBS 
     # ========================================================= 

     values = ['description', 'status', 'reference'] 
     response = [{value: getattr(d, value) for value in values} for d in jobs] 
     return jsonify(jobs=response) 


    except Exception, excpt: 
     log.exception(excpt.__repr__()) 
     response = json.dumps('Internal Server Error. Please try again later') 
     resp = Response(response, status=500, mimetype='application/json') 
     return resp 

我的模型

class Job(db.Model, AutoSerialize, Serializer): 
    """ 

    """ 
    __tablename__ = 'job' 
    __public__ = ('status','description','reference','job_start','job_end') 
    id = Column(Integer, primary_key=True, server_default=text("nextval('job_id_seq'::regclass)")) 
    description = Column(String(200)) 
    reference = Column(String(50)) 
    job_start = Column(DateTime) 
    job_end = Column(DateTime) 
    fk_server = Column(ForeignKey(u'server.id')) 
    owner_id = Column(ForeignKey(u'auth_user.id')) 
    is_cluster = Column(Boolean) 
    host_information = Column(String(1024)) 
    status = Column(Integer, nullable=False) 
    owner = relationship(u'AuthUser') 
    server = relationship(u'Server') 

    def serialize(self): 
     """ 

     :return: 
     """ 

     d = Serializer.serialize(self) 
     return d 

我需要改變什麼?

+0

您可以顯示您是如何使用Flask-Restless管理器聲明路線的。 – pjcunningham

回答