mirror of
https://github.com/Casvt/MIND.git
synced 2026-02-19 11:54:46 -05:00
Refactored ui.py
This commit is contained in:
@@ -9,53 +9,58 @@ from flask import Blueprint, render_template, send_file
|
||||
from backend.internals.server import Server
|
||||
|
||||
ui = Blueprint('ui', __name__)
|
||||
methods = ['GET']
|
||||
|
||||
|
||||
def render(filename: str, **kwargs: Any) -> str:
|
||||
return render_template(filename, url_prefix=Server.url_prefix, **kwargs)
|
||||
|
||||
|
||||
@ui.route('/manifest.json', methods=methods)
|
||||
@ui.route('/manifest.json')
|
||||
def ui_manifest():
|
||||
return send_file(
|
||||
BytesIO(dumps(
|
||||
# autopep8: off
|
||||
manifest = {
|
||||
"name": "MIND",
|
||||
"short_name": "MIND",
|
||||
"description":
|
||||
"MIND is a simple self hosted reminder application that can send "
|
||||
"push notifications to your device. Set the reminder and forget "
|
||||
"about it!",
|
||||
"display": "standalone",
|
||||
"orientation": "portrait-primary",
|
||||
"start_url": f"{Server.url_prefix}/",
|
||||
"scope": f"{Server.url_prefix}/",
|
||||
"id": f"{Server.url_prefix}/",
|
||||
"background_color": "#1b1b1b",
|
||||
"theme_color": "#6b6b6b",
|
||||
"icons": [
|
||||
{
|
||||
"name": "MIND",
|
||||
"short_name": "MIND",
|
||||
"description": "MIND is a simple self hosted reminder application that can send push notifications to your device. Set the reminder and forget about it!",
|
||||
"display": "standalone",
|
||||
"orientation": "portrait-primary",
|
||||
"start_url": f"{Server.url_prefix}/",
|
||||
"scope": f"{Server.url_prefix}/",
|
||||
"id": f"{Server.url_prefix}/",
|
||||
"background_color": "#1b1b1b",
|
||||
"theme_color": "#6b6b6b",
|
||||
"icons": [
|
||||
{
|
||||
"src": f"{Server.url_prefix}/static/img/favicon.svg",
|
||||
"type": "image/svg+xml",
|
||||
"sizes": "any"
|
||||
}
|
||||
]
|
||||
},
|
||||
indent=4
|
||||
).encode('utf-8')),
|
||||
"src": f"{Server.url_prefix}/static/img/favicon.svg",
|
||||
"type": "image/svg+xml",
|
||||
"sizes": "any"
|
||||
}
|
||||
]
|
||||
}
|
||||
# autopep8: on
|
||||
|
||||
return send_file(
|
||||
BytesIO(
|
||||
dumps(manifest, indent=4).encode('utf-8')
|
||||
),
|
||||
mimetype="application/manifest+json",
|
||||
download_name="manifest.json"
|
||||
), 200
|
||||
|
||||
|
||||
@ui.route('/', methods=methods)
|
||||
@ui.route('/')
|
||||
def ui_login():
|
||||
return render('login.html')
|
||||
|
||||
|
||||
@ui.route('/reminders', methods=methods)
|
||||
@ui.route('/reminders')
|
||||
def ui_reminders():
|
||||
return render('reminders.html')
|
||||
|
||||
|
||||
@ui.route('/admin', methods=methods)
|
||||
@ui.route('/admin')
|
||||
def ui_admin():
|
||||
return render('admin.html')
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
import unittest
|
||||
|
||||
from flask import Blueprint, Flask
|
||||
|
||||
from frontend.ui import methods, ui
|
||||
|
||||
|
||||
class Test_UI(unittest.TestCase):
|
||||
def test_methods(self):
|
||||
self.assertEqual(len(methods), 1)
|
||||
self.assertEqual(methods[0], 'GET')
|
||||
|
||||
def test_blueprint(self):
|
||||
self.assertIsInstance(ui, Blueprint)
|
||||
|
||||
def test_route_methods(self):
|
||||
temp_app = Flask(__name__)
|
||||
temp_app.register_blueprint(ui)
|
||||
for rule in temp_app.url_map.iter_rules():
|
||||
self.assertEqual(len(rule.methods or []), 3)
|
||||
self.assertIn(methods[0], rule.methods or [])
|
||||
Reference in New Issue
Block a user