forked from geoscixyz/gpg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgpggeosci.py
97 lines (76 loc) · 2.87 KB
/
gpggeosci.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
#!/usr/bin/env python
#
# Copyright 2007 Google Inc.
#
# 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.
#
import cgi
import datetime
import webapp2
import logging
from google.appengine.ext import ndb
from google.appengine.api import users
from google.appengine.api import mail
from google.appengine.api import urlfetch
import os
import jinja2
import urllib, hashlib
import json
from flask import request
from webapp2 import Route, RedirectHandler
TEMPLATEFOLDER = '_build/html/'
JINJA_ENVIRONMENT = jinja2.Environment(
loader=jinja2.FileSystemLoader(os.path.join(os.path.dirname(__file__).split('/')[:-1])),
extensions=['jinja2.ext.autoescape'],
autoescape=False)
def setTemplate(self, template_values, templateFile, _templateFolder=TEMPLATEFOLDER):
# add Defaults
template_values['_templateFolder'] = _templateFolder
template_values['_year'] = str(datetime.datetime.now().year)
path = os.path.normpath(_templateFolder+templateFile)
template = JINJA_ENVIRONMENT.get_template(path)
resp = self.response.write(template.render(template_values))
if resp is None:
self.redirect('/error.html', permanent=True)
class Images(webapp2.RequestHandler):
def get(self):
self.redirect('/'+self.request.path)
class Redirect(webapp2.RequestHandler):
def get(self):
path = str(self.request.path).split(os.path.sep)[3:]
self.redirect(('/%s' % os.path.sep.join(path)), permanent=True)
class MainPage(webapp2.RequestHandler):
def get(self):
setTemplate(self, {"indexPage": True}, 'index.html')
# class Error(webapp2.RequestHandler):
# def get(self):
# setTemplate(self, {}, 'error.html', _templateFolder='_templates/')
# # self.redirect('/error.html', permanent=True)
# pointers = [
# Route('/en/latest/.*', RedirectHandler, defaults={'_uri': '/.*'}),
# # Route('/en/latest', RedirectHandler, defaults={'_uri': '/en/latest/'}),
# Route('/en/latest/', RedirectHandler, defaults={'_uri': '/'}),
#
# ('/.*', MainPage),
# ('/', MainPage),
# ('', MainPage),
# ('/_images/.*', Images),
# ]
app = webapp2.WSGIApplication([
('/_images/.*', Images),
('/en/latest/.*',Redirect),
Route('/en/latest/', RedirectHandler, defaults={'_uri': '/'}),
('/', MainPage),
# ('/.*', Error),
], debug=True)
# app.error_handlers[404] = Error