OLD | NEW |
1 # Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 import jinja2 | 5 import jinja2 |
| 6 import json |
6 import os | 7 import os |
| 8 import re |
7 import urllib | 9 import urllib |
8 import webapp2 | 10 import webapp2 |
9 | 11 |
10 from google.appengine.ext import blobstore | 12 from google.appengine.ext import blobstore |
11 from google.appengine.ext.webapp import blobstore_handlers | 13 from google.appengine.ext.webapp import blobstore_handlers |
12 | 14 |
13 import services | 15 import services |
14 | 16 |
15 | 17 |
16 JINJA_ENVIRONMENT = jinja2.Environment( | 18 JINJA_ENVIRONMENT = jinja2.Environment( |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 else: | 63 else: |
62 # Jump to new graph page using default template. | 64 # Jump to new graph page using default template. |
63 req_params = { | 65 req_params = { |
64 'run_id': run_id, | 66 'run_id': run_id, |
65 'tmpl_id': default_key.urlsafe() | 67 'tmpl_id': default_key.urlsafe() |
66 } | 68 } |
67 | 69 |
68 self.redirect('/?' + urllib.urlencode(req_params)) | 70 self.redirect('/?' + urllib.urlencode(req_params)) |
69 | 71 |
70 | 72 |
| 73 class ShareHandler(webapp2.RequestHandler): |
| 74 """Handle breakdown template sharing. Generate public url for transferred |
| 75 template and return it back.""" |
| 76 def post(self): |
| 77 run_id = self.request.POST['run_id'] |
| 78 content = json.loads(self.request.POST['content']) |
| 79 tmpl_key = services.CreateTemplate(content) |
| 80 |
| 81 req_params = { |
| 82 'run_id': run_id, |
| 83 'tmpl_id': tmpl_key.urlsafe() |
| 84 } |
| 85 |
| 86 # Take out host url from request by removing share suffix. |
| 87 url = re.sub('share', '', self.request.url) |
| 88 self.response.write(url + '?' + urllib.urlencode(req_params)) |
| 89 |
| 90 |
71 application = webapp2.WSGIApplication([ | 91 application = webapp2.WSGIApplication([ |
72 ('/', MainPage), | 92 ('/', MainPage), |
73 ('/upload', UploadHandler) | 93 ('/upload', UploadHandler), |
| 94 ('/share', ShareHandler) |
74 ], debug=True) | 95 ], debug=True) |
OLD | NEW |