예제 #1
0
async def search(request):
    '''
    url http://localhost:5000/v1/book/search?q={}
    '''
    form = BookSearchForm(data=request.raw_args)
    if BookSearchForm(data=request.raw_args).validate():
        book=Book(request)
        q=form.q.data
        result=await book.search_by_title_or_publisher(q)
        if result:
            resp={"result":result,"flag": 1}         #返回值拼接成json格式
            return json(resp)
        return NotFound(request)
    return ParameterException(request)
예제 #2
0
def search():
    form = BookSearchForm().validate_for_api()
    q = '%' + form.q.data + '%'
    books = Book.query.filter(or_(Book.title.like(q),
                                  Book.publisher.like(q))).all()
    books = [book.hide('summary').append('page') for book in books]
    return jsonify(books)
예제 #3
0
def search():
    # url = http://localhost:5000/v1/book/search?q={}
    form = BookSearchForm().validate_for_api()
    q = "%" + form.q.data + "%"
    books = Book.query.filter(or_(Book.title.like(q), Book.publisher.like(q))).all()
    books = [book.hide("summary") for book in books]
    return jsonify(books)
예제 #4
0
파일: book.py 프로젝트: wlf36/lin-cms-flask
def search():
    form = BookSearchForm().validate_for_api()
    q = '%' + form.q.data + '%'
    books = Book.query.filter(Book.title.like(q)).all()
    if books is None or len(books) < 1:
        raise BookNotFound()
    return jsonify(books)
예제 #5
0
def search():
    form = BookSearchForm().validate_for_api()
    # 用like模式, 查询关键词前后加%号
    q = '%' + form.q.data + '%'
    books = Book.query.filter(or_(Book.title.like(q),
                                  Book.publisher.like(q))).all()
    books = [book.hide('summary', 'id') for book in books]
    return jsonify(books)
예제 #6
0
파일: book.py 프로젝트: junxian123/yushu
def search():
    form = BookSearchForm().validate_for_api()
    q = form.q.data
    if is_isbn_or_key(q) == 'key':
        books = Book.search_by_keywords(q)
    else:
        books = [Book.get_book_by_isbn(q)]
    return jsonify(books), 200
예제 #7
0
파일: book.py 프로젝트: DwyanWade/awake
def search():
    form = BookSearchForm().validate_for_api()
    start = form.start.data
    count = form.count.data
    summary = form.summary.data
    q = form.q.data
    http = Http()
    res = http.book_search(start, count, summary, q)
    return jsonify(res)
예제 #8
0
파일: book.py 프로젝트: gjw199513/ginger
def search():
    # url http://localhost:5000/v1/book/search?q={}
    form = BookSearchForm().validate_for_api()
    q = '%' + form.q.data + '%'
    books = Book.query.filter(or_(Book.title.like(q),
                                  Book.publisher.like(q))).all()
    # 隐藏字段
    books = [book.hide('summary', 'id') for book in books]
    return jsonify(books)
예제 #9
0
파일: book.py 프로젝트: tanglang1990/ginger
def search():
    # /v1/book/search?q=python
    form = BookSearchForm().validate_for_api()
    q = f'%{form.q.data}%'
    # 书名  出版社 ISBN
    books = Book.query.filter(
        or_(Book.title.like(q), Book.publisher.like(q),
            Book.isbn.like(q))).all()
    books = [book.hide('summary') for book in books]
    return jsonify(books)
예제 #10
0
파일: book.py 프로젝트: aserad/yubook
def search_book():
    # url   http://localhost:5000/v1/book?q={}
    form = BookSearchForm().validate_for_api()
    q = '%' + form.q.data + '%'
    books = Book.query.filter(
        and_(
            or_(Book.title.like(q), Book.author.like(q),
                Book.publisher.like(q)), Book.status == 0)).all()
    books = [book.hide('summary') for book in books]
    return jsonify(books)
예제 #11
0
def search():
    """
    搜索图书 模糊检索
    """
    form = BookSearchForm().validate_for_api()
    q = '%' + form.q.data + '%'
    #  元类 创建ORM实例
    books = Book.query.filter(or_(Book.title.like(q),
                                  Book.publisher.like(q))).all()
    books = [book.hide('summary') for book in books]
    return jsonify(books)
