Changeset 3027
- Timestamp:
- 01/10/08 20:07:03 (10 months ago)
- Files:
-
- addcommentmacro/0.11/addcomment/macro.py (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
addcommentmacro/0.11/addcomment/macro.py
r2818 r3027 9 9 from trac.util import TracError 10 10 from trac.util.text import to_unicode 11 from trac.web.chrome import add_link, add_script 12 from trac.wiki.api import parse_args 11 from trac.web.api import IRequestFilter, RequestDone 12 from trac.web.chrome import add_script 13 from trac.wiki.api import parse_args, IWikiMacroProvider 13 14 from trac.wiki.macros import WikiMacroBase 14 15 from trac.wiki.model import WikiPage 15 16 17 from macropost.api import IMacroPoster 16 18 17 19 class AddCommentMacro(WikiMacroBase): … … 26 28 }}} 27 29 """ 28 30 implements(IWikiMacroProvider, IRequestFilter, IMacroPoster) 31 29 32 def expand_macro(self, formatter, name, content): 30 33 … … 109 112 if submitted: 110 113 page.text = newtext 111 page.save(authname, 'Comment added', req.environ['REMOTE_ADDR']) 112 req.warning("Comment saved.") 113 req.redirect(page_url) 114 page.save(authname, 'Comment added.', req.environ['REMOTE_ADDR']) 115 # We can't redirect from macro as it will raise RequestDone 116 # which like other macro errors gets swallowed in the Formatter. 117 # We need to re-raise it in a post_process_request instead. 118 try: 119 req._outheaders = [] 120 req.redirect(page_url) 121 except RequestDone: 122 req.addcomment_raise = True 114 123 else: 115 124 the_message = tag.div(tag.strong("ERROR: "), "[[AddComment]] " … … 160 169 return tag.div(the_preview, the_message, the_form, id="commenting") 161 170 171 # IMacroPoster method 172 162 173 def process_macro_post(self, req): 163 174 self.log.debug('AddCommentMacro: Got a POST') 164 175 176 # IRequestFilter methods 177 178 def pre_process_request(self, req, handler): 179 return handler 180 181 def post_process_request(self, req, template, data, content_type): 182 if hasattr(req, 'addcomment_raise'): 183 self.env.log.debug("AddCommentMacro: Re-raising RequestDone from redirect") 184 raise RequestDone 185 return template, data, content_type
