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 services | |
8 import urllib | |
9 import webapp2 | |
10 | |
11 from google.appengine.ext import blobstore | |
12 from google.appengine.ext.webapp import blobstore_handlers | |
13 | |
14 | |
15 JINJA_ENVIRONMENT = jinja2.Environment( | |
16 loader=jinja2.FileSystemLoader(os.path.dirname(__file__)), | |
17 extensions=['jinja2.ext.autoescape']) | |
18 | |
19 | |
20 class MainPage(webapp2.RequestHandler): | |
21 """Show breakdown with received profiler-id and template-id. If nothing was | |
22 received, show blank page waiting user to upload file.""" | |
23 def get(self): | |
24 page_template = JINJA_ENVIRONMENT.get_template('index.html') | |
25 upload_url = blobstore.create_upload_url('/upload') | |
26 | |
27 # Get profiler id and template id from url query. | |
28 run_id = self.request.get('run_id') | |
29 tmpl_id = self.request.get('tmpl_id') | |
30 | |
31 template_values = {'upload_url': upload_url} | |
32 | |
33 if not run_id or not tmpl_id: | |
34 self.response.write(page_template.render(template_values)) | |
35 else: | |
36 template_values['json'] = services.GetProfiler(run_id) | |
37 template_values['template'] = services.GetTemplate(tmpl_id) | |
38 | |
39 # TODO(junjianx): Return error page when no json or template found. | |
40 self.response.write(page_template.render(template_values)) | |
41 | |
42 | |
43 class UploadHandler(blobstore_handlers.BlobstoreUploadHandler): | |
44 """Handle file uploading with BlobstoreUploadHandler. BlobstoreUploadHandler | |
45 can deal with files overweighing size limitation within one HTTP connection so | |
46 that user can upload large json file.""" | |
47 def post(self): | |
48 blob_info = self.get_uploads('file')[0] | |
49 | |
50 run_id = services.CreateProfiler(blob_info) | |
51 default_key = services.CreateTemplates(blob_info) | |
sullivan
2013/09/20 13:59:51
Reading the code, right now I think if there is no
junjianx
2013/09/24 05:53:53
Done.
I think validation of uploaded file should b
| |
52 | |
53 # Jump to new graph page using default template. | |
54 query_params = { | |
55 'run_id': run_id, | |
56 'tmpl_id': default_key.urlsafe() | |
57 } | |
58 # TODO(junjianx): Return error page when no default template indicated. | |
59 self.redirect('/?' + urllib.urlencode(query_params)) | |
60 | |
61 | |
62 application = webapp2.WSGIApplication([ | |
63 ('/', MainPage), | |
64 ('/upload', UploadHandler) | |
65 ], debug=True) | |
OLD | NEW |