Initial commit

This commit is contained in:
David Carmichael
2024-02-11 21:59:18 +00:00
commit 9687db5a96
79 changed files with 9092 additions and 0 deletions

57
app/resources/cli/cli.py Normal file
View File

@@ -0,0 +1,57 @@
from quart import current_app as app
from app.extensions import db
from app.models.example_user_table import ExampleUserTable
@app.cli.command("config")
async def create_tables():
print(app.config)
@app.cli.command("create-tables")
async def create_tables():
db.create_all()
@app.cli.command("get-example-user")
async def get_example_user():
result = ExampleUserTable.get_by_id(1)
if not result:
print("User not found.")
return
print(
f"""
user_id: {result.user_id}
username: {result.username}
salt: {result.salt}
password: {result.password}
private_key: {result.private_key}
disabled: {result.disabled}
"""
)
@app.cli.command("create-example-user")
async def add_example_user():
ExampleUserTable.create(
username="admin",
password="password",
disabled=False,
)
@app.cli.command("update-example-user")
async def update_example_user():
ExampleUserTable.update(
user_id=1,
username="admin-updated",
private_key="private_key",
disabled=False,
)
@app.cli.command("delete-example-user")
async def delete_example_user():
ExampleUserTable.delete(
user_id=1,
)

View File

@@ -0,0 +1,14 @@
from quart import current_app as app
@app.context_processor
async def example__utility_processor():
"""
Usage:
{{ format_price(100.33) }} -> $100.33
"""
async def example__format_price(amount, currency='$'):
return '{1}{0:.2f}'.format(amount, currency)
return dict(format_price=example__format_price)

View File

@@ -0,0 +1,44 @@
from quart import current_app as app
from quart import render_template
@app.errorhandler(400)
async def error_400(error):
return await render_template(
"errors/400.html",
), 400
@app.errorhandler(401)
async def error_401(error):
return await render_template(
"errors/401.html",
), 401
@app.errorhandler(403)
async def error_403(error):
return await render_template(
"errors/403.html",
), 403
@app.errorhandler(404)
async def error_404(error):
return await render_template(
"errors/404.html",
), 404
@app.errorhandler(405)
async def error_405(error):
return await render_template(
"errors/405.html",
), 405
@app.errorhandler(500)
async def error_500(error):
return await render_template(
"errors/500.html",
), 500

View File

@@ -0,0 +1,30 @@
from quart import current_app as app
@app.template_filter('example__num_to_month')
async 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"

View File

@@ -0,0 +1,7 @@
from quart import current_app as app
from quart import render_template
@app.route("/resources")
async def index():
return await render_template("index.html")

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

View File

@@ -0,0 +1,11 @@
<!doctype html>
<html lang="en">
<head>
<title>400 Bad Request</title>
</head>
<body>
<p>It's not us, it's you.</p>
</body>
</html>

View File

@@ -0,0 +1,11 @@
<!doctype html>
<html lang="en">
<head>
<title>401 Unauthorized</title>
</head>
<body>
<p>You lack valid authentication credentials for the requested resource</p>
</body>
</html>

View File

@@ -0,0 +1,11 @@
<!doctype html>
<html lang="en">
<head>
<title>403 Forbidden</title>
</head>
<body>
<p>Access forbidden!</p>
</body>
</html>

View File

@@ -0,0 +1,11 @@
<!doctype html>
<html lang="en">
<head>
<title>404 Page Not Found</title>
</head>
<body>
<p>No route associated with the URL</p>
</body>
</html>

View File

@@ -0,0 +1,11 @@
<!doctype html>
<html lang="en">
<head>
<title>405 Method Not Allowed</title>
</head>
<body>
<p>Should of GET when you POST, or POST when you GET</p>
</body>
</html>

View File

@@ -0,0 +1,11 @@
<!doctype html>
<html lang="en">
<head>
<title>500 Server Error!</title>
</head>
<body>
<p>There has been a server error!</p>
</body>
</html>

View File

@@ -0,0 +1,12 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="'width=device-width, initial-scale=1.0'">
<title>Quart-Imp Global Template</title>
<link rel="icon" href="{{ url_for('static', filename='favicon.ico') }}" sizes="16x16 32x32" type="image/x-icon">
</head>
<body>
<p>This is the example resources template file located in <code>resources/templates/index.html</code></p>
</body>