def before_request():
    ignore_urls = current_app.config['IGNORE_URLS']
    ignore_check_login_urls = current_app.config['IGNORE_CHECK_LOGIN_URLS']
    path = request.path

    # 如果是静态文件就不要查询用户信息了
    pattern = re.compile('%s' % "|".join(ignore_check_login_urls))
    if pattern.match(path):
        return

    if '/v1' in path:
        return

    user_info = check_login()
    g.current_user = None
    if user_info:
        g.current_user = user_info

    #加入日志
    LogService.add_access_log()

    pattern = re.compile('%s' % "|".join(ignore_urls))
    if pattern.match(path):
        return

    if not user_info:
        return redirect(UrlManager.build_url("/user/login"))
    return
Example #2
0
def info():
    resp_data = {}
    req = request.args  # 参数少用args
    # reqv = request.values      # 参数多用values
    uid = int(req.get('id', 0))
    reback_url = UrlManager.build_url("/account/index")
    if uid < 1:
        return redirect(reback_url)

    info = User.query.filter_by(uid=uid).first()
    if not info:
        return redirect(reback_url)

    access_list = AppAccessLog.query.filter_by(uid=uid).order_by(
        AppAccessLog.id.desc()).limit(10).all()
    resp_data['info'] = info
    resp_data['access_list'] = access_list
    return render_template("account/info.html", **resp_data)
Example #3
0
def info():
    resp_data = {}
    req = request.args
    f_id = int(req.get("id", 0))
    back_url = UrlManager.build_url("/food/index")

    if f_id < 1:
        return redirect(back_url)

    f_info = Food.query.filter_by(id=f_id).first()
    if not info:
        return redirect(back_url)

    stock_change_list = FoodStockChangeLog.query.filter(FoodStockChangeLog.food_id == f_id)\
        .order_by(FoodStockChangeLog.id.desc()).all()

    resp_data['info'] = f_info
    resp_data['stock_change_list'] = stock_change_list
    resp_data['current'] = 'index'
    return render_template("food/info.html", **resp_data)
Example #4
0
def pay_info():
    resp_data = {}
    req = request.values
    id = int(req['id']) if 'id' in req else 0

    back_url = UrlManager.build_url("/finance/index")

    if id < 1:
        return redirect(back_url)

    pay_order_info = PayOrder.query.filter_by( id = id ).first()
    if not pay_order_info:
        return redirect(back_url)

    member_info = Member.query.filter_by(id=pay_order_info.member_id).first()
    if not member_info:
        return redirect(back_url)

    order_item_list = PayOrderItem.query.filter_by(pay_order_id=pay_order_info.id).all()
    data_order_item_list = []
    if order_item_list:
        food_map = get_dict_filter_field(Food, Food.id, "id", select_filter_obj(order_item_list, "food_id"))
        for item in order_item_list:
            tmp_food_info = food_map[item.food_id]
            tmp_data = {
                "quantity": item.quantity,
                "price": item.price,
                "name": tmp_food_info.name
            }
            data_order_item_list.append(tmp_data)

    address_info = {}
    if pay_order_info.express_info:
        address_info = json.loads(pay_order_info.express_info)

    resp_data['pay_order_info'] = pay_order_info
    resp_data['pay_order_items'] = data_order_item_list
    resp_data['member_info'] = member_info
    resp_data['address_info'] = address_info
    resp_data['current'] = 'index'
    return render_template("finance/pay_info.html", **resp_data)
Example #5
0
def info():
    resp_data = {}
    req = request.args
    m_id = int(req.get("id", 0))
    back_url = UrlManager.build_url("/member/index")
    if m_id < 1:
        return redirect(back_url)

    member_info = Member.query.filter_by(id=m_id).first()
    if not member_info:
        return redirect(back_url)

    # pay_order_list = PayOrder.query.filter_by( member_id = m_id ).filter( PayOrder.status.in_( [-8,1] ) )\
    #     .order_by( PayOrder.id.desc() ).all()
    # comment_list = MemberComments.query.filter_by( member_id = m_id ).order_by( MemberComments.id.desc() ).all()

    resp_data['info'] = MemberViewModel(member_info)
    # resp_data['pay_order_list'] = pay_order_list
    # resp_data['comment_list'] = comment_list
    resp_data['current'] = 'index'
    return render_template("member/info.html", **resp_data)
