Skip to content

Commit

Permalink
views
Browse files Browse the repository at this point in the history
  • Loading branch information
davidism committed Feb 19, 2024
1 parent a8ea4a3 commit e981162
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/pallets/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def create_app() -> Flask:

db.init_app(app)

from . import models
from . import models, views

with app.app_context():
db.create_all()
Expand All @@ -35,6 +35,8 @@ def create_app() -> Flask:
},
)

app.register_blueprint(views.bp)

forwarded = app.config["FORWARDED"]

if forwarded["FOR"] > 0:
Expand Down
32 changes: 32 additions & 0 deletions src/pallets/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from flask import Blueprint
from flask import render_template

from . import db
from . import models

bp = Blueprint("core", __name__)


@bp.route("/", defaults={"path": ""})
@bp.route("/<path:path>/")
def page(path: str) -> str:
obj = db.get_or_404(models.Page, path)
return render_template([f"{path}.html", "page.html"], page=obj)


@bp.route("/people/<path>")
def person(path: str) -> str:
obj = db.get_or_404(models.Person, path)
return render_template("person.html", page=obj)


@bp.route("/p/<path>")
def project(path: str) -> str:
obj = db.get_or_404(models.Project, path)
return render_template("project.html", page=obj)


@bp.route("/blog/<path:path>")
def blog_post(path: str) -> str:
obj = db.get_or_404(models.BlogPost, path)
return render_template("blog.html", page=obj)

0 comments on commit e981162

Please sign in to comment.