コード例 #1
0
def add_cafe():
    form = CafeForm(request.form)
    if request.method == "GET":
        return render_template("cafeform.html",
                               form=form,
                               formtype="Add",
                               current_user=current_user)
    if request.method == "POST" and form.validate_on_submit():
        # Add cafe
        cafe = Cafe()
        cafe.name = form.data["name"]
        cafe.location = form.data["location"]
        db.session.add(cafe)
        db.session.commit()
        write_to_events("created", "cafe", cafe.id)
        flash("Cafe added", "success")
        return redirect(url_for("view_cafe", cafeid=cafe.id))
    else:
        for field, errors in form.errors.items():
            flash("Error in %s: %s" % (field, "; ".join(errors)), "danger")
        return render_template("cafeform.html",
                               form=form,
                               formtype="Add",
                               current_user=current_user)
    return redirect(url_for("home"))
コード例 #2
0
ファイル: tests.py プロジェクト: taybenlor/ncss-coffeerun
 def test_run_calculate_cost_total(self):
     # Set up cafe with menu
     cafe = Cafe()
     db.session.add(cafe)
     db.session.commit()
     price1 = Price(cafe.id, "S")
     price1.amount = 1.4
     price1.cafe = cafe
     price2 = Price(cafe.id, "M")
     price2.amount = 2.5
     price2.cafe = cafe
     db.session.add(price1)
     db.session.add(price2)
     db.session.commit()
     # Create run and add some coffees
     run = Run(datetime.utcnow())
     db.session.add(run)
     db.session.commit()
     coffee1 = Coffee("Latte")
     coffee1.price = price1
     coffee1.run = run
     coffee2 = Coffee("Cappuccino")
     coffee2.price = price2
     coffee2.run = run
     coffee3 = Coffee("Mocha")
     coffee3.price = price1
     coffee3.run = run
     coffee3.paid = True
     db.session.add(coffee1)
     db.session.add(coffee2)
     db.session.add(coffee3)
     db.session.commit()
     # Calculate total price of run
     total = run.calculateTotalRunCost()
     assert total == 3.9
コード例 #3
0
ファイル: tests.py プロジェクト: taybenlor/ncss-coffeerun
 def test_add_cafe(self):
     cafe = Cafe()
     db.session.add(cafe)
     db.session.commit()
     assert cafe in db.session
     db.session.remove(cafe)
     db.session.commit()
     assert cafe not in db.session
コード例 #4
0
ファイル: tests.py プロジェクト: taybenlor/ncss-coffeerun
 def test_run_has_cafe(self):
     cafe = Cafe()
     db.session.add(cafe)
     db.session.commit()
     run = Run(datetime.utcnow())
     run.cafe = cafe
     db.session.add(run)
     db.session.commit()
     assert run in cafe.runs
コード例 #5
0
ファイル: create_db.py プロジェクト: miscoined/ncss-coffeerun
def main():
    db.drop_all()
    db.init_app(app)
    db.create_all()

    db.session.add(Cafe('ABS', 'Sydney Uni: Business School'))
    db.session.add(Cafe('Cafe Ella', '274 Abercrombie St, Darlington'))
    db.session.add(Cafe('Campos', 'Newtown'))
    db.session.add(
        Cafe('Taste Baguette (CPC)', 'Sydney Uni: Charles Perkins Centre'))
    db.session.add(Cafe('Taste Baguette (Law)', 'Sydney Uni: Law Building'))
    db.session.add(Cafe('The Shortlist', '258 Abercrombie St, Darlington'))
    db.session.add(Cafe('Toby\'s Estate', 'City Rd'))

    db.session.commit()
コード例 #6
0
ファイル: tests.py プロジェクト: taybenlor/ncss-coffeerun
 def test_user_owes_money_to_person(self):
     # Set up cafe with menu
     cafe = Cafe()
     db.session.add(cafe)
     db.session.commit()
     price1 = Price(cafe.id, "S")
     price1.amount = 1.4
     price1.cafe = cafe
     price2 = Price(cafe.id, "M")
     price2.amount = 2.5
     price2.cafe = cafe
     db.session.add(price1)
     db.session.add(price2)
     db.session.commit()
     # Create run and add some coffees
     run = Run(datetime.utcnow())
     user1 = User()
     user2 = User()
     run.fetcher = user2
     db.session.add(user1)
     db.session.add(user2)
     db.session.add(run)
     db.session.commit()
     coffee1 = Coffee("Latte")
     coffee1.price = price1
     coffee1.run = run
     coffee2 = Coffee("Cappuccino")
     coffee2.price = price2
     coffee2.run = run
     coffee2.addict = user1
     coffee3 = Coffee("Mocha")
     coffee3.price = price1
     coffee3.run = run
     coffee3.paid = True
     coffee3.addict = user1
     db.session.add(coffee1)
     db.session.add(coffee2)
     db.session.add(coffee3)
     db.session.commit()
     amount = user1.moneyOwedPerson(user2)
     assert amount == 2.5
コード例 #7
0
ファイル: create_db.py プロジェクト: rowena-s/ncss-coffeerun
from application import app, db
from application.models import Cafe

db.drop_all()
db.init_app(app)
db.create_all()

db.session.add(Cafe('Toby\'s Estate', 'City Rd'))
db.session.add(Cafe('Campos', 'Newtown'))
db.session.add(Cafe('Twenty 8 Acres', 'Ivy Ln, Darlington'))
db.session.add(Cafe('Taste Baguette', 'Sydney Uni Law Building'))

db.session.commit()