| 412 |
ashish |
1 |
'''
|
|
|
2 |
Created on 04-Aug-2010
|
|
|
3 |
|
|
|
4 |
@author: ashish
|
|
|
5 |
'''
|
|
|
6 |
|
|
|
7 |
import tornado.httpserver
|
|
|
8 |
import tornado.ioloop
|
|
|
9 |
import tornado.web
|
| 434 |
ashish |
10 |
from shop2020.logistics.external.xlsprocessor import get_xls_for_today,\
|
|
|
11 |
get_sample_xml, get_html_page
|
| 412 |
ashish |
12 |
|
|
|
13 |
class BaseHandler(tornado.web.RequestHandler):
|
|
|
14 |
def get_current_user(self):
|
|
|
15 |
return self.get_secure_cookie("user")
|
|
|
16 |
|
|
|
17 |
def get_warehouse(self):
|
|
|
18 |
return self.get_secure_cookie("warehouse")
|
|
|
19 |
|
|
|
20 |
class MainHandler(BaseHandler):
|
|
|
21 |
@tornado.web.authenticated
|
|
|
22 |
def get(self):
|
|
|
23 |
name = tornado.escape.xhtml_escape(self.current_user)
|
|
|
24 |
self.write("Hello, " + name)
|
|
|
25 |
|
| 434 |
ashish |
26 |
class OptionHandler(BaseHandler):
|
|
|
27 |
@tornado.web.authenticated
|
|
|
28 |
def get(self):
|
|
|
29 |
self.set_header("Content-Type", "text/html")
|
|
|
30 |
self.write(get_html_page())
|
|
|
31 |
pass
|
|
|
32 |
|
|
|
33 |
class ArxHandler(BaseHandler):
|
|
|
34 |
def get(self):
|
|
|
35 |
self.set_header("Content-Type", "text/xml")
|
|
|
36 |
self.write(get_sample_xml())
|
|
|
37 |
|
|
|
38 |
class PaymentsHandler(BaseHandler):
|
|
|
39 |
def get(self):
|
|
|
40 |
url = self.get_argument("url")
|
|
|
41 |
nonce = self.get_argument("nonce")
|
|
|
42 |
amount = self.get_argument("amount")
|
|
|
43 |
|
| 412 |
ashish |
44 |
class ListHandler(BaseHandler):
|
|
|
45 |
@tornado.web.authenticated
|
|
|
46 |
def get(self):
|
|
|
47 |
self.name = tornado.escape.xhtml_escape(self.current_user)
|
|
|
48 |
self.warehouse = tornado.escape.xhtml_escape(self.get_warehouse())
|
|
|
49 |
self.set_header("Content-Type", "application/vnd.ms-excel")
|
|
|
50 |
self.set_header("Content-Disposition", "attachment;filename=List Of Shipment.xls;")
|
|
|
51 |
self.write(get_xls_for_today(self.warehouse))
|
|
|
52 |
|
|
|
53 |
def get_xls_for_warehouse(self):
|
|
|
54 |
pass
|
|
|
55 |
|
|
|
56 |
class LoginHandler(BaseHandler):
|
|
|
57 |
def get(self):
|
|
|
58 |
self.write('<html><body><form action="/login" method="post">'
|
|
|
59 |
'Name: <input type="text" name="name">'
|
|
|
60 |
'Password:<input type="password" name="password">'
|
|
|
61 |
'<input type="submit" value="Sign in">'
|
|
|
62 |
'</form></body></html>')
|
|
|
63 |
|
|
|
64 |
def post(self):
|
|
|
65 |
if self.get_auth(self.get_argument("name"), self.get_argument("password")):
|
|
|
66 |
self.set_secure_cookie("user", self.get_argument("name"))
|
|
|
67 |
self.set_secure_cookie("warehouse", self.get_warehouse_id(self.get_argument("name")))
|
|
|
68 |
self.redirect("/list")
|
|
|
69 |
else:
|
|
|
70 |
self.redirect("/login")
|
|
|
71 |
|
|
|
72 |
def get_auth(self, user, password):
|
|
|
73 |
return True
|
|
|
74 |
|
|
|
75 |
def get_warehouse_id(self, user):
|
|
|
76 |
if user == "Ashish":
|
|
|
77 |
return "all"
|
| 434 |
ashish |
78 |
return "1"
|
| 412 |
ashish |
79 |
|
|
|
80 |
settings = {
|
| 434 |
ashish |
81 |
"cookie_secret": "61oETzKXQAGaYdkL5gEmGeJJFuYh7EQnp2XdTP1o/Vx=",
|
| 412 |
ashish |
82 |
"login_url": "/login",
|
|
|
83 |
}
|
|
|
84 |
|
|
|
85 |
application = tornado.web.Application([
|
|
|
86 |
(r"/", MainHandler),
|
|
|
87 |
(r"/login", LoginHandler),
|
|
|
88 |
(r"/list", ListHandler),
|
| 434 |
ashish |
89 |
(r"/arx", ArxHandler),
|
|
|
90 |
(r"/opt", OptionHandler),
|
| 412 |
ashish |
91 |
], **settings)
|
|
|
92 |
|
|
|
93 |
|
|
|
94 |
if __name__ == "__main__":
|
|
|
95 |
http_server = tornado.httpserver.HTTPServer(application)
|
|
|
96 |
http_server.listen(8888)
|
|
|
97 |
tornado.ioloop.IOLoop.instance().start()
|