Mercurial > hg > bitsyblog
comparison bitsyblog/bitsyblog.py @ 72:c9bab68d00ac
* add handlers argument class default
* pass full url to handler
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Thu, 08 Jul 2010 10:48:13 -0700 |
parents | 0c98d1c2c6df |
children | 2c219b788648 6b8ccf6ec819 |
comparison
equal
deleted
inserted
replaced
71:0c98d1c2c6df | 72:c9bab68d00ac |
---|---|
54 'header': None, # text to insert as first child of body' | 54 'header': None, # text to insert as first child of body' |
55 'template_directories': '', # space separated template_directories | 55 'template_directories': '', # space separated template_directories |
56 'auto_reload': 'True', # reload the genshi templates | 56 'auto_reload': 'True', # reload the genshi templates |
57 'help_file': None, # help to display | 57 'help_file': None, # help to display |
58 'feed_items': 10, # number of RSS/atom items to display | 58 'feed_items': 10, # number of RSS/atom items to display |
59 'post_handlers': '' # post handlers | |
59 } | 60 } |
60 | 61 |
61 | 62 |
62 cooked_bodies = {} | 63 cooked_bodies = {} |
63 | 64 |
105 | 106 |
106 # for BitsyAuth | 107 # for BitsyAuth |
107 self.newuser = self.users.new | 108 self.newuser = self.users.new |
108 | 109 |
109 # post handlers | 110 # post handlers |
111 self.post_handlers = [ i for i in self.post_handlers.split() if i ] | |
110 self.handlers = [] # handlers for blog post event | 112 self.handlers = [] # handlers for blog post event |
111 for entry_point in iter_entry_points('bitsyblog.listeners'): | 113 for entry_point in iter_entry_points('bitsyblog.listeners'): |
112 try: | 114 if entry_point.name in self.post_handlers: |
113 handler = entry_point.load()(self, **handler_args.get(entry_point.name, {})) | 115 try: |
114 self.handlers.append(handler) | 116 handler = entry_point.load()(self, **handler_args.get(entry_point.name, {})) |
115 except: | 117 self.handlers.append(handler) |
116 print 'Cant load entry point %s' % entry_point.name | 118 except: |
117 continue | 119 print 'Cant load entry point %s' % entry_point.name |
118 | 120 raise |
119 | 121 |
120 ### methods dealing with HTTP | 122 ### methods dealing with HTTP |
121 | 123 |
122 def __call__(self, environ, start_response): | 124 def __call__(self, environ, start_response): |
123 request = Request(environ) | 125 request = Request(environ) |
335 # determine if the post is secret or private | 337 # determine if the post is secret or private |
336 privacy = request.GET.get('privacy') or request.POST.get('privacy') or 'public' | 338 privacy = request.GET.get('privacy') or request.POST.get('privacy') or 'public' |
337 | 339 |
338 # write the file | 340 # write the file |
339 now = utils.datestamp(datetime.datetime.now()) | 341 now = utils.datestamp(datetime.datetime.now()) |
340 location = self.user_url(request, user, now) | 342 location = self.user_url(request, user, now, permalink=True) |
341 blog_entry = self.blog.post(user, now, body, privacy) | 343 blog_entry = self.blog.post(user, now, body, privacy) |
342 | 344 |
343 # fire event handlers | 345 # fire event handlers |
344 # XXX could be done asynchronously | 346 # XXX could be done asynchronously |
345 for handler in self.handlers: | 347 for handler in self.handlers: |
346 handler(blog_entry) | 348 handler(blog_entry, location) |
347 | 349 |
348 # point the user at the post | 350 # point the user at the post |
349 return exc.HTTPSeeOther("Post blogged by bitsy", location=location) | 351 return exc.HTTPSeeOther("Post blogged by bitsy", location=location) |
350 | 352 |
351 def put(self, request): | 353 def put(self, request): |
444 path = [''] | 446 path = [''] |
445 path = [ i.strip('/') for i in path ] | 447 path = [ i.strip('/') for i in path ] |
446 if permanant: | 448 if permanant: |
447 application_url = request.application_url | 449 application_url = request.application_url |
448 else: | 450 else: |
449 | |
450 application_url = urlparse(request.application_url)[2] | 451 application_url = urlparse(request.application_url)[2] |
451 path = [ application_url ] + list(path) | 452 path = [ application_url ] + list(path) |
452 return '/'.join(path) | 453 return '/'.join(path) |
453 | 454 |
454 def user_url(self, request, user, *args, **kw): | 455 def user_url(self, request, user, *args, **kw): |