예제 #12
0
파일: book.py 프로젝트: wswjuea/ginger
def search():
    # url:/v1/book/search?q={}
    form = BookSearchForm().validate_for_api()
    q = '%' + form.q.data + '%'
    # 元类 ORM
    books = Book.query.filter(
        or_(Book.title.like(q), Book.publisher.like(q))).all()
    # 查询中的条件为or_(条件1或条件2);like()模糊查询
    books = [book.hide('summary') for book in books]
    # 隐藏部分字段
    return jsonify(books)
예제 #13
0
파일: book.py 프로젝트: Air-Zhuang/ginger
def search():
    '''
    url http://localhost:5000/v1/book/search?q={}
    '''
    form = BookSearchForm().validate_for_api()
    q = '%' + form.q.data + '%'  #模糊搜索前后要加%
    books = Book.query.filter(or_(Book.title.like(q),
                                  Book.publisher.like(q))).all()
    books = [book.hide('summary') for book in books]
    resp = {"result": books, "flag": 1}  #返回值拼接成json格式
    return jsonify(resp)
예제 #14
0
파일: book.py 프로젝트: itswl/flask-api
def search():
    #url http://locahost:5000/v1/book/search?q={}
    # request.args.to_dict() 在base中完成
    form = BookSearchForm().validate_for_api()  #  完成验证
    q = '%' + form.q.data + '%'  # 模糊搜索前后得加 %
    # return q
    books = Book.query.filter(or_(Book.title.like(q),
                                  Book.publisher.like(q))).all()  #like 指定关键字 q
    books = [book.hide('summary', 'id').append('pages')
             for book in books]  # 只 返回指定的 关键字
    # 隐藏summary,id.追加pages.
    return jsonify(books)
예제 #15
0
def search():
    """
    根据传入的查询参数搜索图书信息 -> 用like实现模糊查询, or_在filter中表示或关系
    :return:
    """
    form = BookSearchForm().validate_for_api()
    q = '%' + form.q.data + '%'
    # # book = Book()
    # # 元类 ORM
    books = Book.query.filter(or_(Book.title.like(q),
                                  Book.publisher.like(q))).all()
    books = [book.hide('summary', 'id') for book in books]  # 隐藏summary字段
    return jsonify(books)
예제 #16
0
파일: book.py 프로젝트: ruoruo5203/ginger2
def search():
    # 实例化,然后调用
    form = BookSearchForm().validate_for_api()
    # 获取q。模糊搜索前后+%
    q = '%' + form.q.data + '%'
    #
    # sqlalchey实例化变量,不是通过普通的, book = Book()。而是通过元类 ORM创建的,,在ssqlalchey里面,不会去执行构造函数,使用装饰器
    # 模糊查询sqlalchemy方法。or_意思是或关系,默认是且关系。需要导入
    books = Book.query.filter(or_(Book.title.like(q),
                                  Book.publisher.like(q))).all()
    # 去除掉某些字段的返回,比如summary。hide方法。在book下面新建hide方法
    books = [book.hide('summary') for book in books]
    return jsonify(books)
예제 #17
0
def search():
    form = BookSearchForm(request.form).validate_for_api()
    q = '%' + form.q.data + '%'
    books = Book.query.filter(
        or_(Book.name.like(q), Book.category_id.like(q))).all()
    return jsonify(books)
예제 #18
0
def search():
    form = BookSearchForm().validate_for_api()
    q = '%' + form.q.data + '%'
    books = Book.query.filter(or_(Book.title.like(q),
                                  Book.publisher.like(q))).all()
    return jsonify(books)
예제 #19
0
def search():
    form = BookSearchForm().validate_for_api()
    books = Book.search_by_keywords(form.q.data)
    return jsonify(books)
예제 #20
0
파일: book.py 프로젝트: DwyanWade/ginger
def search():
    form = BookSearchForm().validate_for_api()
    q = form.q.data
    return q