-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
73 lines (57 loc) · 1.87 KB
/
main.py
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
from flask import Flask, render_template
from funcs import *
from Enum import Gender
app = Flask(__name__)
@app.route("/")
def index():
return render_template("README.html")
@app.route("/get/")
@app.route("/get")
def get_one_user():
user = create_user()
return render_template(
"user.html", title="1 user", user=convert_to_string(user), status=1
)
@app.route("/get/<int:count>")
def get_several_user(count):
users = create_several_user(amount=count)
return render_template("users.html", title=f"{count} user", users=users, status=1)
@app.route("/get/<int:count>/<string:gender>")
def get_user_specific_gender(count, gender):
types = [Gender.male.name, Gender.female.name, Gender.both.name]
if gender.lower() in types:
users = create_several_user(amount=count, gender=gender.lower())
return render_template(
"users.html", title=f"{count} user", users=users, status=1
)
else:
return render_template(
"error.html",
title="ERROR",
status=0,
message="Oops, sorry. Something does not go as we expected.",
)
@app.route("/get/<string:gender>")
def get_one_user_with_gender(gender):
types = [Gender.male.name, Gender.female.name, Gender.both.name]
if gender.lower() in types:
user = create_user(gender=gender.lower())
return render_template(
"user.html", title="1 user", user=convert_to_string(user), status=1
)
else:
return render_template(
"error.html",
title="ERROR",
status=0,
message="Oops, sorry. Something does not go as we expected.",
)
@app.errorhandler(404)
def error(e):
return render_template(
"error.html",
title="ERROR",
message="404-page not found",
)
if __name__ == "__main__":
app.run(debug=True)