def create_data():
    """Function to create and set up DB and populate with data."""

    global SESSION
    SESSION = establish_session()

    # Query for restaurant list. If none exist, create via prefab data.
    all_restaurants = SESSION.query(Restaurant).all()
    if len(all_restaurants) < 1:
        import prefab_db_data
        prefab_db_data.create_all_the_things(SESSION)
        all_restaurants = SESSION.query(Restaurant).all()
Beispiel #2
0
"""
This module provides logic for returning views for the Restaurant project.
"""

#pylint: disable=relative-import,invalid-name,import-error

from flask import Flask, render_template, url_for
from flask import redirect, request, flash, jsonify
from database_utils import establish_session, get_or_create
from models import Restaurant, MenuItem

SESSION = establish_session()

# Create instance of Flask class
app = Flask(__name__)

# Including '/' so the main directory gets a valid response, not a 404.
# Using <> makes dynamic URLs possible, substituting var name as part of URL.
# Ex: "path/<type:var_name>/path" -- where "type" can be int, string, or path.
@app.route('/')
@app.route('/restaurants/')
def all_restaurants():
    """Function to return full list of Restaurants."""

    restaurants = SESSION.query(Restaurant).all()
    return render_template('restaurant_list.html', restaurants=restaurants)


@app.route('/restaurant/new/', methods=['GET', 'POST'])
def new_restaurant():
    """Function to return a page to add a new restaurant."""