2 # Copyright 2008 Google Inc.
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
16 """The main Geochat application.
18 Contains the MainHandler, which handles root requests to the server, along
19 with several other template-driven pages that don't have any significant DB
22 MainHandler: Handles requests to /
23 SettingsHandler: Handles requests to /settings
24 HelpHandler: Handles requests to /help
32 from google
.appengine
.api
import users
33 from google
.appengine
.ext
import db
34 from google
.appengine
.ext
import webapp
35 from google
.appengine
.ext
.webapp
import template
36 from google
.appengine
.ext
.webapp
.util
import run_wsgi_app
43 class MainHandler(webapp
.RequestHandler
):
45 """Handles requests to /
47 MainHandler handles requests for the server root, presenting the main user
48 interface for Geochat. It relies on the geochat.html template, with most
49 of the heavy lifting occuring client-side through JavaScript linked there.
56 user
= users
.get_current_user()
59 user_settings
= settings
.get(user
)
60 if user_settings
== None:
61 self
.redirect('/settings')
65 'auth_url': users
.CreateLogoutURL(self
.request
.uri
),
66 'auth_text': 'Sign out',
67 'user_email': user
.email(),
68 'user_nickname': user
.nickname(),
69 'default_location': user_settings
.default_location
,
70 'initial_latitude': 37.4221,
71 'initial_longitude': -122.0837,
75 'auth_url': users
.CreateLoginURL(self
.request
.uri
),
76 'auth_text': 'Sign in',
79 'initial_latitude': 37.4221,
80 'initial_longitude': -122.0837,
83 template_path
= os
.path
.join(os
.path
.dirname(__file__
), 'geochat.html')
84 self
.response
.headers
['Content-Type'] = 'text/html'
85 self
.response
.out
.write(template
.render(template_path
, template_data
))
88 class SettingsHandler(webapp
.RequestHandler
):
90 """Handles requests to /settings
92 SettingsHandler handles requests to /settings, serving up the template
93 found in settings.html on GET requests, and saving user settings on
101 user
= users
.get_current_user()
103 self
.redirect(users
.CreateLoginURL(self
.request
.uri
))
106 user_settings
= settings
.get(user
)
109 'auth_url': users
.CreateLogoutURL(self
.request
.uri
),
110 'auth_text': 'Sign out',
111 'user_email': user
.email(),
112 'user_nickname': user
.nickname(),
113 'default_location': user_settings
.default_location
,
114 'default_zoom': user_settings
.default_zoom
,
118 'auth_url': users
.CreateLogoutURL(self
.request
.uri
),
119 'auth_text': 'Sign out',
120 'user_email': user
.email(),
121 'user_nickname': user
.nickname(),
124 template_path
= os
.path
.join(os
.path
.dirname(__file__
), 'settings.html')
125 self
.response
.headers
['Content-Type'] = 'text/html'
126 self
.response
.out
.write(template
.render(template_path
, template_data
))
130 user
= users
.get_current_user()
132 self
.redirect(users
.CreateLoginURL(self
.request
.uri
))
135 location
= self
.request
.get('location')
136 user_settings
= settings
.get(user
)
139 user_settings
.default_location
= location
142 user_settings
= settings
.new(user
, location
)
147 class HelpHandler(webapp
.RequestHandler
):
149 """Handles requests to /help
151 HelpHandler handles requests to /settings, serving up the template
159 user
= users
.get_current_user()
162 'auth_url': users
.CreateLogoutURL(self
.request
.uri
),
163 'auth_text': 'Sign out',
164 'user_email': user
.email(),
168 'auth_url': users
.CreateLoginURL(self
.request
.uri
),
169 'auth_text': 'Sign in',
173 template_path
= os
.path
.join(os
.path
.dirname(__file__
), 'help.html')
174 self
.response
.headers
['Content-Type'] = 'text/html'
175 self
.response
.out
.write(template
.render(template_path
, template_data
))
178 if __name__
== '__main__':
179 application
= webapp
.WSGIApplication([('/', MainHandler
),
180 ('/settings', SettingsHandler
),
181 ('/help', HelpHandler
),], debug
= True)
183 run_wsgi_app(application
)