-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.py
102 lines (70 loc) · 2.11 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
100
101
102
# -*- coding: utf-8 -*-
"""
Main page views.
"""
__author__ = "Python Finland <hallitus@python.fi>"
__copyright__ = "Copyright (c) 2011 Python Suomi ry"
__license__ = "BSD"
__docformat__ = "epytext"
# Python standard library imports
import os
import logging
# Appengine imports
from google.appengine.ext.webapp import template
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
class PigPage(webapp.RequestHandler):
"""Base class for page renderer"""
def render_page(self, template_file_name):
""" Render a page template from templates folder"""
# Fill in template parameters
vars = {}
path = os.path.join(os.path.dirname(__file__), 'templates', template_file_name)
self.response.out.write(template.render(path, vars))
class MainPage(PigPage):
"""Index page of the site"""
def get(self):
self.render_page("main.html")
class NewsPage(PigPage):
def get(self):
self.render_page("news.html")
class AboutPage(PigPage):
def get(self):
self.render_page("about.html")
class InEnglishPage(PigPage):
def get(self):
self.render_page("english.html")
class CompaniesPage(PigPage):
def get(self):
self.render_page("companies.html")
class BlogsPage(PigPage):
def get(self):
self.render_page("blogs.html")
class JobsPage(PigPage):
def get(self):
self.render_page("jobs.html")
class LearnPage(PigPage):
def get(self):
self.render_page("learn.html")
class NotFound(PigPage):
"""Handle URIs not found"""
def get(self):
self.render_page("404.html")
from proxy import ProxyHandler
application = webapp.WSGIApplication([
('/about', AboutPage),
("/proxy", ProxyHandler),
('/news', NewsPage),
('/english', InEnglishPage),
('/companies', CompaniesPage),
('/blogs', BlogsPage),
('/jobs', JobsPage),
('/learn', LearnPage),
('/', MainPage),
('/.*', NotFound),
], debug=True)
def main():
logging.getLogger().setLevel(logging.DEBUG)
run_wsgi_app(application)
if __name__ == "__main__":
main()