コード例 #1
0
def message_send():
    data = None
    msg = None
    if not isConnected():
        print("---------------------------Connection Error------------")
        return abort(404, description="Resource not found")
    if request.method == 'POST':
        time = int(datetime.now().timestamp()) * 1000
        data = request.form['data']
        msg = str(request.form['msg'])
        senderid = request.form['senderid']
        image_path = "https://firebasestorage.googleapis.com/v0/b/canteen-management-syste-e183d.appspot.com/o/Admin%2Fburger.png?alt=media&token=b6731782-c9a6-452a-8bb6-46a4ce8a8321"
        if data == 'adminn' and msg != None:
            print("Admin Call")
            pushData = dict({
                'senderId': "17352015",
                'senderName': "Admin",
                'senderEmail': "*****@*****.**",
                'senderProfileUri': image_path,
                'msgTime': time,
                'msg': msg
            })

            print(f"The Sender Id : {senderid} and time : {time} ")
            db.child("Users").child(senderid).child("Chat").child(time).set(
                pushData)
            return json.dumps({'status': 'ok'})

        elif data == "page":
            return json.dumps(get_data(senderid))
        else:
            print("Another Call")

        return json.dumps({'status': 'ok'})
    print("Not a post Request")
コード例 #2
0
ファイル: routes.py プロジェクト: shkhaider2015/IUSM
def user_profile(uid):
    if not isConnected():
        print("---------------------------Connection Error------------")
        return abort(404, description="Resource not found")
    profile_path = db.child("Users").child(uid).child("Profile").get()
    orders_path = db.child("Users").child(uid).child("Orders").get()
    profile = dict(profile_path.val())

    if orders_path.val():
        orders = dict(orders_path.val())
    else:
        orders = None
    
    return render_template("profile.html", profile=profile, orders=orders)
コード例 #3
0
ファイル: routes.py プロジェクト: shkhaider2015/IUSM
def process_accept():
    if not isConnected():
        print("---------------------------Connection Error------------")
        return abort(404, description="Resource not found")
    data = None
    if request.method == 'POST':
        data = request.form['data']
        user_id = str(data[:-13:1])
        order_id = str(data[-13::1])
        pair = {'accepted' : True}
        print(user_id)
        print(order_id)
        db.child("Orders").child(order_id).update(pair)
        db.child("Users").child(user_id).child("Orders").child(order_id).update(pair)

        return json.dumps({'status':'OK'})
    print("Not a Post Request")
コード例 #4
0
def foods_list():
    if not isConnected():
        print("---------------------------Connection Error------------")
        return abort(404, description="Resource not found")
    tmpData = db.child("Foods").get()
    data = dict(tmpData.val())
    print(data)
    return render_template("foods_list.html", data=data)
コード例 #5
0
def chat_process():
    if not isConnected():
        print("---------------------------Connection Error------------")
        return abort(404, description="Resource not found")
    global previous_data
    key = request.form['key']
    m_type = request.form['m_type']
    data = dict()

    if m_type == 'send':
        print("send request")
        msg = request.form['msg']
        msgTime = int(time.time()) * 1000
        set_data = {
            'senderName': 'admin',
            'senderId': '17352015',
            'senderEmail': '*****@*****.**',
            'senderProfileUri':
            'https://firebasestorage.googleapis.com/v0/b/canteen-management-syste-e183d.appspot.com/o/Admin%2Fburger.png?alt=media&token=b6731782-c9a6-452a-8bb6-46a4ce8a8321',
            'msgTime': msgTime,
            'msg': msg
        }
        db.child("Users").child(key).child("Chat").child(msgTime).set(set_data)
        data = get_data(key)
        previous_data = data

    elif m_type == 'detect_changes':
        next_data = get_data(key)
        if not bool(previous_data):
            print("Previous Dict is empty")
            previous_data = next_data
            return json.dumps({'status': 'initialize'})
        else:
            if previous_data == next_data:
                print("Nothing Changes")
                return json.dumps({'status': 'nothing changed'})
            else:
                data = next_data
                previous_data = next_data
                print("Somthing changes")
    elif m_type == "refresh":
        data = get_data(key)
        previous_data = data

    return json.dumps(data)
コード例 #6
0
def get_data(key):
    if not isConnected():
        print("---------------------------Connection Error------------")
        return abort(404, description="Resource not found")
    print(key)
    tmp = db.child("Users").child(key).child("Chat").get()
    dicts = dict(tmp.val())
    print(dicts)
    return dicts
コード例 #7
0
ファイル: routes.py プロジェクト: shkhaider2015/IUSM
def admin_order():
    if not isConnected():
        print("---------------------------Connection Error------------")
        return abort(404, description="Resource not found")
    orders = db.child("Orders").get()
    objectList = list()
    for order in orders.each():
        print("Loop Runs ")
        print(order.val())
        objectList.append(dict(order.val()))
    print(objectList)
    objectList.reverse()
    return render_template("admin_order.html", objectList=objectList)
コード例 #8
0
ファイル: routes.py プロジェクト: shkhaider2015/IUSM
def admin_main():
    if not isConnected():
        print("---------------------------Connection Error------------")
        return abort(404, description="Resource not found")
    users = db.child("Users").get()
    userList = list()
    if users.val():
        for user in users.each():
            profile = user.val()
            data = profile['Profile']
            print("My data : " + str(data))
            userList.append(data)
    return render_template("admin_home_page.html", users=userList)
コード例 #9
0
def process_data():
    if request.method == 'POST':
        foodName = request.form['foodName']
        foodPrice = request.form['foodPrice']
        foodImage = request.files['foodImage']
        if foodImage and foodName and foodPrice:
            upload = storage.child("Foods/logos/" +
                                   secure_filename(foodImage.filename)).put(
                                       foodImage)
            filePath = downloadUri(foodImage, upload['downloadTokens'])
            if filePath:
                data = {
                    'foodName': foodName,
                    'foodPrice': foodPrice,
                    'foodImageUri': filePath
                }
                db.child("Foods").child(foodName).set(data)
                return redirect(url_for("foods.foods_list"))
            else:
                print("File Path Return empty")
        else:
            print("some data field may b empty")

    return render_template("foods_add.html")
コード例 #10
0
def availability(name, condition):
    pair = {'availability': condition}
    db.child("Foods").child(name).update(pair)