Esempio n. 1
0
def remove_menu(pk, menu_id):
    role = Role.query.filter(Role.id == pk).one()
    # logging.error(role.menus.all())
    # logging.error(schemas.role_schema.dump(role))
    menu = Menu.query.filter(Menu.id == menu_id).one()
    if not role or not menu:
        return ValidationErrorResult(
            message=f'ID 为{pk} role不存在 或者ID为{menu_id} Menu不存在')
    if menu not in role.menus.all():
        return ValidationErrorResult(message=f'当前role中不存在ID为{menu_id} 的权限')
    role.menus.remove(menu)
    # logging.error(role.menus.all())
    db.session.flush()
    return jsonify(schemas.role_schema.dump(role)), 204
Esempio n. 2
0
def delete(pk):
    order = Order.query.filter(Order.id == pk).one()
    if not order:
        return ValidationErrorResult(message='ID 为{pk} Order不存在')
    db.session.delete(order)
    db.session.flush()
    return '', 204
Esempio n. 3
0
def delete_category(pk):
    category = Category.query.filter(Category.id == pk).one()
    if not category:
        return ValidationErrorResult(message='ID 为{pk} Category不存在')
    db.session.delete(category)
    db.session.flush()
    return '', 204
Esempio n. 4
0
def delete(pk):
    good = Good.query.filter(Good.id == pk).one()
    if not Good:
        return ValidationErrorResult(message='ID 为{pk} Good不存在')
    db.session.delete(good)
    db.session.flush()
    return '', 204
Esempio n. 5
0
def delete(pk):
    role = role.query.filter(role.id == pk).one()
    if not role:
        return ValidationErrorResult(message='ID 为{pk} role不存在')
    db.session.delete(role)
    db.session.flush()
    return '', 204
Esempio n. 6
0
def delete_attribute(pk):
    attribute = Attribute.query.filter(Attribute.id == pk).one()
    if not attribute:
        return ValidationErrorResult(message='ID 为{pk} Attribute不存在')
    db.session.delete(attribute)
    db.session.flush()
    return '', 204
Esempio n. 7
0
def create(order_number, trad_no, invoice_titile, invoice_company,
           invoice_content, consignee_address, order_price, pay_status,
           is_send, user_id, goods):
    if Order.query.filter(or_(Order.order_number == order_number)).first():
        return ValidationErrorResult(message='Order已存在')
    order = Order(order_number=order_number,
                  trad_no=trad_no,
                  invoice_titile=invoice_titile,
                  invoice_company=invoice_company,
                  invoice_content=invoice_content,
                  consignee_address=consignee_address,
                  order_price=order_price,
                  pay_status=pay_status,
                  is_send=is_send)

    user = User.query.filter(User.id == user_id).one()
    if user:
        user.orders.append(order)
        order.user_id = user_id
    if goods:
        for good in goods:
            gd = Good.query.filter(Good.id == good['id']).one()
            if gd:
                order.goods.append(gd)
    db.session.add(order)
    db.session.flush()
    return jsonify(schemas.order_schema.dump(order)), 201
Esempio n. 8
0
def create(good_name, good_price, good_weight, good_number, category_id,
           photos, good_desc, attributes, hot_number, good_state, is_promote):
    if Good.query.filter(or_(Good.good_name == good_name)).first():
        return ValidationErrorResult(message='Good已存在')
    good = Good(good_name=good_name,
                good_state=good_state,
                good_price=good_price,
                good_number=good_number,
                good_weight=good_weight,
                good_desc=good_desc,
                hot_number=hot_number,
                is_promote=is_promote)

    category = Category.query.filter(Category.id == category_id).one()
    if category:
        category.goods.append(good)
        good.category_id = category_id
    if photos:
        for photo in photos:
            ph = Photo(photo_name=photo['photo_name'],
                       photo_url=photo['photo_url'])
            good.photos.append(ph)
    if attributes:
        for attribute in attributes:
            attr = Attribute.query.filter(
                Attribute.id == attribute['id']).one()
            if attr:
                attr.attribute_values = attribute['attribute_values']
    db.session.add(good)
    db.session.flush()
    return jsonify(schemas.good_schema.dump(good)), 201
Esempio n. 9
0
def status(status, pk):
    user = User.s_query().filter(User.id == pk).one()
    if not user:
        return ValidationErrorResult(message='ID 为{pk} 用户不存在')
    user.status = status
    db.session.flush()

    return jsonify(schemas.user_schema.dump(user)), 200
