Ian Lewis avatar Ian Lewis committed ad1ebce

Added an AppStatsMiddleware for easy recording of data using appstats

Comments (0)

Files changed (2)

Add a comment to this file

kay/ext/appstats/__init__.py

Empty file added.

kay/ext/appstats/middleware.py

+#!/usr/bin/env python2.5
+# -*- coding:utf-8 -*-
+
+"""
+AppStatsMiddleware adapted to Kay framework.
+
+:Copyright: (c) 2010 Ian Lewis <ianmlewis@gmail.com>,
+:license: BSD, see LICENSE for more details.
+"""
+
+class AppStatsMiddleware(object):
+  """
+  Middleware to enable appstats recording.
+
+  Based off of the the AppstatsDjangoMiddleware in the 
+  Appengine SDK
+  """
+
+  def process_request(self, request):
+    """
+    Called by Django before deciding which view to execute.
+    """
+    from google.appengine.ext.appstats.recording import start_recording
+    start_recording()
+
+  def process_response(self, request, response):
+    """
+    Stops recording. Optionally sets some extension data for
+    FirePython.
+    """
+    from google.appengine.ext.appstats.recording import end_recording
+
+    firepython_set_extension_data = getattr(
+      request,
+      'firepython_set_extension_data',
+      None)
+    end_recording(response.status_code, firepython_set_extension_data)
+    return response
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.