コード例 #1
0
ファイル: app.py プロジェクト: davidleecodes/Capstone1
def get_pet():
    """return pet with id"""
    token = get_token()
    id = request.json.get("id")
    # print(id)
    resp = requests.get(f" https://api.petfinder.com/v2/animals/{id}",
                        headers={"Authorization": f"Bearer {token}"})
    rating = Booking.avg_rating(id=id)
    resp_json = resp.json()
    resp_json["rating"] = rating
    # print(resp_json)
    return jsonify(resp_json)
コード例 #2
0
    def test_avg_rating(self):

        b1 = Booking(pet_id=48038022,
                     renter_id=self.rid1,
                     startTime="2020-5-25",
                     endTime="2020-5-26",
                     rating=2)

        b2 = Booking(pet_id=48038022,
                     renter_id=self.rid1,
                     startTime="2020-6-25",
                     endTime="2020-6-26",
                     rating=4)

        db.session.add(b1)
        db.session.add(b2)
        db.session.commit()

        rating = Booking.avg_rating(id=48038022)
        self.assertEqual(rating, 3)
コード例 #3
0
ファイル: app.py プロジェクト: davidleecodes/Capstone1
def pet(pet_id):
    "return pet page"
    form = PetForm()
    rating = Booking.avg_rating(id=pet_id)
    if not g.renter:
        flash("Sign in", "danger")
        return render_template("pet.html", id=pet_id)
    booked_dates = Booking.booked_dates(id=pet_id)
    print("_____BOOKED", booked_dates)

    if form.validate_on_submit():
        isAvaliable = Booking.is_avaliable(id=pet_id,
                                           start=form.start_date.data,
                                           end=form.end_date.data)
        print("ISAVALIABLE", isAvaliable)
        if isAvaliable:
            booking = Booking(pet_id=pet_id,
                              renter_id=g.renter.id,
                              startTime=form.start_date.data,
                              endTime=form.end_date.data)
            db.session.add(booking)
            db.session.commit()
            print("____red")
            return redirect(f"/renter")
        else:
            flash("already booked pick another date", "danger")
            return render_template("pet.html",
                                   id=pet_id,
                                   form=form,
                                   rating=rating,
                                   booked=booked_dates)
    else:
        return render_template("pet.html",
                               id=pet_id,
                               form=form,
                               rating=rating,
                               booked=booked_dates)