Esempio n. 10
0
def create(role_name, role_desc):
    if Role.query.filter(or_(Role.role_name == role_name)).first():
        return ValidationErrorResult(message='role已存在')
    role = Role(role_name=role_name, role_desc=role_desc)
    db.session.add(role)
    db.session.flush()

    return jsonify(schemas.role_schema.dump(role)), 201
Esempio n. 11
0
def create(auth_name, path, level):
    if Menu.query.filter(or_(Menu.auth_name == auth_name)).first():
        return ValidationErrorResult(message='Menu已存在')
    menu = Menu(level=level, auth_name=auth_name, path=path)
    db.session.add(menu)
    db.session.flush()

    return jsonify(schemas.menu_schema.dump(menu)), 201
Esempio n. 12
0
def create(username, password, email):
    if User.s_query().filter(
            or_(User.username == username, User.email == email)).first():
        return ValidationErrorResult(message='用户名或者邮箱已存在')
    user = User(username=username, password=password, email=email)
    db.session.add(user)
    db.session.flush()

    return jsonify(schemas.user_schema.dump(user)), 201
Esempio n. 13
0
def update(username, email, pk):
    # logging.error(f"'status'*10: {status}, {type(status)}")
    user = User.query.filter(User.id == pk).one()
    if not user:
        return ValidationErrorResult(message='ID 为{pk} 用户不存在')

    user.username = username
    user.email = email
    db.session.flush()
    return jsonify(schemas.user_schema.dump(user)), 200
Esempio n. 14
0
def update_attribute(attribute_id, attribute_name, attribute_sel,
                     attribute_write, attribute_values):
    attribute = Attribute.query.filter(Attribute.id == attribute_id).one()
    if not attribute:
        return ValidationErrorResult(message='ID 为{attribute} 属性不存在')
    attribute.attribute_name = attribute_name
    attribute.attribute_sel = attribute_sel
    attribute.attribute_write = attribute_write
    attribute.attribute_values = attribute_values
    db.session.flush()
    return jsonify(schemas.attribute_schema.dump(attribute)), 200
Esempio n. 15
0
def update_category(category_name, category_level, pk, category_desc=''):

    category = Category.query.filter(Category.id == pk).one()
    if not category:
        return ValidationErrorResult(message='ID 为{pk} 分类不存在')
    category.category_name = category_name
    category.category_desc = category_desc
    category.category_level = category_level
    db.session.flush()

    return jsonify(schemas.category_schema.dump(category)), 200
Esempio n. 16
0
def update_children(children, pk):

    category = Category.query.filter(Category.id == pk).one()
    if not category:
        return ValidationErrorResult(message='ID 为{pk} 分类不存在')
    if children:
        categories = Category.query.filter(Category.id.in_(children)).all()
        category.children = categories
    db.session.flush()

    return jsonify(schemas.category_schema.dump(category)), 200
Esempio n. 17
0
def update_children(children, pk):

    menu = Menu.query.filter(Menu.id == pk).one()
    if not menu:
        return ValidationErrorResult(message='ID 为{pk} 菜单不存在')
    if children:
        menus = Menu.query.filter(Menu.id.in_(children)).all()
        menu.children = menus
    db.session.flush()

    return jsonify(schemas.menu_schema.dump(menu)), 200
Esempio n. 18
0
def update_role(role_id, pk):
    # logging.error(f"'status'*10: {status}, {type(status)}")
    user = User.query.filter(User.id == pk).one()
    if not user:
        return ValidationErrorResult(message='ID 为{pk} 用户不存在')

    role = Role.query.filter(Role.id == role_id).one()
    if role:
        user.role = role
    db.session.flush()
    return jsonify(schemas.user_schema.dump(user)), 200
Esempio n. 19
0
def category_attributes(pk, page, page_size, order_by, attribute_sel=None):
    category = Category.query.filter_by(id=pk).one()
    if not category:
        return ValidationErrorResult(message='ID 为{pk} 分类不存在')
    qexp = category.attributes.filter(Attribute.attribute_sel == attribute_sel)
    # qexp = Category.query.filter(Category.category_level.in_(range(type)))
    paged_ret = pagination(Attribute,
                           page,
                           page_size,
                           order_by,
                           query_exp=qexp)
    return jsonify(schemas.paged_attribute_schemas.dump(paged_ret))
Esempio n. 20
0
def update(role_name, role_desc, menu_ids, pk):

    role = Role.query.filter(Role.id == pk).one()
    if not role:
        return ValidationErrorResult(message='ID 为{pk} Role不存在')

    role.role_name = role_name
    role.role_desc = role_desc
    if menu_ids:
        menus = Menu.query.filter(Menu.id.in_(menu_ids)).all()
        role.menus = menus

    db.session.flush()
    return jsonify(schemas.role_schema.dump(role)), 200
