Skip to content

Commit

Permalink
Finished #12. All of the original project structure has been refactor…
Browse files Browse the repository at this point in the history
…ed to use Blueprints. All of the original routes.py are now split into the varying categories of Blueprint subdirectories.
  • Loading branch information
DeepBlockDeepak committed Nov 24, 2023
1 parent 519f5e7 commit 5e76965
Show file tree
Hide file tree
Showing 19 changed files with 350 additions and 354 deletions.
40 changes: 0 additions & 40 deletions main.py

This file was deleted.

16 changes: 8 additions & 8 deletions src/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from flask_login import LoginManager
from config import Config
from database import db # import the db instance
from src.views import welcome_page, not_found


def create_app():
Expand Down Expand Up @@ -30,15 +29,16 @@ def load_user(user_id):
# Register blueprints, routes, and error handlers
from .auth import auth as auth_bp
from .dashboard import dashboard as dashboard_bp
from .places import places as places_bp
from .travel import travel as travel_bp
from .user_profile import user_profile as user_profile_db
from .utility import utility as utility_db

app.register_blueprint(auth_bp)
app.register_blueprint(dashboard_bp)

app.add_url_rule("/", "welcome_page", welcome_page)
app.add_url_rule("/index", "welcome_page", welcome_page)
app.add_url_rule("/home", "welcome_page", welcome_page)

# Register error handlers
app.register_error_handler(404, not_found)
app.register_blueprint(places_bp)
app.register_blueprint(travel_bp)
app.register_blueprint(user_profile_db)
app.register_blueprint(utility_db)

return app
6 changes: 4 additions & 2 deletions src/auth/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def login():
# Redirect already authenticated users to the home page
if current_user.is_authenticated:
flash("You are already logged in.")
return redirect(url_for("welcome_page"))
return redirect(url_for("utility.welcome_page"))

# Create and process the login form
form = LoginForm(csrf_enabled=False)
Expand All @@ -30,7 +30,9 @@ def login():
# Redirect to the requested page or to the user's profile
next_page = request.args.get("next")
flash(f"Welcome back, {user.username}!")
return redirect(next_page or url_for("profile", user_id=user.id))
return redirect(
next_page or url_for("user_profile.profile", user_id=user.id)
)
flash("Invalid username or password.")

return render_template("login.html", form=form)
Expand Down
5 changes: 5 additions & 0 deletions src/places/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from flask import Blueprint

places = Blueprint("places", __name__)

from . import routes
32 changes: 32 additions & 0 deletions src/places/routes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import json
from flask import render_template
from flask_login import login_required
from src.models import Place
from src.places import places
from src.scraping_functions.wiki_places import get_main_image


# Renders page detailing the Place()
# used for anchoring Place items within html
@places.route("/place_info/<int:place_id>", methods=["POST", "GET"])
@login_required
def place_info(place_id):
# get the unique place by id
place = Place.query.get(place_id)

try:
place_wiki = json.loads(place.wiki)
except json.decoder.JSONDecodeError:
place_wiki = json.dumps('{"error": "wiki not availble"}')

url_string = get_main_image(place.city, place.state)
if not url_string:
url_string = "https://en.wikipedia.org/static/images/icons/wikipedia.png"

# render the place template
return render_template(
"place.html",
place=place,
wiki_content=place_wiki,
url_string=url_string,
)
Loading

0 comments on commit 5e76965

Please sign in to comment.