Exemplo n.º 1
0
def getallbills():
    username = request.authorization.username
    passwordinfo = request.authorization.password
    bill_sc = Billschema(many=False)
    data = request.get_json()

    flag = checkauthentication(username, passwordinfo)

    if flag == True:
        result = Credential.select_user_by_email(username)
        user_sc = Credentialschema()

        data = user_sc.dump(result)
        owner_id = data.get('id')

        bills_schema = Billschema(many=True)

        result = Bills.select_user_by_ownerid(owner_id)

        data = bills_schema.dumps(result)

        #File.select_file_by_billid()

        return jsonify(data)
    else:
        return custom_http_code("unauthorized", 401)
Exemplo n.º 2
0
def getallbills():
    start = time.time()
    username = request.authorization.username
    passwordinfo = request.authorization.password
    bill_sc = Billschema(many=False)
    data = request.get_json()
    dbtime = time.time()
    flag = checkauthentication(username, passwordinfo)
    dur = (time.time() - dbtime) * 1000
    c.timing("dbconnect", dur)

    if flag == True:
        result = Credential.select_user_by_email(username)
        user_sc = Credentialschema()

        data = user_sc.dump(result)
        owner_id = data.get('id')

        bills_schema = Billschema(many=True)
        dbtime = time.time()
        result = Bills.select_user_by_ownerid(owner_id)
        dur = (time.time() - dbtime) * 1000
        c.timing("dbconnect", dur)

        data = bills_schema.dumps(result)

        #File.select_file_by_billid()

        c.incr("getallbillcount")
        dur = (time.time() - start) * 1000
        c.timing("getallbilltime", dur)

        return jsonify(data)
    else:
        return custom_http_code("unauthorized", 401)
Exemplo n.º 3
0
def billcreate():
    #db.create_all()
    username = request.authorization.username
    passwordinfo = request.authorization.password
    bill_sc = Billschema(many=False)
    data = request.get_json()

    flag = checkauthentication(username, passwordinfo)

    if flag == True:
        # file = request.files['file']
        #

        data1 = request.get_json()

        list_var = data1["categories"]
        list_var = str(list_var)
        list_var = ((list_var.strip("[")).strip("]")).strip("'")
        data1["categories"] = list_var

        result = Credential.select_user_by_email(username)
        user_sc = Credentialschema()
        #user_sc = Credentialschema(many=False)
        bill_scs = Billschema(many=False)
        data = user_sc.dump(result)
        owner_id = data.get('id')
        #data=str(owner_id)
        id = str(uuid.uuid4().hex)

        load_data = bill_sc.load(data1)
        new_bill = Bills(load_data, id, owner_id)
        db.session.add(new_bill)
        db.session.commit()

        result = Bills.select_user_by_billid(id)
        print(owner_id)
        print(id)
        if result:
            print("there")
        else:
            print("empt")
        data = bill_sc.dumps(result)
        # print(result)
        # print(data)
        # # output=Credential.select_user_by_email(check_email)
        # print("done")

        attachmentfile = {}

        final = json.loads(data)
        final["attachments"] = attachmentfile
        return custom_http_code(final, 200)

    else:

        return custom_http_code("not authorized", 401)
Exemplo n.º 4
0
def getasinglebill(billid):
    start = time.time()

    # print(billid)
    username = request.authorization.username
    passwordinfo = request.authorization.password
    # bill_sc = Billschema(many=False)
    # data = request.get_json()
    dbtime = time.time()
    flag = checkauthentication(username, passwordinfo)

    dur = (time.time() - dbtime) * 1000
    c.timing("dbconnect", dur)

    print(billid)
    if flag == True:
        print(billid)
        dbtime = time.time()
        result = Credential.select_user_by_email(username)
        dur = (time.time() - dbtime) * 1000
        c.timing("dbconnect", dur)
        user_sc = Credentialschema()

        data = user_sc.dump(result)
        owner_id = data.get('id')
        print(owner_id)
        dbtime = time.time()
        result2 = Bills.select_user_by_billid(billid)
        dur = (time.time() - dbtime) * 1000
        c.timing("dbconnect", dur)

        bill_sc = Billschema(many=False)

        data2 = bill_sc.dump((result2))

        owner_id_test = data2.get('owner_id')
        print(owner_id_test)
        #return "before delete"
        if owner_id == owner_id_test:
            bill_schema = Billschema(many=False)

            dbtime = time.time()
            data = Bills.select_user_by_billid(billid)
            dur = (time.time() - dbtime) * 1000
            c.timing("dbconnect", dur)

            query_result = bill_schema.dumps(data)
            query_result = json.loads(query_result)

            #check attachment
            dbtime = time.time()
            result = File.select_file_by_billid(billid)
            dur = (time.time() - dbtime) * 1000
            c.timing("dbconnect", dur)

            if not result:
                attachmentfile = {}
                query_result["attachments"] = attachmentfile
                return jsonify(query_result)

            #if attachment

            print(result)
            #attachmentb results dump
            file_sc = File_schema_output(many=False)
            data = file_sc.dumps(result)

            #bill info dict
            attachmentfile = query_result

            #attachment dict
            final = json.loads(data)

            #add two dict
            attachmentfile["attachments"] = final

            c.incr("getbillcount")
            dur = (time.time() - start) * 1000
            c.timing("getbillcount", dur)
            return jsonify(attachmentfile)

        else:

            c.incr("getbillcount")
            dur = (time.time() - start) * 1000
            c.timing("getbillcount", dur)
            return custom_http_code("invalid bill id", 404)

    else:
        return custom_http_code("unzauthorized", 401)