Exemplo n.º 1
0
def initdb():
    try:
        db.create_all()
    except:
        db.drop_all()
    # add some records
    try:
        admin_pass = generate_password_hash("admin", method="sha1", salt_length=8)
        guest_pass = generate_password_hash("guest", method="sha1", salt_length=8)
        admin = User("admin", admin_pass, "*****@*****.**")
        guest = User("guest", guest_pass, "*****@*****.**")
        # save them into database
        admin.store_to_db()
        flash("user admin added")
        guest.store_to_db()
        flash("user guest added")
    except:
        flash("create User table failed.", "error")

    try:
        todo1 = Todo("check in code", "modify reset")
        todo2 = Todo("talk with somebody", "about cloud")
        todo1.store_to_db()
        flash("todo #1 added")
        todo2.store_to_db()
        flash("todo #2 added")
    except:
        flash("create Todo table failed.", "error")

    try:
        wiki1 = Wiki("MainPage", "wikitest")
        wiki2 = Wiki("Sandbox", "wikitest")
        wiki1.store_to_db()
        flash("wiki #1 added")
        wiki2.store_to_db()
        flash("wiki #2 added")
    except:
        flash("create Wiki table failed.", "error")
    return redirect(url_for("index"))
Exemplo n.º 2
0
def dropdb():
    db.drop_all()
    flash("drop database ok")
    return redirect(url_for("index"))