def load_restaurants(): """Load restaurants from restaurants.txt into database.""" print("Restaurants") # Read restaurants.txt file and insert data for row in open("seed_data/restaurants.txt"): row = row.rstrip() id, name, street_address, city, state, zipcode, email, password = row.split( "|") restaurant = Restaurant(id=id, name=name, street_address=street_address, city=city, state=state, zipcode=zipcode, email=email) restaurant.set_password(password) # We need to add to the session or it won't ever be stored db.session.add(restaurant) # Once we're done, we should commit our work db.session.commit()
def process_restaurant_registration(): """Process restaurant registration.""" name = request.form.get("name") email = request.form.get("email") password = request.form.get("password") street_address = request.form.get("street-address") city = request.form.get("city") state = request.form.get("state") zipcode = request.form.get("zipcode") if Restaurant.query.filter_by(email=email).first(): flash("An account with this email already exists.") return redirect("/register") new_restaurant = Restaurant(name=name, email=email, street_address=street_address, city=city, state=state, zipcode=zipcode) new_restaurant.set_password(password) db.session.add(new_restaurant) db.session.commit() restaurant_id = new_restaurant.id # Log in new restaurant. session["restaurant_id"] = restaurant_id flash(f"Successfully registered {name}.") return redirect(f"/restaurant-dashboard/{restaurant_id}")