Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example Customizations - Inclass Online #10

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 33 additions & 34 deletions app/models/book.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,34 @@

#from app.db import BaseModel
#
#class Book(BaseModel):
#
# SHEET_NAME = "books"
#
# COLUMNS = ["title", "author", "year"]
#
# SEEDS = [
# {"title": "To Kill a Mockingbird", "author": "Harper Lee", "year": 1960},
# {"title": "1984", "author": "George Orwell", "year": 1949},
# {"title": "The Great Gatsby", "author": "F. Scott Fitzgerald", "year": 1925},
# {"title": "The Catcher in the Rye", "author": "J.D. Salinger", "year": 1951},
# {"title": "Pride and Prejudice", "author": "Jane Austen", "year": 1813},
# {"title": "To the Lighthouse", "author": "Virginia Woolf", "year": 1927},
# {"title": "The Hobbit", "author": "J.R.R. Tolkien", "year": 1937},
# {"title": "Moby-Dick", "author": "Herman Melville", "year": 1851},
# {"title": "Brave New World", "author": "Aldous Huxley", "year": 1932},
# {"title": "Alice's Adventures in Wonderland", "author": "Lewis Carroll", "year": 1865},
# {"title": "Harry Potter and the Philosopher's Stone", "author": "J.K. Rowling", "year": 1997},
# {"title": "Harry Potter and the Chamber of Secrets", "author": "J.K. Rowling", "year": 1998},
# ]
#
#
#if __name__ == "__main__":
#
# books = Book.all()
# print("FOUND", len(books), "BOOKS")
# if any(books):
# for book in books:
# print(book.title, book.author, book.year)
# else:
# Book.seed()
#
from app.db import BaseModel

class Book(BaseModel):

SHEET_NAME = "books"

COLUMNS = ["title", "author", "year"]

SEEDS = [
{"title": "To Kill a Mockingbird", "author": "Harper Lee", "year": 1960},
{"title": "1984", "author": "George Orwell", "year": 1949},
{"title": "The Great Gatsby", "author": "F. Scott Fitzgerald", "year": 1925},
{"title": "The Catcher in the Rye", "author": "J.D. Salinger", "year": 1951},
{"title": "Pride and Prejudice", "author": "Jane Austen", "year": 1813},
{"title": "To the Lighthouse", "author": "Virginia Woolf", "year": 1927},
{"title": "The Hobbit", "author": "J.R.R. Tolkien", "year": 1937},
{"title": "Moby-Dick", "author": "Herman Melville", "year": 1851},
{"title": "Brave New World", "author": "Aldous Huxley", "year": 1932},
{"title": "Alice's Adventures in Wonderland", "author": "Lewis Carroll", "year": 1865},
{"title": "Harry Potter and the Philosopher's Stone", "author": "J.K. Rowling", "year": 1997},
{"title": "Harry Potter and the Chamber of Secrets", "author": "J.K. Rowling", "year": 1998},
]


if __name__ == "__main__":

books = Book.all()
print("FOUND", len(books), "BOOKS")
if any(books):
for book in books:
print(book.title, book.author, book.year)
else:
Book.seed()
2 changes: 2 additions & 0 deletions web_app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from web_app.routes.user_routes import user_routes
from web_app.routes.product_routes import product_routes
from web_app.routes.order_routes import order_routes
from web_app.routes.book_routes import book_routes

load_dotenv()

Expand Down Expand Up @@ -70,6 +71,7 @@ def create_app():
app.register_blueprint(user_routes)
app.register_blueprint(product_routes)
app.register_blueprint(order_routes)
app.register_blueprint(book_routes)

return app

Expand Down
10 changes: 10 additions & 0 deletions web_app/routes/book_routes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from flask import Blueprint, render_template, current_app #, session

from app.models.book import Book

book_routes = Blueprint("book_routes", __name__)

@book_routes.route("/books")
def books():
books = Book.all()
return render_template("books.html", books=books)
1 change: 1 addition & 0 deletions web_app/templates/about.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ <h1>About</h1>

<p>Here is some more info!</p>

<p>More stuff</p>
{% endblock %}
26 changes: 26 additions & 0 deletions web_app/templates/books.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{% extends "bootstrap_5_layout.html" %}
{% set page_title = "Books Page" %}
{% set active_page = "books" %}

{% block content %}

<h1>Books</h1>

<p class="lead">This is the books page</p>

{% if books|length > 0 %}

<ul>
{% for book in books %}
<li>{{ book.title }} | {{ book.author }} </li>
{% endfor %}
</ul>
<!--/div-->

{% else %}

<p>Oops, no books found.</p>

{% endif %}

{% endblock %}
9 changes: 4 additions & 5 deletions web_app/templates/bootstrap_5_layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,13 @@
-->
{% set public_nav = [
('/about', 'about', 'About'),
('/products', 'products', 'Products'),
('/books', 'books', 'Books'),
('/login', 'login', 'Login'),
] -%}

{% set protected_nav = [
('/about', 'about', 'About'),
('/products', 'products', 'Products'),
('/user/orders', 'user_orders', 'Orders'),
('/books', 'books', 'Books'),
] -%}

<!--
Expand All @@ -100,7 +99,7 @@
https://getbootstrap.com/docs/5.1/customize/color/#theme-colors
-->

<nav class="navbar navbar-expand-lg navbar-dark bg-primary">
<nav class="navbar navbar-expand-lg navbar-dark bg-danger">
<div class="container-fluid">
<a class="navbar-brand" href="/">
<!--
Expand Down Expand Up @@ -177,7 +176,7 @@
<div class="row">
<div class="col-sm-6" style="display: inline; margin-bottom: 5px;">
<p class="small">
&copy; Copyright 2024 Your Name Here
&copy; Copyright 2024 MY NAME
</p>
<p class="small white-space: nowrap;">
Made with the <a href="https://github.com/prof-rossetti/flask-sheets-template-2024">Flask Sheets Template 2024</a>
Expand Down
2 changes: 2 additions & 0 deletions web_app/templates/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ <h1>Home</h1>

<p>Here is some more info!</p>


<p>Here's some more stuff</p>
{% endblock %}
Loading