| OLD | NEW |
| (Empty) | |
| 1 # Copyright (c) 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 """Request handler for the /admin/app_config page. |
| 6 |
| 7 Allows admins to set configuration parameter via the appengine admin console. |
| 8 """ |
| 9 |
| 10 import cgi |
| 11 import webapp2 |
| 12 |
| 13 import third_party # pylint: disable=W0611 |
| 14 |
| 15 import model.app_config |
| 16 import rietveld |
| 17 |
| 18 |
| 19 FIELDS = ('client_id', 'service_account_key', 'server_url', 'nickname') |
| 20 |
| 21 |
| 22 class AppConfigHandler(webapp2.RequestHandler): |
| 23 """Handles /admin/appconfig.""" |
| 24 |
| 25 def post(self): |
| 26 """Handles POST requests to update app config. |
| 27 |
| 28 Parses the request data, writes it to the data store entity, and sends a |
| 29 request to rietveld to update the app's nickname. |
| 30 """ |
| 31 app_config = model.app_config.get() |
| 32 for field in FIELDS: |
| 33 setattr(app_config, field, self.request.get(field, None)) |
| 34 app_config.put() |
| 35 |
| 36 # Set the nickname with rietveld. |
| 37 rv = rietveld.Rietveld() |
| 38 settings_payload = { |
| 39 'column_width': 80, # required field |
| 40 'nickname': app_config.nickname, |
| 41 } |
| 42 |
| 43 try: |
| 44 rv.post_data('settings', settings_payload) |
| 45 except rietveld.RietveldRequestError as e: |
| 46 # Redirect indicates success. |
| 47 if e[1].status != 302: |
| 48 raise e |
| 49 |
| 50 self.RenderForm() |
| 51 |
| 52 def get(self): |
| 53 """Handles GET requests.""" |
| 54 self.RenderForm() |
| 55 |
| 56 def RenderForm(self): |
| 57 """Renders the app config form to the client.""" |
| 58 app_config = model.app_config.get() |
| 59 self.response.write('<html><body><form action="%s" method="post"><table>' % |
| 60 self.request.path) |
| 61 for field in FIELDS: |
| 62 self.response.write( |
| 63 '<tr><td>%s</td><td><textarea name="%s">%s</textarea></td></tr>' % |
| 64 (field, field, cgi.escape(getattr(app_config, field, '')))) |
| 65 self.response.write('<tr><td><input type="submit" value="Set"></td></tr>') |
| 66 self.response.write('</table><form></body></body>') |
| 67 |
| 68 |
| 69 app = webapp2.WSGIApplication([('/admin/app_config', AppConfigHandler)]) |
| OLD | NEW |