def wrapper(**kwargs):
     from app.models import Utils
     #TODO move it to check app version or some other reliable source
     user_data = session.get('_user', None)
     if (Utils.getParam(request.form, 'ref') == 'web'
             and (user_data is None or
                  (user_data and user_data['user_id'] != Utils.getParam(
                      request.form, 'user_id', 'int')))):
         return Utils.errorResponse({'status': 'false'},
                                    'HTTP_STATUS_CODE_CLIENT_ERROR')
     return func(**kwargs)
Beispiel #2
0
def searchString():
    response = {'status': 'False'}
    results = {}

    query = Utils.getParam(request.args, 'q')
    page = Utils.getParam(request.args, 'page', var_type='int', default=1)
    search_type = Utils.getParam(request.args, 'type', default='free')
    user_id = Utils.getParam(request.args, 'userId', 'int')
    flow = Utils.getParam(request.args, 'flow', default='borrow')
    gcm_id = Utils.getParam(request.args, 'gcm_id', default=None)
    uuid = Utils.getParam(request.args, 'distinct_id', default=None)
    ref = Utils.getParam(request.args, 'ref', default='mobile')

    if not query:
        return Utils.errorResponse(response, 'HTTP_STATUS_CODE_DATA_MISSING')

    if ref == 'web':
        return json.dumps(WebUtils.fetchSearchResults(query, search_type,
                                                      page))

    user_info = {'user_id': user_id, 'gcm_id': gcm_id, 'uuid': uuid}
    search = Search(query, user_info, flow)
    if search_type == 'free':
        results = search.basicSearch(page=page - 1)
    elif search_type == 'category':
        results = search.categorySearch(page=page - 1)
    elif search_type == 'collections':
        results = search.collectionsSearch(page=page - 1)
    elif search_type == 'isbn':
        results = search.isbnSearch(page=page - 1)
    elif search_type == 'auto':
        results = search.autoComplete()
    elif search_type == 'custom':
        results = search.customQuery()
        return results
    #log
    if user_id not in Utils.getAdmins():
        Search.logSearch({_: request.args.get(_)
                          for _ in request.args}, search_type)

    return jsonify(results) if flow != 'admin' else jsonp(results)