Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 # Copyright 2013 The Chromium Authors. All rights reserved. | |
| 2 # Use of this source code is governed by a BSD-style license that can be | |
| 3 # found in the LICENSE file. | |
| 4 | |
| 5 import jinja2 | |
| 6 import os | |
| 7 import urllib | |
| 8 import webapp2 | |
| 9 | |
| 10 from google.appengine.ext import blobstore | |
| 11 from google.appengine.ext.webapp import blobstore_handlers | |
| 12 | |
| 13 import services | |
| 14 | |
| 15 | |
| 16 JINJA_ENVIRONMENT = jinja2.Environment( | |
| 17 loader=jinja2.FileSystemLoader(os.path.dirname(__file__)), | |
| 18 extensions=['jinja2.ext.autoescape']) | |
| 19 | |
| 20 | |
| 21 class MainPage(webapp2.RequestHandler): | |
| 22 """Show breakdown with received profiler-id and template-id. If nothing was | |
| 23 received, show blank page waiting user to upload file.""" | |
| 24 def get(self): | |
| 25 page_template = JINJA_ENVIRONMENT.get_template('index.html') | |
| 26 upload_url = blobstore.create_upload_url('/upload') | |
| 27 | |
| 28 # Get profiler id and template id from url query. | |
| 29 run_id = self.request.get('run_id') | |
| 30 tmpl_id = self.request.get('tmpl_id') | |
| 31 upload_msg = self.request.get('upload_msg') | |
| 32 | |
| 33 template_values = { | |
| 34 'upload_url': upload_url, | |
| 35 'upload_msg': upload_msg | |
| 36 } | |
| 37 | |
| 38 if run_id and tmpl_id: | |
|
Dai Mikurube (NOT FULLTIME)
2013/09/24 10:13:09
It looks you added 'null' ones in Patch Set 5. Wer
junjianx
2013/09/24 10:25:20
I moved verification of these two variables to the
| |
| 39 template_values['json'] = services.GetProfiler(run_id) | |
| 40 template_values['template'] = services.GetTemplate(tmpl_id) | |
| 41 | |
| 42 self.response.write(page_template.render(template_values)) | |
| 43 | |
| 44 | |
| 45 class UploadHandler(blobstore_handlers.BlobstoreUploadHandler): | |
| 46 """Handle file uploading with BlobstoreUploadHandler. BlobstoreUploadHandler | |
| 47 can deal with files overweighing size limitation within one HTTP connection so | |
| 48 that user can upload large json file.""" | |
| 49 def post(self): | |
| 50 blob_info = self.get_uploads('file')[0] | |
| 51 | |
| 52 run_id = services.CreateProfiler(blob_info) | |
| 53 default_key = services.CreateTemplates(blob_info) | |
| 54 | |
| 55 # TODO(junjianx): Validation of uploaded file should be done separately. | |
| 56 if not default_key: | |
| 57 # Jump to home page with error message. | |
| 58 req_params = { | |
| 59 'upload_msg': 'No default key was found.' | |
|
sullivan
2013/09/24 12:29:21
Maybe 'No default template key was found'? FWIW, I
| |
| 60 } | |
| 61 else: | |
| 62 # Jump to new graph page using default template. | |
| 63 req_params = { | |
| 64 'run_id': run_id, | |
| 65 'tmpl_id': default_key.urlsafe() | |
| 66 } | |
| 67 | |
| 68 self.redirect('/?' + urllib.urlencode(req_params)) | |
| 69 | |
| 70 | |
| 71 application = webapp2.WSGIApplication([ | |
| 72 ('/', MainPage), | |
| 73 ('/upload', UploadHandler) | |
| 74 ], debug=True) | |
| OLD | NEW |