Exemplo n.º 1
0
def search():
    """
    word: 搜索关键词
    order: 排序方式
    """
    word = request.args.get('word', '')
    order_way = request.args.get('order') if request.args.get(
        'order') else 'flow'
    params = [Goods.status == True]
    if word:
        WordCloud.upsert(word)
        params.append(
            or_(Goods.name.like('%{}%'.format(word)),
                Goods.number.like('%{}%'.format(word))))
    else:
        params.append(Goods.id == 0)
    goods = Goods.query.filter(*params).order_by(goods_order_map(order_way,
                                                                 0)).all()
    word_cloud = WordCloud.query_for_max_on_window(90)
    return render_template('main/search.html',
                           goods=goods,
                           word=word,
                           order_way=order_way,
                           word_cloud=word_cloud,
                           goods_order_map=goods_order_map)
Exemplo n.º 2
0
def usr_center():
    name_dic = {'flow': '我的最受欢迎', 'date_down': '我的最新发布'}
    goods_data = [{
        'name':
        name_dic[key],
        'data':
        current_user.goods.filter(Goods.status == True).order_by(
            goods_order_map(key, 0)).limit(10).all(),
    } for key in name_dic if current_user.is_authenticated]
    goods_stat = current_user.get_goods_stat()
    return render_template('main/usr_center.html',
                           goods_data=goods_data,
                           goods_stat=goods_stat)
Exemplo n.º 3
0
def all_goods(tid=None, order='flow'):
    """ 所有商品分类展示 """
    tid = tid if tid else GoodsType.query.order_by(
        GoodsType.sequence.asc()).first().id
    data_goods = Goods.query.filter(Goods.status == True, Goods.type_id == tid).\
        order_by(goods_order_map(order, 0)).all()
    return render_template('main/all_goods.html',
                           data_goods=data_goods,
                           tid=tid,
                           order=order,
                           type_li=GoodsType.query.order_by(
                               GoodsType.sequence.asc()).all(),
                           goods_order_map=goods_order_map)
Exemplo n.º 4
0
def usr_home(uid, tid=None, order='flow'):
    """ 用户个人主页 """
    PvCount.add_home_count()
    tid = tid if tid else GoodsType.query.order_by(
        GoodsType.sequence.asc()).first().id
    user_obj = User.query.get_or_404(uid)
    data_goods = user_obj.goods.filter(Goods.status == True, Goods.type_id == tid).\
        order_by(goods_order_map(order, 0)).all()
    return render_template('main/usr_home.html',
                           user_obj=user_obj,
                           goods=data_goods,
                           uid=uid,
                           tid=tid,
                           order=order,
                           type_li=GoodsType.query.order_by(
                               GoodsType.sequence.asc()).all(),
                           goods_order_map=goods_order_map)
Exemplo n.º 5
0
def index():
    """
    tid: 当其为0时表示类型为已下架商品
    order: 表示排序方式
    """
    args = request.args.to_dict()
    type_id = int(
        args.get('tid',
                 GoodsType.query.order_by(
                     GoodsType.sequence.asc()).first().id))
    order_way = args.get('order', 'date_down')
    params = [Goods.type_id == type_id, Goods.status == True
              ] if type_id else [Goods.status == False]
    if not current_user.can('system_manage'):
        params.append(Goods.user_id == current_user.id)
    goods_list = Goods.query.filter(*params).order_by(
        goods_order_map(order_way, 0)).all()
    return render_template('goods/index.html',
                           goods_list=goods_list,
                           type_id=type_id,
                           order_way=order_way,
                           goods_order_map=goods_order_map,
                           type_li=GoodsType.query.all())