forked from oppia/oppia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
99 lines (82 loc) · 3.3 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# Copyright 2012 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS-IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Main package for URL routing."""
__author__ = 'Sean Lip'
import jinja2
import webapp2
import base
import editor
import feconf
import os
import reader
import utils
import widgets
jinja_env = jinja2.Environment(loader=jinja2.FileSystemLoader(
os.path.join(os.path.dirname(__file__), feconf.TEMPLATE_DIR)))
class Error404Handler(base.BaseHandler):
"""Handles 404 errors."""
def get(self): # pylint: disable-msg=C6409
self.error(404)
class MainPage(base.BaseHandler):
"""Oppia's main page."""
def get(self): # pylint: disable-msg=C6409
"""Handles GET requests."""
self.values['js'] = utils.GetJsFile('indexNew')
self.response.out.write(
jinja_env.get_template('index_new.html').render(self.values))
# Regex for base64 hash_id encoding
r = '[A-Za-z0-9=_-]+'
# Register the URL with the responsible classes
urls = [
# Handlers for the new version of Oppia
# TODO(sll): Use the URL r'/?' instead.
(r'/index/?', MainPage),
(r'/learn/?', reader.MainPage),
(r'/learn/(%s)/?' % r, reader.ExplorationPage),
(r'/learn/(%s)/data/?' % r, reader.ExplorationHandler),
(r'/create/?', editor.MainPage),
(r'/create/(%s)/?' % r, editor.ExplorationPage),
(r'/create/(%s)/data/?' % r, editor.ExplorationHandler),
# Reader handlers
(r'/?', reader.HomePage),
(r'/reader/profile/?', reader.ProfilePage),
(r'/reader/(%s)/?' % r, reader.StoryInitPage),
(r'/reader/(%s)/data/?' % r, reader.StoryHandler),
(r'/reader/(%s)/data/(%s)/?' % (r, r), reader.StoryHandler),
(r'/reader/(%s)/data/(%s)/(%s)/?' % (r, r, r), reader.StoryHandler),
# Editor handlers
(r'/editor/?', editor.HomePage),
(r'/editor/images/?', editor.Image),
(r'/editor/images/(%s)/?' % r, editor.Image),
(r'/editor/(%s)/structure/?' % r, editor.StoryPage),
(r'/editor/(%s)/structure/(%s)/?' % (r, r), editor.ChapterPage),
(r'/editor/(%s)/structure/(%s)/data/?' % (r, r), editor.ChapterHandler),
(r'/editor/(%s)/structure/(%s)/g/(%s)/?' % (r, r, r),
editor.QuestionGroupHandler),
(r'/editor/(%s)/qneditor/(%s)/(%s)/?' % (r, r, r), editor.QuestionPage),
(r'/editor/(%s)/qneditor/(%s)/(%s)/data/?' % (r, r, r),
editor.QuestionHandler),
(r'/editor/(%s)/qneditor/(%s)/(%s)/(%s)/?' % (r, r, r, r),
editor.StatePage),
(r'/editor/(%s)/qneditor/(%s)/(%s)/(%s)/data/?' % (r, r, r, r),
editor.StateHandler),
# Widget repository handlers
(r'/widgets/?', widgets.Widget),
(r'/widgets/repository/?', widgets.WidgetRepositoryPage),
(r'/widgets/(%s)/?' % r, widgets.Widget),
(r'/widgets/repository/data/?', widgets.WidgetRepositoryHandler),
# 404 error handler.
(r'/.*', Error404Handler),
]
app = webapp2.WSGIApplication(urls, debug=feconf.DEBUG)