示例#1
0
def add_food():
    if request.method() == "GET":
        if request.args:

            if "user_id" in args:

                user_id = args["user_id"]

                eat_time = str(datetime.now())
                all_food_eaten = (
                    f"MATCH (u: user), (f: food) WHERE u.id = {user_id} AND (u)-[:ATE]->(f) RETURN collect(f)"
                )

                # Above query (beautified):
                # MATCH (u: User), (f: food)
                # WHERE u.id = {user_id} AND (u)-[:ATE]->(f)
                # RETURN collect(f)

                with db_driver.session() as session:
                    result = session.run(all_food_eaten)

                return result, 201

    elif request.method() == "POST":
        if request.args:

            if "user_id" in args:
                if "food_id" in args:
                    if "meal_type" in args:

                        user_id = args["user_id"]
                        food_id = args["food_id"]
                        meal_type = args["meal_type"]

                        eat_time = str(datetime.now())
                        new_food_eaten = (
                            f"MATCH (u: user), (f: food) WHERE u.id = {user_id} AND f.id = {food_id} CREATE (u)-[:ATE {{timestamp: {eat_time}, meal: {meal_type}}}]->(f)"
                        )

                        # Above query (beautified):
                        # MATCH (u: User), (f: food)
                        # WHERE u.id = {user_id} AND f.id = {food_id}
                        # CREATE (u)-[:ATE {{timestamp: {eat_time}, meal: {meal_type}}}]->(f)

                        with db_driver.session() as session:
                            session.run(new_food_eaten)

                        return '', 201
示例#2
0
def like(post_id):
    if request.method("POST"):
        likes = Likes(current_user.id, post_id)
        db.session.add(likes)
        db.session.commit()
        currentlikes = (Likes.query.filter_by(post_id=post_id).first()).user_id.count()
        likesmessage = {
            "message": "Post liked!",
            "likes": currentlikes
        }
        return jsonify(likesmessage=likesmessage)
示例#3
0
def api_items():
    if request.method =="GET":
        print(request.method)
        items =[]
        for item in Item.objects:
            items.append(item)
        #print(items)
        return make_response(jsonify(items),200)

    elif request.method=="POST":
        content = request.json()
        item= Item(item_id=content['item_id'],name=content['name'],seller=content['seller'],price=content['price'])
        item.save()
        return request.method(" ",201)
示例#4
0
def sell():
    if request.method("POST"):
        if request.form.get("symbol") == None:
            return apology("Provide a stock.")
        else:
            quote = lookup(request.form.get("symbol"))
            if quote == None:
                return apology("This is not a stock.")
        if request.form.get("shares") == None:
            return apology("Tell us your shares.")
        else:
            shares = request.form.get("shares")
            cash = db.execute("SELECT cash FROM users WHERE id = :id",
                              id=session["user_id"])[0]["cash"]
            if quote["price"] * float(shares) < 0 or quote["price"] * float(
                    shares) == 0:
                return apology(
                    "This number is too low. We can not sell this amount.")
    else:
        return render_template("sell.html")
示例#5
0
def profile():
    """Render the website's add profile page."""
    form = forms.ProfileForm()
    if request.method() == 'POST':
        if form.validate_on_submit():
            firstname = form.firstname.data
            lastname = form.lastname.data
            email = form.email.data
            location = form.location.data
            gender = form.gender.data
            biography = form.biography.data

            photo = form.photo.data
            filename = secure_filename(photo.filename)

            if not re.match(r'.*\.(jpg|png|jpeg)$', filename):
                flash("Invalid file. File must have .jpg/.png/.jpeg extension")
                flash_errors(form)
                return render_template('profile.html', form=form)

            profile = Profile(firstname,
                              lastname,
                              email,
                              location,
                              gender,
                              biography,
                              created_on=date_joined())

            db.session.add(profile)
            db.session.commit()

            form.save(
                os.path.join(app.config['UPLOAD_FOLDER'],
                             str(profile.id) + "_" + filename))

            flash("Profile successfully created")
            return redirect(url_for('profiles'))

        flash_errors(form)
        return render_template('profile.html', form=form)
示例#6
0
def add_food():
    if request.method() == "GET":
        if request.args:

            if "user_id" in args:

                user_id = args["user_id"]

                eat_time = str(datetime.now())
                all_food_liked = (
                    f"MATCH (u: user), (f: food) WHERE u.id = {user_id} AND (u)-[:LIKES]->(f) RETURN collect(f)"
                )

                # Above query (beautified):
                # MATCH (u: User), (f: food)
                # WHERE u.id = {user_id} AND (u)-[:LIKES]->(f)
                # RETURN collect(f)

                with db_driver.session() as session:
                    result = session.run(all_food_liked)

                return result, 201

    elif request.method() == "POST":
        if request.args:

            if "user_id" in args:
                if "food_id" in args:

                    user_id = args["user_id"]
                    food_id = args["food_id"]

                    new_food_liked = (
                        f"MATCH (u: user), (f: food) WHERE u.id = {user_id} AND f.id = {food_id} CREATE (u)-[:LIKES]->(f)"
                    )

                    # Above query (beautified):
                    # MATCH (u: User), (f: food)
                    # WHERE u.id = {user_id} AND f.id = {food_id}
                    # CREATE (u)-[:LIKES]->(f)

                    with db_driver.session() as session:
                        session.run(new_food_liked)

                    return '', 201

    elif request.method() == "DELETE":
        if request.args:

            if "user_id" in args:
                if "food_id" in args:

                    user_id = args["user_id"]
                    food_id = args["food_id"]

                    food_deleted = (
                        f"MATCH (u: User)-[r:LIKES]->(f: food) WHERE u.id = {user_id} AND f.id = {food_id} DELETE r"
                    )

                    # Above query (beautified):
                    # MATCH (u: User)-[r:LIKES]->(f: food)
                    # WHERE u.id = {user_id} AND f.id = {food_id}
                    # DELETE r

                    with db_driver.session() as session:
                        session.run(food_deleted)

                    return '', 201
示例#7
0
def generate_prediction():
    if request.method() == "POST":
示例#8
0
def listarMaterialesp():
    if request.method():
        listarMateriales2(request.form['abreviatura'])
    return render_template("listarMaterialesp.html")
示例#9
0
文件: Methods.py 项目: Hexogenua/repo
def login():
    if request.method('POST'):
        return do_the_login()
    else:
        return show_the_login_from()