コード例 #1
0
def delwatch():
    if not 'uid' in session:
        return jsonify(code=1)
    goodsid = int(request.args['goodsid'])
    goods_model = GoodsModel(app.config['MYSQL_AGENT'])
    watchlist = WatchListModel(app.config['MYSQL_AGENT'])
    watchlist.del_watch(session['uid'], goodsid)
    return jsonify(code=0)
コード例 #2
0
def addwatch():
    if not 'uid' in session:
        return jsonify(code=1)
    goodsid = int(request.args['goodsid'])
    watchprice = float(request.args['watchprice'])
    watchlist = WatchListModel(app.config['MYSQL_AGENT'])
    watch = Row()
    watch.userid = int(session['uid'])
    watch.goodsid = goodsid
    watch.notify = 1
    watch.notify_param = 'price:%f' % (watchprice)
    watchlist.add_watch(watch)
    return jsonify(code=0)
コード例 #3
0
def getwatch():
    if not 'uid' in session:
        return jsonify(code=1)
    watchlist = WatchListModel(app.config['MYSQL_AGENT'])
    mywatch = watchlist.get_goods(session['uid'])
    goodsids = []
    for w in mywatch:
        goodsids.append(w['goodsid'])
    goods_model = GoodsModel(app.config['MYSQL_AGENT'])
    goods = goods_model.query_goods_byid(goodsids, ['title', 'url', 'goodsid',
        'picurl', 'price'])
    goods_map = {}
    for item in goods:
        goods_map[ item['goodsid'] ] = item
    results = []
    for w in mywatch:
        gid = w['goodsid']
        if not gid in goods_map:
            continue
        good = goods_map[gid]
        w.update(good)
        w['create_time'] = time.mktime(w['create_time'].timetuple())
        results.append(w)
    return jsonify(code=0, watchlist=results)