Skip to content

Commit 62c8b7d

Browse files
author
dhermes@google.com
committed
Updating tasks App Engine sample.
Reviewed in https://codereview.appspot.com/6973047/
1 parent 1cea2a7 commit 62c8b7d

2 files changed

Lines changed: 25 additions & 23 deletions

File tree

samples/tasks_appengine/app.yaml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
application: mytasks
22
version: 1
3-
runtime: python
3+
runtime: python27
44
api_version: 1
5+
threadsafe: true
56

67
handlers:
78
- url: /css
89
static_dir: css
910

1011
- url: .*
11-
script: main.py
12+
script: main.application
13+
14+
libraries:
15+
- name: jinja2
16+
version: latest

samples/tasks_appengine/main.py

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,49 +12,46 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
from google.appengine.dist import use_library
16-
use_library('django', '1.2')
17-
from google.appengine.ext import webapp
18-
from google.appengine.ext.webapp import template
19-
from google.appengine.ext.webapp.util import run_wsgi_app
15+
import webapp2
16+
from webapp2_extras import jinja2
17+
2018
from apiclient.discovery import build
21-
import httplib2
2219
from oauth2client.appengine import OAuth2Decorator
20+
2321
import settings
2422

2523
decorator = OAuth2Decorator(client_id=settings.CLIENT_ID,
2624
client_secret=settings.CLIENT_SECRET,
27-
scope=settings.SCOPE,
28-
user_agent='mytasks')
25+
scope=settings.SCOPE)
26+
service = build('tasks', 'v1')
27+
2928

29+
class MainHandler(webapp2.RequestHandler):
3030

31-
class MainHandler(webapp.RequestHandler):
31+
def render_response(self, template, **context):
32+
renderer = jinja2.get_jinja2(app=self.app)
33+
rendered_value = renderer.render_template(template, **context)
34+
self.response.write(rendered_value)
3235

3336
@decorator.oauth_aware
3437
def get(self):
3538
if decorator.has_credentials():
36-
service = build('tasks', 'v1', http=decorator.http())
37-
result = service.tasks().list(tasklist='@default').execute()
39+
result = service.tasks().list(tasklist='@default').execute(
40+
http=decorator.http())
3841
tasks = result.get('items', [])
3942
for task in tasks:
4043
task['title_short'] = truncate(task['title'], 26)
41-
self.response.out.write(template.render('templates/index.html',
42-
{'tasks': tasks}))
44+
self.render_response('index.html', tasks=tasks)
4345
else:
4446
url = decorator.authorize_url()
45-
self.response.out.write(template.render('templates/index.html',
46-
{'tasks': [],
47-
'authorize_url': url}))
47+
self.render_response('index.html', tasks=[], authorize_url=url)
4848

4949

5050
def truncate(s, l):
5151
return s[:l] + '...' if len(s) > l else s
5252

53-
application = webapp.WSGIApplication([
53+
54+
application = webapp2.WSGIApplication([
5455
('/', MainHandler),
5556
(decorator.callback_path, decorator.callback_handler()),
5657
], debug=True)
57-
58-
59-
def main():
60-
run_wsgi_app(application)

0 commit comments

Comments
 (0)