Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(264)

Unified Diff: handler.py

Issue 10448057: Add refresh support to the console page. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/chromium-build
Patch Set: Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base_page.py ('k') | pylintrc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: handler.py
diff --git a/handler.py b/handler.py
index 75fee5acd5bba34e0c2c4f3357f9a48be4572754..0eefaddc744e6b44bfe922838a7166b871187631 100644
--- a/handler.py
+++ b/handler.py
@@ -2,87 +2,67 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
-import os.path
import urllib
from google.appengine.ext import deferred
# F0401: 9,0: Unable to import 'webapp2'
# pylint: disable=F0401
import webapp2
-from google.appengine.ext.webapp import template
import app
+import base_page
+import utils
-def _clean_int(value, default):
- """Convert a value to an int, or the default value if conversion fails."""
- try:
- return int(value)
- except (TypeError, ValueError):
- return default
-
-# W0232: 23,0:MyRequestHandler: Class has no __init__ method
-# pylint: disable=W0232
-class MyRequestHandler(webapp2.RequestHandler):
- """Base request handler with this application specific helpers."""
-
- # E1101: 31,4:MyRequestHandler._render_template: Instance of
- # 'MyRequestHandler' has no 'response' member
- # pylint: disable=E1101
- def _render_template(self, name, values):
- """
- Wrapper for template.render that updates response
- and knows where to look for templates.
- """
- self.response.out.write(template.render(
- os.path.join(os.path.dirname(__file__), 'templates', name),
- values))
-
-
-# W0232: 42,0:PageAction: Class has no __init__ method
-# pylint: disable=W0232
-class PageAction(MyRequestHandler):
+class PageAction(base_page.BasePage):
# W0221: 44,2:PageAction.get: Arguments number differs from overridden method
# pylint: disable=W0221
def get(self, localpath):
- # E1101: 70,11:PageAction.get: Instance of 'PageAction' has no 'request'
- # member
- # pylint: disable=E1101
if len(self.request.query_string) > 0:
- # E1101: 47,11:PageAction.get: Instance of 'PageAction' has no 'request'
- # member
- # pylint: disable=E1101
- localpath += '?' + self.request.query_string
+ # The reload arg, if present, must be stripped from the URL.
+ args = self.request.query_string.split('&')
+ args = [arg for arg in args if not arg.startswith('reload=')]
+ if args:
+ localpath += '?' + '&'.join(args)
unquoted_localpath = urllib.unquote(localpath)
- content = app.get_and_cache_page(unquoted_localpath)
- if content is None:
- # E1101: 78,6:PageAction.get: Instance of 'PageAction' has no 'error'
- # member
- # pylint: disable=E1101
+ page_data = app.get_and_cache_pagedata(unquoted_localpath)
+ if page_data.get('content') is None:
self.error(404) # file not found
return
+ self.response.headers['Content-Type'] = app.path_to_mime_type(
+ unquoted_localpath)
+ template_values = self.InitializeTemplate()
+ if self.request.path.endswith('/console'):
+ template_values = self.InitializeTemplate()
+ template_values['body_class'] = page_data.get('body_class')
+ template_values['content'] = page_data.get('content')
+ template_values['offsite_base'] = page_data.get('offsite_base')
+ template_values['title'] = page_data.get('title')
+ if self.user:
+ reloadarg = utils.clean_int(self.request.get('reload'), -1)
+ if reloadarg != -1:
+ reloadarg = max(reloadarg, 30)
+ template_values['reloadarg'] = reloadarg
+ else:
+ # Make the Google Frontend capable of caching this request for 60
+ # seconds.
+ # TODO: Caching is not working yet.
+ self.response.headers['Cache-Control'] = 'public, max-age=60'
+ self.response.headers['Pragma'] = 'Public'
+ self.DisplayTemplate('base.html', template_values)
+ return
+
# Make the Google Frontend capable of caching this request for 60 seconds.
# TODO: Caching is not working yet.
- # E1101: 83,4:PageAction.get: Instance of 'PageAction' has no 'response'
- # member
- # pylint: disable=E1101
self.response.headers['Cache-Control'] = 'public, max-age=60'
- # E1101: 83,4:PageAction.get: Instance of 'PageAction' has no 'response'
- # member
- # pylint: disable=E1101
self.response.headers['Pragma'] = 'Public'
- # E1101: 83,4:PageAction.get: Instance of 'PageAction' has no 'response'
- # member
- # pylint: disable=E1101
- self.response.headers['Content-Type'] = app.path_to_mime_type(
- unquoted_localpath)
- self.response.out.write(content)
+ self.response.out.write(page_data.get('content'))
-class FetchPagesAction(MyRequestHandler):
+class FetchPagesAction(base_page.BasePage):
# R0201: 93,2:FetchPagesAction.get: Method could be a function
# pylint: disable=R0201
@@ -90,17 +70,15 @@ class FetchPagesAction(MyRequestHandler):
deferred.defer(app.fetch_pages)
-class MainAction(MyRequestHandler):
+class MainAction(base_page.BasePage):
def get(self):
- # E1101: 96,4:MainAction.get: Instance of 'MainAction' has no 'redirect'
- # member
- # pylint: disable=E1101
self.redirect('/p/chromium/console')
# Call initial bootstrap for the app module.
app.bootstrap()
+base_page.bootstrap()
# GAE will cache |application| across requests if we set it here. See
# http://code.google.com/appengine/docs/python/runtime.html#App_Caching for more
« no previous file with comments | « base_page.py ('k') | pylintrc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698