Esempio n. 1
0
def account():
    if request.method == "GET":
        msg = ['',
               u'请填写完整后再提交',
               u'更新成功']
        user = utils.get_current_user()
        if int(request.args.get('msg') or 0) == 2:
            msg_result = 'success'
        else:
            msg_result = 'error'
        msg_text = msg[int(request.args.get('msg') or 0)]
        return render_template('account.html', user=user, msg=msg_text, msg_result=msg_result)
    elif request.method == "POST":
        nickname = request.form.get('nickname')
        name = request.form.get('name')

        #email 未填写
        if nickname and name:
            user = User.query.get(utils.get_currentt_user_id())
            user.name = name
            user.nickname = nickname
            db.session.commit()
            return redirect(url_for('frontend.account', msg=2))
        else:
            return redirect(url_for('frontend.account', msg=1))
Esempio n. 2
0
def submit_order():
    luck = random.randint(0, 100)
    list = request.form.get('list')
    user_id = utils.get_currentt_user_id()
    shop_id = int(request.form.get('shop_id'))
    time = utils.get_now()

    #检查小组是否已经添加这个店铺
    group = Group.query.filter(Group.id == utils.get_currentt_user_group_id(), Shop.id == shop_id).first()

    if group:
        #计算总价
        order_list = json.loads(list)
        total = 0.0
        for order in order_list:
            total += float(order['price']) * int(order['num'])

        order = Order(user_id, shop_id, utils.get_currentt_user_group_id(), total, time, list, luck)

        db.session.add(order)
        db.session.commit()

        return jsonify(result="success", luck=luck)
    else:
        return redirect("/")
Esempio n. 3
0
def submit_order():
    luck = random.randint(0, 100)
    list = request.form.get('list')
    user_id = utils.get_currentt_user_id()
    shop_id = int(request.form.get('shop_id'))
    time = utils.get_now()

    #检查小组是否已经添加这个店铺
    group = Group.query.filter(Group.id == utils.get_currentt_user_group_id(),
                               Shop.id == shop_id).first()

    if group:
        #计算总价
        order_list = json.loads(list)
        total = 0.0
        for order in order_list:
            total += float(order['price']) * int(order['num'])

        order = Order(user_id, shop_id, utils.get_currentt_user_group_id(),
                      total, time, list, luck)

        db.session.add(order)
        db.session.commit()

        return jsonify(result="success", luck=luck)
    else:
        return redirect("/")
Esempio n. 4
0
def join(id):
    #已经加入小组的不能加入另外的小组
    if utils.get_currentt_user_group_id() > 0:
        return redirect('/')

    group = Group.query.filter(Group.id == id).first()

    if group:
        user = User.query.get(utils.get_currentt_user_id())
        user.group_id = id
        #新增用户数
        group.user_num += 1
        db.session.commit()
        return redirect('/?action=join_group_success')
    else:
        return redirect('/')
Esempio n. 5
0
def add():
    """添加店铺页面"""
    if request.method == "GET":
        return render_template('/shop/add.html')
    elif request.method == "POST":
        if utils.get_currentt_user_group_id():
            name = request.form['name']
            tel = request.form['tel']
            address = request.form['address']
            city_id = utils.get_currentt_user_group().city_id

            if not name or not tel or not address or not city_id:
                return redirect("/action=add_shop_fail")

            shop = Shop(name, address, tel, city_id, utils.get_currentt_user_id())
            utils.get_currentt_user_group().shops.append(shop)
            db.session.add(shop)
            db.session.commit()

            return redirect(url_for('shop.edit_food', id=shop.id))
        else:
            return redirect("/")
Esempio n. 6
0
def new():
    if request.method == "GET":
        cities = City.query.all()
        return render_template("/group/new.html", cities=cities)
    elif request.method == "POST":
        #已经加入小组的不能再创建小组
        if utils.get_currentt_user_group_id() > 0:
            return redirect('/')

        name = request.form["name"]
        descrip = request.form["descrip"]
        address = request.form["address"]

        if not name or not descrip or not address:
            return redirect('/?action=create_group_fail')

        group = Group(name, descrip, address, request.form['city'], utils.get_currentt_user_id())
        group.users = [utils.get_current_user()]

        db.session.add(group)
        db.session.commit()

        return redirect('/?action=create_group_success')
Esempio n. 7
0
def add():
    """添加店铺页面"""
    if request.method == "GET":
        return render_template('/shop/add.html')
    elif request.method == "POST":
        if utils.get_currentt_user_group_id():
            name = request.form['name']
            tel = request.form['tel']
            address = request.form['address']
            city_id = utils.get_currentt_user_group().city_id

            if not name or not tel or not address or not city_id:
                return redirect("/action=add_shop_fail")

            shop = Shop(name, address, tel, city_id,
                        utils.get_currentt_user_id())
            utils.get_currentt_user_group().shops.append(shop)
            db.session.add(shop)
            db.session.commit()

            return redirect(url_for('shop.edit_food', id=shop.id))
        else:
            return redirect("/")