Example #6
0
def set():
    if request.method == "GET":
        resp_data = {}
        req = request.args
        m_id = int(req.get("id", 0))
        back_url = UrlManager.build_url("/member/index")
        if m_id < 1:
            return redirect(back_url)

        member_info = Member.query.filter_by(id=m_id).first()
        if not member_info:
            return redirect(back_url)

        if member_info.status != 1:
            return redirect(back_url)

        resp_data['info'] = member_info
        resp_data['current'] = 'index'
        return render_template("member/set.html", **resp_data)

    req = request.values
    m_id = req['id'] if 'id' in req else 0
    nickname = req['nickname'] if 'nickname' in req else ''
    if nickname is None or len(nickname) < 1:
        return AjaxFail('请输入符合规范的姓名')

    member_info = Member.query.filter_by(id=m_id).first()
    if not member_info:
        return AjaxFail('指定会员不存在')

    member_info.nickname = nickname
    member_info.updated_time = get_current_date()

    with db.auto_commit():
        member_info
    return AjaxSuccess()
Example #7
0
def set():
    if request.method == 'GET':
        resp_data = {}
        req = request.args
        id = int(req.get('id', 0))
        info = Food.query.filter_by(id=id).first()
        if info and info.status != 1:
            return redirect(UrlManager.build_url('/food/index'))

        c_list = FoodCategory.query.all()
        resp_data['info'] = info
        resp_data['c_list'] = c_list
        resp_data['current'] = 'index'
        return render_template("food/set.html", **resp_data)

    req = request.values
    id = int(req['id']) if 'id' in req and req['id'] else 0
    cat_id = int(req['cat_id']) if 'cat_id' in req else 0
    name = req['name'] if 'name' in req else ''
    price = req['price'] if 'price' in req else ''
    main_image = req['main_image'] if 'main_image' in req else ''
    summary = req['summary'] if 'summary' in req else ''
    stock = int(req['stock']) if 'stock' in req else ''
    tags = req['tags'] if 'tags' in req else ''

    if cat_id < 1:
        return AjaxFail('请选择分类')

    if name is None or len(name) < 1:
        return AjaxFail('请输入符合规范的名称')

    if not price or len(price) < 1:
        return AjaxFail('请输入符合规范的售卖价格')

    price = Decimal(price).quantize(Decimal('0.00'))
    if price <= 0:
        return AjaxFail('请输入符合规范的售卖价格')

    if main_image is None or len(main_image) < 3:
        return AjaxFail('请上传封面图')

    if summary is None or len(summary) < 3:
        return AjaxFail('请输入图书描述,并不能少于10个字符')

    if stock < 1:
        return AjaxFail('请输入符合规范的库存量')

    if tags is None or len(tags) < 1:
        return AjaxFail('请输入标签,便于搜索')

    food_info = Food.query.filter_by(id=id).first()
    before_stock = 0
    if food_info:
        model_food = food_info
        before_stock = model_food.stock
    else:
        model_food = Food()
        model_food.status = 1
        model_food.created_time = get_current_date()

    model_food.cat_id = cat_id
    model_food.name = name
    model_food.price = price
    model_food.main_image = main_image
    model_food.summary = summary
    model_food.stock = stock
    model_food.tags = tags
    model_food.updated_time = get_current_date()

    with db.auto_commit():
        db.session.add(model_food)

    PayService.set_stock_change_log(model_food.id,
                                    int(stock) - int(before_stock), "后台修改")

    return AjaxSuccess()
Example #8
0
def logout():
    response = make_response(redirect(UrlManager.build_url("/user/login")))
    logout_user()
    # response.delete_cookie(app.config['AUTH_COOKIE_NAME'])
    return response