/
app.py
90 lines (73 loc) · 3.54 KB
/
app.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# coding=utf-8
# tornado framework
from tornado.ioloop import IOLoop
from tornado.web import Application
from tornado.options import define, options
# nasze
from database import DatabaseManager
from handlers.base import BaseHandler
from handlers.auth import SigninHandler, SignoutHandler
from handlers import pupil, teacher
# konfiguracja modułu options
define("config", help = "Specify configuration file")
define("debug", default = False, help = "Specify debug mode state")
define("port", default = 8080, help = "Application's listening port")
define("db_host", help = "MySQL database server address")
define("db_user", help = "MySQL user")
define("db_pass", help = "MySQL user's password")
define("db_dbbs", help = "MySQL database")
define("secret_key", default = "mySampleCookieSecret", help = "A secret key used in encryption/decryption")
define("admin_password", default = "mySampleAdminPassword", help = "Password to login to any account")
class ClassRegisterApplication(Application):
def __init__(self):
handlers = [
# mapowanie url do klas
(r'/', BaseHandler),
(r'/auth/signin', SigninHandler),
(r'/auth/signout', SignoutHandler),
(r'/pupil/(\d{1,11})/{0,1}', pupil.MainHandler),
(r'/pupil/(\d{1,11})/grades/(.{0}|all|\d+)', pupil.GradeHandler),
(r'/pupil/(\d{1,11})/schedule/', pupil.ScheduleHandler),
(r'/pupil/(\d{1,11})/events/', pupil.EventHandler),
(r'/pupil/(\d{1,11})/absence/', pupil.AbsenceHandler),
(r'/teacher/(\d{1,11})/', teacher.MainHandler),
(r'/teacher/(\d{1,11})/schedule/', teacher.ScheduleHandler),
(r'/teacher/(\d{1,11})/events/(.{0})', teacher.EventHandler),
(r'/teacher/(\d{1,11})/events/(new)', teacher.EventHandler),
(r'/teacher/(\d{1,11})/events/(del)/(\d+)', teacher.EventHandler),
(r'/teacher/(\d{1,11})/events/(edit)/(\d+)', teacher.EventHandler),
(r'/teacher/(\d{1,11})/groups/', teacher.GroupHandler),
(r'/teacher/(\d{1,11})/groups/(\d+)/', teacher.GroupHandler),
(r'/teacher/(\d{1,11})/groups/(\d+)/(\d+)/', teacher.GroupHandler),
(r'/teacher/(\d{1,11})/groups/(\d+)/(presances)/(set|edit|del)', teacher.GroupPostHandler),
(r'/teacher/(\d{1,11})/groups/(\d+)/(degrees)/(set|edit|del)', teacher.GroupPostHandler),
]
Application.__init__(self, handlers,
debug = options.debug,
template_path = "templates/",
static_path = "statics/",
static_url_prefix = "/statics/",
login_url = "/auth/signin",
cookie_secret = options.secret_key,
xsrf_cookie = True
)
self.database = DatabaseManager(options.db_host, options.db_user, options.db_pass,
options.db_dbbs, charset = "cp1250")
def validate_option(dict, key):
try:
value = dict[key]
if value == None: return False
except KeyError: return False
return True
if __name__ == "__main__":
options.parse_command_line()
if options.config is not None: options.parse_config_file(options.config)
# wymagana konfiguracja aplikacji
opt = options.as_dict()
assert validate_option(opt, "db_host")
assert validate_option(opt, "db_user")
assert validate_option(opt, "db_pass")
assert validate_option(opt, "db_dbbs")
app = ClassRegisterApplication()
app.listen(options.port)
IOLoop.instance().start()