feat/flask: total rework and finalization
- Finished all locale pages - Updated styles, fixed some mobile problems - Updated texts on index page - Fixed flask locales search error, now it throws 404 - Something else, that I already forgot
This commit is contained in:
@@ -1,9 +1,16 @@
|
||||
import os
|
||||
from os import path, listdir
|
||||
from datetime import date
|
||||
from configparser import ConfigParser
|
||||
|
||||
from flask import Flask, render_template, url_for, redirect
|
||||
|
||||
from flask import (
|
||||
Flask,
|
||||
abort,
|
||||
redirect,
|
||||
render_template,
|
||||
request,
|
||||
send_from_directory,
|
||||
url_for,
|
||||
)
|
||||
|
||||
cp = ConfigParser()
|
||||
app = Flask(__name__)
|
||||
@@ -11,32 +18,65 @@ app = Flask(__name__)
|
||||
|
||||
def load_all_locales():
|
||||
locales = {}
|
||||
locales_dir = 'locales'
|
||||
for filename in os.listdir(locales_dir):
|
||||
if filename.endswith('.ini'):
|
||||
lang = os.path.splitext(filename)[0]
|
||||
locales_dir = "locales"
|
||||
|
||||
for filename in listdir(locales_dir):
|
||||
if filename.endswith(".ini"):
|
||||
lang = path.splitext(filename)[0]
|
||||
cp = ConfigParser()
|
||||
with open(os.path.join(locales_dir, filename), encoding='utf-8') as f:
|
||||
with open(path.join(locales_dir, filename), encoding="utf-8") as f:
|
||||
cp.read_file(f)
|
||||
locales[lang] = {section: dict(cp[section]) for section in cp.sections()}
|
||||
|
||||
return locales
|
||||
|
||||
|
||||
locales = load_all_locales()
|
||||
|
||||
|
||||
@app.route("/favicon.ico")
|
||||
def favicon():
|
||||
return send_from_directory(
|
||||
app.static_folder,
|
||||
"favicon.ico",
|
||||
mimetype="image/vnd.microsoft.icon"
|
||||
)
|
||||
|
||||
|
||||
@app.route("/")
|
||||
def home():
|
||||
return redirect(url_for("index", lang="en"))
|
||||
|
||||
|
||||
@app.route("/<lang>")
|
||||
def index(lang):
|
||||
return render_template(f'{lang}.html', locale=locales[lang], lang=lang, year=date.today().year) # TODO: Check for vulnerability
|
||||
|
||||
if lang not in locales:
|
||||
abort(404)
|
||||
|
||||
return render_template(
|
||||
f"{lang}.html",
|
||||
locale=locales[lang],
|
||||
lang=lang,
|
||||
year=date.today().year,
|
||||
current=request.endpoint,
|
||||
)
|
||||
|
||||
|
||||
@app.route("/<lang>/download")
|
||||
def download_page(lang):
|
||||
return render_template('tmpl/download.htm', locale=locales[lang], lang=lang, year=date.today().year)
|
||||
|
||||
if lang not in locales:
|
||||
abort(404)
|
||||
|
||||
return render_template(
|
||||
"tmpl/download.htm",
|
||||
locale=locales[lang],
|
||||
lang=lang,
|
||||
year=date.today().year,
|
||||
current=request.endpoint,
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
app.run(host="0.0.0.0", debug=True)
|
||||
|
||||
Reference in New Issue
Block a user