-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathall_bananas_handler.py
75 lines (71 loc) · 2.25 KB
/
all_bananas_handler.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
import initialization_handler
import requests
import tornado.web
class AllBananas(initialization_handler.InitializationHandler):
"""
"""
# TODO pydoc
def get(self):
"""
"""
# TODO pydoc
try:
url = "http://{}/banana".format(self.back_ip)
answer = requests.get(url).json()
if "error" in answer:
raise tornado.web.HTTPError(500)
except tornado.web.HTTPError:
self.render(
"templates/error.html",
error_code=answer["error"],
error_msg=answer["errorCode"],
front_ip=self.front_ip,
infra=self.infra,
)
except Exception as e:
self.render(
"templates/error.html",
error_code="with backend query: " + str(e),
error_msg="500",
front_ip=self.front_ip,
infra=self.infra,
)
else:
self.render(
"templates/bananas.html",
bananas=answer,
front_ip=self.front_ip,
infra=self.infra,
)
def post(self):
"""
"""
# TODO pydoc
data = {
"color": self.get_argument('color', None),
"size": self.get_argument('size', None),
"price": self.get_argument('price', None),
}
try:
url = "http://{}/banana".format(self.back_ip)
answer = requests.post(url, data=data).json()
if "error" in answer:
raise tornado.web.HTTPError(500)
except tornado.web.HTTPError:
self.render(
"templates/error.html",
error_code=answer["error"],
error_msg=answer["errorCode"],
front_ip=self.front_ip,
infra=self.infra,
)
except Exception as e:
self.render(
"templates/error.html",
error_code="Error with backend query: " + str(e),
error_msg="500",
front_ip=self.front_ip,
infra=self.infra,
)
else:
self.redirect("/banana/" + str(answer["last_row_id"]))