-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgeosci-courses.py
executable file
·127 lines (95 loc) · 3.7 KB
/
geosci-courses.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import cgi
import datetime
import webapp2
from collections import OrderedDict
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
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 = 'templates/'
# add Defaults
template_values['_templateFolder'] = _templateFolder
template_values['_year'] = str(datetime.datetime.now().year)
path = os.path.normpath(_templateFolder+templateFile)
print(path)
template = JINJA_ENVIRONMENT.get_template(path)
self.response.write(template.render(template_values))
# class MainPage(webapp2.RequestHandler):
# def get(self, mailSent=False):
# setTemplate(self, {"indexPage": True, 'mailSent': mailSent}, 'index.html')
# # data = {'mailSent':mailSent}
# # setTemplate(self, data, 'index.html')
# def post(self):
# email = self.request.get('email')
# name = self.request.get('name')
# message = self.request.get('message')
# sender_address = "DISC Mail <[email protected]>"
# email_to = ["Lindsey Heagy <[email protected]>"]
# email_subject = "DISC2017 Mail"
# email_message = "New email from:\n\n%s<%s>\n\n\n%s\n" % (name, email, message)
# mail.send_mail(sender_address, email_to, email_subject, email_message)
# self.get(mailSent=True)
class MainPage(webapp2.RequestHandler):
@property
def where(self):
if getattr(self, '_where', None) is None:
self.__class__._where = json.load(
open('./templates/where/where.json', 'r'),
object_pairs_hook=OrderedDict
)
return self._where
def get(self):
setTemplate(self, {'where': self.where}, 'index.html')
class Events(webapp2.RequestHandler):
def get(self):
setTemplate(self, {}, 'events.html')
# data = {'mailSent':mailSent}
# setTemplate(self, data, 'index.html')
class Images(webapp2.RequestHandler):
def get(self):
self.redirect('http://disc2017.geosci.xyz'+self.request.path)
class Assets(webapp2.RequestHandler):
def get(self):
self.redirect('http://disc2017.geosci.xyz'+self.request.path)
class Where(webapp2.RequestHandler):
@property
def where(self):
if getattr(self, '_where', None) is None:
self.__class__._where = json.load(
open('./templates/where/where.json', 'r')
)
return self._where
def get(self):
loc = self.request.path.split('/')[-1]
# where = [w.rsplit('.')[0] for w in os.listdir('./templates/where/')]
# where = json.load(open('./templates/where/where.json', 'r'))
if loc in self.where.keys():
args = self.where[loc]
if 'name' not in args.keys():
args['name'] = loc
# args['upcoming'] = args[''] #TODO: use datetime to figure this out
setTemplate(self, args, 'where/template.html')
else:
setTemplate(self, {}, 'error.html')
where = json.load(open('./templates/where/where.json', 'r'))
print('|'.join(where.keys()))
base_apps = [
('/', MainPage),
# ('/({})'.format('|'.join(where.keys())), Where),
('/events', Events),
('/assets', Assets),
('/img/.*', Images),
('/.*', Where)
]
app = webapp2.WSGIApplication(
base_apps, debug=os.environ.get("SERVER_SOFTWARE", "").startswith("Dev")
)