示例#1
0
def index(*args, **kwargs):
    if request.method == 'GET':
        print('[i] Kwargs is ', kwargs)
        prod_cat = db.session.query(Prod_cat.id.label('value'),
                                    Prod_cat.name.label('text')).all()
        prod_cat = sql_to_dict(prod_cat)
        print("[i] Prod_cat query returns is", prod_cat)
        return jsonify(prod_cat)
    if request.method == 'POST':
        formData = json.loads(request.data)
        print('[i][Prod_cat/:post] Request is ', formData)

        prodCat = Prod_cat(name=formData['text'])
        db.session.add(prodCat)
        db.session.commit()
        print('[i][Prod_cat/:post] Added Prod_cat id is ', prodCat.id)
        return jsonify({'id': prodCat.id})
    if request.method == 'PUT':
        formData = json.loads(request.data)
        print('[i][Prod_cat/:PUT] Request is ', formData)

        prodCat = Prod_cat.query.filter(
            Prod_cat.id == formData['value']).update(
                {'name': formData['text']})
        print('[i][Prod_cat/:PUT] User id is ', prodCat)
        db.session.commit()
        return 'OK'
示例#2
0
def index(*args, **kwargs):
    if request.method == 'GET':
        print('[i] Kwargs is ', kwargs)
        res = db.session.query( \
            Model.id.label('value'), Model.name.label('text'), Model.address, Model.desc \
        ).order_by("value desc").all()
        res = sql_to_dict(res)
        print("[i] {} query returns is ".format(bpName), res)
        return jsonify(res)
    if request.method == 'POST':
        formData = json.loads(request.data)
        print('[i][{}/:post] Request is '.format(bpName), formData)
        res = Model(name=formData['text'], address=formData['address'], desc=formData['desc'])
        db.session.add(res)
        db.session.commit()
        print('[i][{}/:post] Added Model id is '.format(bpName), res.id)
        return jsonify({'value': res.id})
    if request.method == 'PUT':
        formData = json.loads(request.data)
        print('[i][{}/:PUT] Request is '.format(bpName), formData)

        res = Model.query.filter(Model.id == formData['value']).update({
            'name': formData['text'],
            'address': formData['address'],
            'desc': formData['desc'],
        })
        print('[i][{}/:PUT] User id is '.format(bpName), res)
        db.session.commit()
        return 'OK'
示例#3
0
def index(*args, **kwargs):
    if request.method == 'GET':
        users = db.session.query(User.id, User.name, User.phone, User_role.name.label('role_name'), User.role_id)\
                    .join(User_role, User_role.id == User.role_id).all()
        users = sql_to_dict(users)
        print("[i] User query returns is", users)
        return jsonify(users)
    if request.method == 'POST':
        formData = json.loads(request.data)
        print('[i][user/:put] Request is ', formData)
        user = User(name=formData['name'],
                    role_id=formData['role_id'],
                    phone=formData['phone'])
        db.session.add(user)
        db.session.commit()
        print('[i][user/:put] Added user id is ', user.id)
        # user = to_json(user)
        return jsonify({'id': user.id})
    if request.method == 'PUT':
        formData = json.loads(request.data)
        print('[i][user/:post] Request is ', formData)
        user = User.query.filter(User.id == formData['id']).update({
            'name':
            formData['name'],
            'phone':
            formData['phone'],
            'role_id':
            formData['role_id']
        })
        print('[i][user/:post] User id is ', user)
        db.session.commit()
        return 'OK'
示例#4
0
def index(*args, **kwargs):
    if request.method == 'GET':
        print('[i] Kwargs is ', kwargs)
        prod_component = db.session.query( \
            Prod_component.id.label('value'), Prod_component.name.label('text'), Prod_component.desc \
        ).order_by("value desc").all()
        prod_component = sql_to_dict(prod_component)
        print("[i] prod_component query returns is", prod_component)
        return jsonify(prod_component)
    if request.method == 'POST':
        formData = json.loads(request.data)
        print('[i][prod_component/:post] Request is ', formData)
        prod_component = Prod_component(name=formData['text'],
                                        desc=formData['desc'])
        db.session.add(prod_component)
        db.session.commit()
        print('[i][prod_component/:post] Added prod_component id is ',
              prod_component.id)
        return jsonify({'id': prod_component.id})
    if request.method == 'PUT':
        formData = json.loads(request.data)
        print('[i][Prod_component/:PUT] Request is ', formData)

        prod_component = Prod_component.query.filter(
            Prod_component.id == formData['value']).update({
                'name':
                formData['text'],
                'desc':
                formData['desc'],
            })
        print('[i][Prod_component/:PUT] User id is ', prod_component)
        db.session.commit()
        return 'OK'
示例#5
0
def getUserRoles(*args, **kwargs):
    if request.method == 'GET':
        roles = db.session.query(User_role.id.label('value'),
                                 User_role.name.label('text')).all()
        print("[i][getUserRoles]  Roles query returns is ", roles)
        roles = sql_to_dict(roles)
        print("[i][getUserRoles]  Roles modificate to ", roles)
        return jsonify(roles)
示例#6
0
def getUser(*args, **kwargs):
    print("[i][getUser] kwargs is ", kwargs)
    if request.method == 'GET':
        users = db.session.query(User.id, User.name, User.phone, User_role.name.label('role_name'), User.role_id)\
            .join(User_role, User_role.id == User.role_id)\
            .filter(User.id == kwargs['user_id']).first()
        user = sql_to_dict(users)
        print("[i] User query returns is", user)
        return jsonify(user)
    if request.method == 'DELETE':
        print("[i][user/id:delete] User request returns is ",
              kwargs['user_id'])
        res = User.query.filter(User.id == kwargs['user_id']).delete()
        print("[i][user/id:delete] Deleting query result is ", res)
        db.session.commit()
        return 'OK'
示例#7
0
def index(*args, **kwargs):
    if request.method == 'GET':
        print('[i] Kwargs is ', kwargs)

        res = db.session.query( Model.id, Model.name, Model.phone, Model.address, Model.discount, Model.desc)\
                .order_by("id desc").all()
        res = sql_to_dict(res)
        print("[i] {} query returns is ".format(bpName), res)
        return jsonify(res)
    if request.method == 'POST':
        formData = json.loads(request.data)
        print('[i][{}/:post] Request is '.format(bpName), formData)
        res = Model(name=formData['name'], phone=formData['phone'], \
                    address=formData['address'], discount=formData['discount'], desc=formData['desc'])
        db.session.add(res)
        db.session.commit()
        print('[i][{}/:post] Added Model id is '.format(bpName), res.id)
        return jsonify({'id': res.id})
    if request.method == 'PUT':
        formData = json.loads(request.data)
        print('[i][{}/:PUT] Request is '.format(bpName), formData)

        res = Model.query.filter(Model.id == formData['id']).update({
            'name':
            formData['name'],
            'phone':
            formData['phone'],
            'address':
            formData['address'],
            'discount':
            formData['discount'],
            'desc':
            formData['desc']
        })
        print('[i][{}/:PUT] User id is '.format(bpName), res)
        db.session.commit()
        return 'OK'