Changeset 251:d3a695dd1aa5
- Timestamp:
- 01/30/10 14:49:36 (7 months ago)
- Branch:
- default
- Location:
- shakespeare
- Files:
-
- 2 modified
-
config/deployment.ini_tmpl (modified) (3 diffs)
-
controllers/site.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
shakespeare/config/deployment.ini_tmpl
r245 r251 37 37 #beaker.session.data_dir = %(here)s/data/sessions 38 38 39 # repoze.who authentication 40 # you should not have to change this though you will need to symlink provided 41 # who.ini into same directory as this config file 42 who.config_file = %(here)s/who.ini 43 who.log_level = error 44 who.log_file = stdout 45 39 46 # =========================== 40 47 # User configured variables … … 44 51 # execute malicious code after an exception is raised. 45 52 set debug = false 53 54 # site_title for use around the site 55 # for more serious customization suggest making your own templates (e.g. 56 # layout.html) and using extra_template_paths option 57 # site_title = Your Site Title 46 58 47 59 # We use sqlalchemy to connect and work with databases. … … 63 75 # extra_template_paths = %(here)s/shksprdata/templates 64 76 65 # repoze.who authentication 66 # you should not have to change this 67 who.config_file = %(here)s/who.ini 68 who.log_level = error 69 who.log_file = stdout 77 ## deliverance/proxying stuff 78 # set to any value to enable 79 deliverance.enable = 80 # destination to proxy from 81 deliverance.dest = http://blog.openshakespeare.org/ 82 70 83 71 84 # Logging configuration -
shakespeare/controllers/site.py
r164 r251 1 1 import logging 2 import os 2 3 3 4 import genshi 5 from pylons import config 4 6 5 7 from shakespeare.lib.base import * … … 15 17 log = logging.getLogger(__name__) 16 18 19 DELIVERANCE_ENABLE = bool(config.get('deliverance.enable', '')) 20 print DELIVERANCE_ENABLE 21 22 23 # based on http://rufuspollock.org/code/deliverance 24 import paste.urlmap 25 import deliverance.middleware 26 import paste.proxy 27 from webob import Request, Response 28 from deliverance.middleware import DeliveranceMiddleware, SubrequestRuleGetter 29 from deliverance.log import PrintingLogger 30 def create_deliverance_proxy(): 31 # where we are proxying from 32 dest = config['deliverance.dest'] 33 34 # use a urlmap so we can mount theme and urlset 35 app = paste.urlmap.URLMap() 36 37 # set up theme consistent with our rules file 38 app['/theme.html'] = Response(render('index.html')) 39 40 # rules_path = os.path.join('demo-rules.xml') 41 # rules = open(rules_path).read() 42 rules = '''<ruleset> 43 44 <theme href="/theme.html" /> 45 46 <!-- These are the default rules for anything with class="default" or no class: --> 47 <rule> 48 <replace content="children:#content" theme="children:#content" /> 49 <append content="children:#sidebar" theme="children:#primary" /> 50 </rule> 51 </ruleset> 52 ''' 53 app['/rules.xml'] = Response(rules, content_type="application/xml") 54 55 class MyProxy(object): 56 def __init__(self, dest): 57 self.proxy = paste.proxy.Proxy(dest) 58 59 def __call__(self, environ, start_response): 60 req = Request(environ) 61 res = req.get_response(self.proxy) 62 # result = '' 63 # for out in self.proxy(environ, start_response): 64 # result += out 65 # res = Response(result) 66 res.decode_content() 67 return res(environ, start_response) 68 69 app['/'] = MyProxy(dest) 70 71 deliv = DeliveranceMiddleware(app, SubrequestRuleGetter('/rules.xml'), 72 PrintingLogger, 73 log_factory_kw=dict(print_level=logging.WARNING)) 74 return deliv 75 17 76 18 77 class SiteController(BaseController): 19 20 78 def index(self): 21 79 return render('index.html') 22 80 23 81 def about(self): 24 return render('about.html') 82 if DELIVERANCE_ENABLE: 83 return self.deliverance(request.environ, self.start_response) 84 else: 85 return render('about.html') 25 86 26 87 def guide(self): 27 88 return render('guide.html') 28 89 90 def news(self): 91 if DELIVERANCE_ENABLE: 92 # modify path for proxy to strip out /news/ 93 currentpath = request.environ['PATH_INFO'] 94 request.environ['PATH_INFO'] = currentpath[5:] 95 return self.deliverance(request.environ, self.start_response) 96 else: 97 return '' 98 99 @property 100 def deliverance(self): 101 if not hasattr(self, '_deliverance'): 102 self._deliverance = create_deliverance_proxy() 103 return self._deliverance 104
