changeset 4:ce757057961c

flow contol now works; bumping version
author k0s <k0scist@gmail.com>
date Wed, 24 Feb 2010 20:11:25 -0500
parents b0ef5452a740
children 6c6766109dac
files captchamiddleware/example.py captchamiddleware/middleware.py setup.py
diffstat 3 files changed, 15 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/captchamiddleware/example.py	Tue Feb 23 20:08:22 2010 -0500
+++ b/captchamiddleware/example.py	Wed Feb 24 20:11:25 2010 -0500
@@ -3,7 +3,12 @@
 from paste.httpexceptions import HTTPExceptionHandler
 
 def example_app(environ, start_response):
-    return Response('<html><body><p>method=%s</p><form method="post">Hello, world!<input type="submit"/></form></body></html>' % environ['REQUEST_METHOD'])(environ, start_response)
+    method = environ['REQUEST_METHOD']
+    form = ''
+    if method != 'POST':
+        form = '<form method="post">Hello, world!<input type="submit"/></form>'
+
+    return Response('<html><body><p>method=%s</p>%s</body></html>' % (method, form))(environ, start_response)
 
 
 def factory(global_conf, **app_conf):
--- a/captchamiddleware/middleware.py	Tue Feb 23 20:08:22 2010 -0500
+++ b/captchamiddleware/middleware.py	Wed Feb 24 20:11:25 2010 -0500
@@ -65,7 +65,13 @@
     def __call__(self, environ, start_response):
         request = Request(environ)
         if request.method == 'POST' and not request.remote_user:
-            return self.app(environ, start_response)
+            if not self.check_captcha(request):
+                location = request.referrer
+                return exc.HTTPSeeOther(location=location)(environ, start_response)
+            # TODO: set a cookie to record an error
+            # stage 2: record form values from request.POST,
+            # and reinsert them into the form so that users
+            # don't hate me ;)
 
         return LXMLMiddleware.__call__(self, environ, start_response)
 
--- a/setup.py	Tue Feb 23 20:08:22 2010 -0500
+++ b/setup.py	Wed Feb 24 20:11:25 2010 -0500
@@ -1,7 +1,7 @@
 from setuptools import setup, find_packages
 import sys, os
 
-version = "0.1.1"
+version = "0.2"
 
 setup(name='CAPTCHAmiddleware',
       version=version,
@@ -11,7 +11,7 @@
       classifiers=[], # Get strings from http://www.python.org/pypi?%3Aaction=list_classifiers
       author='Jeff Hammel',
       author_email='k0scist@gmail.com',
-      url='http://k0s.org',
+      url='http://k0s.org/hg',
       license="GPL",
       packages=find_packages(exclude=['ez_setup', 'examples', 'tests']),
       include_package_data=True,