diff simplewiki/handlers.py @ 1:4c83f7715993

[mq]: renderer
author Jeff Hammel <jhammel@mozilla.com>
date Tue, 07 Sep 2010 18:11:04 -0700
parents d5102c881cb5
children 2464e2051b78
line wrap: on
line diff
--- a/simplewiki/handlers.py	Tue Sep 07 17:50:04 2010 -0700
+++ b/simplewiki/handlers.py	Tue Sep 07 18:11:04 2010 -0700
@@ -3,6 +3,7 @@
 these are instantiated for every request, then called
 """
 
+import os
 from urlparse import urlparse
 from webob import Response, exc
 
@@ -49,10 +50,33 @@
     def redirect(self, location):
         raise exc.HTTPSeeOther(location=location)
 
-class GenshiHandler(Handler):
+class GenshiRenderer(Handler):
+
+    @classmethod
+    def match(cls, app, request):
+
+        # check the method
+        if request.method not in cls.methods:
+            return None
+
+        # check the path
+        path = request.environ['path']
+        if not path:
+            return None
+        if not path[-1].endswith('.html'):
+            return None
+
+        
+        try:
+            return cls(app, request)
+        except HandlerMatchException:
+            return None
 
     def __init__(self, app, request):
         Handler.__init__(self, app, request)
+        self.template = os.path.join(app.directory, *request.environ['path'])
+        if not os.path.exists(self.template):
+            raise HandlerMatchException
         self.data = { 'request': request,
                       'link': self.link }
 
@@ -65,17 +89,3 @@
         return Response(content_type='text/html',
                         body=template.generate(**self.data).render('html'))
 
-class Index(GenshiHandler):
-    template = 'index.html'
-    methods=set(['GET', 'POST'])
-
-    def __init__(self, app, request):
-        GenshiHandler.__init__(self, app, request)
-
-    def Get(self):
-        self.data['name'] = self.request.remote_user or self.app.name
-        return GenshiHandler.Get(self)
-
-    def Post(self):
-        self.app.name = self.request.POST.get('name', self.app.name)
-        self.redirect(self.link(self.handler_path))