This repository has been archived by the owner on Sep 23, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
118 lines (95 loc) · 3.93 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# [START imports]
import os
import urllib
import jinja2
import webapp2
from google.appengine.ext import ndb
JINJA_ENVIRONMENT = jinja2.Environment(
loader=jinja2.FileSystemLoader(os.path.dirname(__file__)),
extensions=['jinja2.ext.autoescape'],
autoescape=True)
################################ IGNORE: START ################################
# This statement will cause jinja to look for templates in the 'templates'
# directory.
jinja = jinja2.Environment(
loader=jinja2.FileSystemLoader(
os.path.join(os.path.dirname(__file__), 'templates')))
# Helper function; you probably don't want to use this directly.
def TemplateString(template_name, template_values):
t = jinja.get_template(template_name)
return t.render(template_values)
# Helper function; you probably don't want to use this directly.
def Template(template_name, template_values, output_stream):
output_stream.write(TemplateString(template_name, template_values))
################################# IGNORE: END #################################
# Writes the given text to the response. Use to display simple text
# on the page.
#
# Example:
# render.Text('Hello, world!!', self.response)
def TextResponse(text, response):
response.out.write(text)
# Executes the provided template text and writes the resulting string to the
# provided output stream. In this function, the template text is a string
# rather than reading it from a file.
#
# Example:
# template = 'Hello, {{name}}'
# template_values = {'name': 'Sabrina'}
# render.TemplateText(template, template_values, self.response)
def TextTemplateResponse(template_string, template_values, response):
t = jinja.from_string(template_string)
response.out.write(t.render(template_values))
# Looks in the templates folder for a file with the name provided in template_name.
# The template gets executed with the given template_values and writes the resulting
# string out to the given response object.
#
# Example:
# template_values = {
# 'key1': 'value1',
# 'key2': 'value2'
# }
# render.TemplateResponse('home.html', template_values, self.response)
def TemplateResponse(template_name, template_values, response):
Template(template_name, template_values, response.out)
# [END imports]
# class Marker(ndb.Model):
# title = ndb.StringProperty(required=True)
# latitude = ndb.FloatProperty(required=True)
# longitude = ndb.FloatProperty(required=True)
class MainPage(webapp2.RequestHandler):
def get(self):
# """
# markers = [
# Marker(title="A", latitude=-25, longitude=131),
# Marker(title="B", latitude=-26, longitude=130),
# Marker(title="C", latitude=-24, longitude=132),
# Marker(title="D", latitude=-25.5, longitude=131.5),
# Marker(title="E", latitude=-24.5, longitude=130.5)
# ]
# """
# markers = Marker.query()
template = JINJA_ENVIRONMENT.get_template('index.jsp')
TemplateResponse(template, {'results': ""}, self.response)
#self.response.write(template.render())
class Characters(webapp2.RequestHandler):
def get(self):
template = JINJA_ENVIRONMENT.get_template('characters.html')
TemplateResponse(JINJA_ENVIRONMENT.get_template('characters.html'), {'results': ""}, self.response)
# class AddMarker(webapp2.RequestHandler):
# def get(self):
# TemplateResponse(JINJA_ENVIRONMENT.get_template('addmarker.html'), {'results': ""}, self.response)
# def post(self):
# Marker(
# title=self.request.get("title"),
# latitude=float(self.request.get("latitude")),
# longitude=float(self.request.get("longitude"))).put()
# TemplateResponse(JINJA_ENVIRONMENT.get_template('addmarker.html'), {'results': "SUCCESS"}, self.response)
# class GetReady(webapp2.RequestHandler):
# def get(self):
# template = JINJA_ENVIRONMENT.get_template('getready.html')
# TemplateResponse(JINJA_ENVIRONMENT.get_template('getready.html'), {'results': ""}, self.response)
app = webapp2.WSGIApplication([
('/', MainPage),
('/characters', Characters)
], debug=True)