-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path__init__.py
More file actions
75 lines (63 loc) · 1.98 KB
/
__init__.py
File metadata and controls
75 lines (63 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import os
from werkzeug.routing import PathConverter
from flask import (
Flask, redirect, render_template,
request, send_from_directory, url_for
)
from .lookup import lookup, random_key
from .lookup.charutils import roman
from .lookup.table import Multitable
class Query(PathConverter):
regex = ".*?" # everything PathConverter accepts but also leading slashes
app = Flask(__name__)
app.url_map.converters["query"] = Query
@app.route("/")
def index():
return render_template("index.html")
#roman_dict = {letter: digit for digit, letter in enumerate(roman)}
@app.route("/lookup/<query:word>")
def results(word):
input_yat = request.args.get("in") or "e"
output_yat = request.args.get("out") or "e"
par = request.args.get("par") or None
subpar = request.args.get("subpar") or None
tables = lookup(word, input_yat, output_yat)
if par:
tables = [t for t in tables if t.caption.par == par]
if subpar:
tables = [t for t in tables if t.caption.subpar == subpar]
return render_template(
"results.html",
tables=Multitable(word, tables),
input_yat=input_yat,
output_yat=output_yat
)
else:
return render_template(
"results.html",
tables=tables,
input_yat=input_yat,
output_yat=output_yat
)
@app.errorhandler(404)
def page_not_found(_):
return render_template("404.html"), 404
@app.route("/random")
def random():
word, yat = random_key()
if yat == "je":
kwargs = {"word": word, "in": "ije", "out": "je"}
# because input doesn't differentiate between what we call jekav and ijekav
else: # e or ije
kwargs = {"word": word, "in": yat, "out": yat}
return redirect(url_for("results", **kwargs))
@app.route("/about")
def about():
return render_template("about.html")
@app.route("/favicon.ico")
def favicon():
return send_from_directory(
os.path.join(app.root_path, "static"),
"favicon.ico",
mimetype="image/vnd.microsoft.icon"
)