Esempio n. 21
0
def update(auth_name, path, pk, level, parent_id=None):

    menu = Menu.query.filter(Menu.id == pk).one()
    if not menu:
        return ValidationErrorResult(message='ID 为{pk} 菜单不存在')

    menu.auth_name = auth_name
    menu.path = path
    menu.level = level
    if parent_id:
        parent = Menu.query.filter(Menu.id == parent_id).one()
        if parent and (menu not in parent.children):
            parent.children.append(menu)
    db.session.flush()

    return jsonify(schemas.menu_schema.dump(menu)), 200
Esempio n. 22
0
def create_category(category_name,
                    category_level,
                    category_desc,
                    parent_id=None):
    if Category.query.filter(
            or_(Category.category_name == category_name)).first():
        return ValidationErrorResult(message='Category已存在')
    category = Category(category_name=category_name,
                        category_level=category_level,
                        category_desc=category_desc)
    # category = Category(
    #     category_name=category_name, category_level=category_level)
    if parent_id:
        parent = Category.query.filter_by(id=parent_id).one()
        if parent:
            parent.children.append(category)
            category.parent_id = parent_id
    db.session.add(category)
    db.session.flush()

    return jsonify(schemas.category_schema.dump(category)), 201
Esempio n. 23
0
def delete(pk):
    menu = Menu.query.filter(Menu.id == pk).one()
    if not Menu:
        return ValidationErrorResult(message='ID 为{pk} Menu不存在')
    db.session.delete(menu)
    db.session.flush()
    return '', 204


# @bp.route('/sub_menus/', methods=['GET'])
# @use_kwargs(PageParams)
# @jwt_required()
# def sub_list(page, page_size, order_by):
#     qexp = SubMenu.query
#     paged_ret = pagination(SubMenu, page, page_size, order_by, query_exp=qexp)
#     return jsonify(schemas.paged_sub_menu_schemas.dump(paged_ret))

# @bp.route('/sub_menus/', methods=['POST'])
# @use_kwargs(schemas.sub_menu_create_schema)
# @jwt_required()
# @transaction(db.session)
# def sub_create(auth_name, path):
#     if SubMenu.query.filter(or_(
#             SubMenu.auth_name == auth_name)).first():
#         return ValidationErrorResult(message='SubMenu已存在')
#     sub_menu = SubMenu(auth_name=auth_name, path=path)
#     db.session.add(sub_menu)
#     db.session.flush()

#     return jsonify(schemas.sub_menu_schema.dump(sub_menu)), 201

# @bp.route('/sub_menus/<int:pk>/', methods=['GET'])
# @jwt_required()
# def sub_retrieve(pk):
#     sub_menu = SubMenu.query.filter(SubMenu.id == pk).one()
#     return jsonify(schemas.sub_menu_schema.dump(sub_menu)), 200

# @bp.route('/sub_menus/<int:pk>/', methods=['PUT'])
# @use_kwargs(schemas.sub_menu_create_schema)
# @jwt_required()
# @transaction(db.session)
# def sub_update(auth_name, path, pk):

#     sub_menu = SubMenu.query.filter(SubMenu.id == pk).one()
#     if not sub_menu:
#         return ValidationErrorResult(
#             message='ID 为{pk} 菜单不存在')

#     sub_menu.auth_name = auth_name
#     sub_menu.path = path
#     db.session.flush()

#     return jsonify(schemas.sub_menu_schema.dump(sub_menu)), 200

# @bp.route('/sub_menus/<int:pk>/', methods=['DELETE'])
# @jwt_required()
# @transaction(db.session)
# def sub_delete(pk):
#     sub_menu = SubMenu.query.filter(SubMenu.id == pk).one()
#     if not sub_menu:
#         return ValidationErrorResult(
#             message='ID 为{pk} SubMenu不存在')
#     db.session.delete(sub_menu)
#     db.session.flush()
#     return '', 204
Esempio n. 24
0
def delete(pk):
    user = User.s_query().filter(User.id == pk).one()
    if not user:
        return ValidationErrorResult(message='ID 为{pk} 用户不存在')
    user.del_flag = user.id
    return '', 204
Esempio n. 25
0
def login(username, password):
    user = User.s_query().filter_by(username=username).first()
    if user is None or not user.check_password(password):
        return ValidationErrorResult(message='错误的用户名或者密码')
    return jsonify(schemas.token_schema.dump(user)), 201