def get_all_category():
    category_name = request.args.get('category_name', '').replace('$', '&')

    if category_name:
      	query_field = mongo_util.generate_query(eval(request.args.get('field', '[]')))
        
        try:
            page = int(request.args.get('page', '1'))
        except:
            page = 1
        page = page if page > 0 else 1
        
        #get target collection from mongodb
        com_col = mongo_util.get_commodity_col()
        
        com_cursor = com_col.find(
            {'category': {'$elemMatch': {'$all': category_name.split('>')}}},
            query_field).skip((page - 1) * conf.ITEM_PER_PAGE).limit(conf.ITEM_PER_PAGE).batch_size(500)

        return json.dumps(map(lambda x:x, com_cursor), cls=ComplexEncoder)

    com_col = mongo_util.get_commodity_col()

    all_category = com_col.distinct('category.0')

    return json.dumps(map(lambda x: {'name': '>'.join(x)},
                      all_category), cls=ComplexEncoder)
Exemple #2
0
def get_all_category():
    category_name = request.args.get('category_name', '').replace('$', '&')

    if category_name:
        query_field = mongo_util.generate_query(
            eval(request.args.get('field', '[]')))

        try:
            page = int(request.args.get('page', '1'))
        except:
            page = 1
        page = page if page > 0 else 1

        #get target collection from mongodb
        com_col = mongo_util.get_commodity_col()

        com_cursor = com_col.find(
            {
                'category': {
                    '$elemMatch': {
                        '$all': category_name.split('>')
                    }
                }
            }, query_field).skip((page - 1) * conf.ITEM_PER_PAGE).limit(
                conf.ITEM_PER_PAGE).batch_size(500)

        return json.dumps(map(lambda x: x, com_cursor), cls=ComplexEncoder)

    com_col = mongo_util.get_commodity_col()

    all_category = com_col.distinct('category.0')

    return json.dumps(map(lambda x: {'name': '>'.join(x)}, all_category),
                      cls=ComplexEncoder)
def get_commodity_info(asin):
    '''
            获取指定ASIN的商品信息
    '''
    query_field = mongo_util.generate_query(eval(request.args.get('field', '[]')))
    
    com_col = mongo_util.get_commodity_col()

    asin_info = com_col.find_one({'ASIN': asin},
                                 query_field)
    del com_col
    return json.dumps(asin_info, cls=ComplexEncoder)
Exemple #4
0
def get_commodity_info(asin):
    '''
            获取指定ASIN的商品信息
    '''
    query_field = mongo_util.generate_query(
        eval(request.args.get('field', '[]')))

    com_col = mongo_util.get_commodity_col()

    asin_info = com_col.find_one({'ASIN': asin}, query_field)
    del com_col
    return json.dumps(asin_info, cls=ComplexEncoder)