comparison taginthemiddle/middleware.py @ 2:1182315b18ac

add rudimentary code for handlers
author Jeff Hammel <jhammel@mozilla.com>
date Tue, 04 May 2010 19:15:21 -0700
parents 837cfc05d4d9
children 8fb20b780341
comparison
equal deleted inserted replaced
1:837cfc05d4d9 2:1182315b18ac
3 data persisting across requests should go here 3 data persisting across requests should go here
4 """ 4 """
5 5
6 import os 6 import os
7 7
8 from handlers import Index 8 from handlers import TagCloud, ViewTags, PostTags
9 from model import Tags 9 from model import Tags
10 10
11 from genshi.template import TemplateLoader 11 from genshi.template import TemplateLoader
12 from lxmlmiddleware import LXMLMiddleware 12 from lxmlmiddleware import LXMLMiddleware
13 from paste.fileapp import FileApp 13 from paste.fileapp import FileApp
19 # instance defaults 19 # instance defaults
20 defaults = { 'auto_reload': 'False', 20 defaults = { 'auto_reload': 'False',
21 'template_dirs': '', 21 'template_dirs': '',
22 'patterns': '*' 22 'patterns': '*'
23 'tags_file': None, 23 'tags_file': None,
24 'url': 'tags' 24 'tags_url': 'tags',
25 'post_url': '.tags' 25 'post_url': '.tags',
26 'author': None, # for RSS
26 } 27 }
27 28
28 def __init__(self, app, **kw): 29 def __init__(self, app, **kw):
29 self.app = app 30 self.app = app
30 31
31 # set instance parameters from kw and defaults 32 # set instance parameters from kw and defaults
32 for key in self.defaults: 33 for key in self.defaults:
33 setattr(self, key, kw.get(key, self.defaults[key])) 34 setattr(self, key, kw.get(key, self.defaults[key]))
34 self.auto_reload = self.auto_reload.lower() == 'true' 35 self.auto_reload = self.auto_reload.lower() == 'true'
35 assert self.tags_file is not None 36 assert self.tags_file is not None
36 self.tags 37 self.tags = Tags(self.tags_file)
37 self.patterns = self.patterns.strip().split() 38 self.patterns = self.patterns.strip().split()
38 39
39 # request handlers 40 # request handlers
40 self.handlers = [ Cloud ] 41 self.handlers = [ TagCloud, ViewTags, PostTags ]
41 42
42 # template loader 43 # template loader
43 self.template_dirs = self.template_dirs.split() 44 self.template_dirs = self.template_dirs.split()
44 self.template_dirs.append(resource_filename(__name__, 'templates')) 45 self.template_dirs.append(resource_filename(__name__, 'templates'))
45 self.loader = TemplateLoader(self.template_dirs, 46 self.loader = TemplateLoader(self.template_dirs,