Skip to content

Commit

Permalink
Customizations
Browse files Browse the repository at this point in the history
  • Loading branch information
s2t2 committed Apr 25, 2024
1 parent 89a8574 commit 96bc93e
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 54 deletions.
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()
15 changes: 7 additions & 8 deletions app/models/login.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@

#from app.db import BaseModel
#
#class Login(BaseModel):
#
# SHEET_NAME = "logins"
#
# COLUMNS = ["email", "verified", "first_name", "last_name", "profile_photo_url"]
#
from app.db import BaseModel

class Login(BaseModel):

SHEET_NAME = "logins"

COLUMNS = ["email", "verified", "first_name", "last_name", "profile_photo_url"]
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
16 changes: 8 additions & 8 deletions web_app/routes/auth_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from flask import session, flash, redirect, current_app
from flask import Blueprint, session, redirect, url_for, render_template #request, , , jsonify

#from app.models.login import Login
from app.models.login import Login

auth_routes = Blueprint("auth_routes", __name__)

Expand Down Expand Up @@ -49,13 +49,13 @@ def google_oauth_callback():
session["current_user"] = user_info

# consider storing the user login info in the database:
#Login.create({
# "email": user_info["email"],
# "verified": user_info["email_verified"],
# "first_name": user_info["given_name"],
# "last_name": user_info["family_name"],
# "profile_photo_url": user_info["picture"],
#})
Login.create({
"email": user_info["email"],
"verified": user_info["email_verified"],
"first_name": user_info["given_name"],
"last_name": user_info["family_name"],
"profile_photo_url": user_info["picture"],
})

else:
print("NO USER INFO")
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)
27 changes: 27 additions & 0 deletions web_app/templates/books.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{% 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 %}

<!--div class="container"-->
<ol>
{% for book in books %}
<li>{{ book.title }} | {{ book.author }}</li>
{% endfor %}
</ol>
<!--/div-->

{% else %}

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

{% endif %}

{% endblock %}
7 changes: 3 additions & 4 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-success">
<div class="container-fluid">
<a class="navbar-brand" href="/">
<!--
Expand Down

0 comments on commit 96bc93e

Please sign in to comment.