Skip to content

Commit

Permalink
feat: docs fixed, cli overhaul
Browse files Browse the repository at this point in the history
  • Loading branch information
CheeseCake87 committed Aug 5, 2024
1 parent 5c2d245 commit f1e6310
Show file tree
Hide file tree
Showing 94 changed files with 1,985 additions and 4,609 deletions.
10 changes: 6 additions & 4 deletions app_full/models/example_user_table.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from sqlalchemy import select, update, delete, insert

from app_full.extensions import db
from flask_imp.auth import authenticate_password
from flask_imp.auth import encrypt_password
from flask_imp.auth import generate_private_key
from flask_imp.auth import generate_salt
from flask_imp.auth import (
authenticate_password,
encrypt_password,
generate_private_key,
generate_salt,
)


class ExampleUserTable(db.Model):
Expand Down
6 changes: 6 additions & 0 deletions app_full/resources/cli/cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from flask import current_app as app


@app.cli.command("show-config")
def show_config():
print(app.config)
14 changes: 14 additions & 0 deletions app_full/resources/context_processors/context_processors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from flask import current_app as app


@app.context_processor
def example__utility_processor():
"""
Usage:
{{ example__format_price(100.33) }} -> $100.33
"""

def example__format_price(amount, currency='$'):
return '{1}{0:.2f}'.format(amount, currency)

return dict(example__format_price=example__format_price)
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,22 @@
from flask import render_template


@app.errorhandler(404)
def page_not_found(e):
@app.errorhandler(400)
def bad_request(e):
return render_template(
"error.html",
error_code=404,
error_message="The page you are looking for does not exist.",

), 404
error_code=400,
error_message="The request is invalid.",
), 400


@app.errorhandler(500)
def server_error(e):
@app.errorhandler(401)
def unauthorized(e):
return render_template(
"error.html",
error_code=500,
error_message="An internal server error has occurred.",
), 500
error_code=401,
error_message="You are not authorized to access this page.",
), 401


@app.errorhandler(403)
Expand All @@ -31,6 +30,25 @@ def forbidden(e):
), 403


@app.errorhandler(404)
def page_not_found(e):
return render_template(
"error.html",
error_code=404,
error_message="The page you are looking for does not exist.",

), 404


@app.errorhandler(405)
def method_not_allowed(e):
return render_template(
"error.html",
error_code=405,
error_message="The method is not allowed for the requested URL.",
), 405


@app.errorhandler(410)
def gone(e):
return render_template(
Expand All @@ -49,19 +67,10 @@ def too_many_requests(e):
), 429


@app.errorhandler(401)
def unauthorized(e):
return render_template(
"error.html",
error_code=401,
error_message="You are not authorized to access this page.",
), 401


@app.errorhandler(400)
def bad_request(e):
@app.errorhandler(500)
def server_error(e):
return render_template(
"error.html",
error_code=400,
error_message="The request is invalid.",
), 400
error_code=500,
error_message="An internal server error has occurred.",
), 500
30 changes: 30 additions & 0 deletions app_full/resources/filters/filters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from flask import current_app as app


@app.template_filter('example__num_to_month')
def example__num_to_month(num: str) -> str:
"""
Usage:
{{ 1 | example__num_to_month }} -> January
"""
if isinstance(num, int):
num = str(num)

months = {
"1": "January",
"2": "February",
"3": "March",
"4": "April",
"5": "May",
"6": "June",
"7": "July",
"8": "August",
"9": "September",
"10": "October",
"11": "November",
"12": "December",
}

if num in months:
return months[num]
return "Month not found"
6 changes: 6 additions & 0 deletions app_full/resources/routes/routes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from flask import current_app as app


@app.route("/example--resources")
def example_route():
return "From the [app_root]/resources/routes/routes.py file"
Loading

0 comments on commit f1e6310

Please sign in to comment.