def filter_stream(self, req, method, filename, stream, data): """Return a filtered Genshi event stream, or the original unfiltered stream if no match. `req` is the current request object, `method` is the Genshi render method (xml, xhtml or text), `filename` is the filename of the template to be rendered, `stream` is the event stream and `data` is the data for the current template. See the Genshi documentation for more information. """ # only show CAPTCHAs for anonymous users if req.authname != 'anonymous': return stream # only put CAPTCHAs in the realms specified realm = self.realm(req) if realm not in self.realms: return stream # add the CAPTCHA to the stream if filename in self.xpath: # store CAPTCHA in DB and session word = random_word(self.dict_file) insert_update(self.env, 'captcha', 'id', req.session.sid, dict(word=word)) req.session['captcha'] = word req.session.save() # render the template chrome = Chrome(self.env) template = chrome.load_template('captcha.html') _data = {} # CAPTCHA type if self.captcha_type == 'png': captcha = tag.img(None, src=req.href('captcha.png')) else: captcha = Markup(skimpyAPI.Pre(word).data()) _data['captcha'] = captcha _data['email'] = req.session.get('email', '') _data['name'] = req.session.get('name', '') _data['captchaid'] = req.session.sid xpath = self.xpath[filename] stream |= Transformer(xpath).before(template.generate(**_data)) if filename in self.delete: stream |= Transformer(self.delete[filename]).remove() return stream
def set_default(self, ticket_id, image): insert_update(self.env, 'default_image', 'ticket', ticket_id, dict(image=image))
def set_default(self, ticket_id, image): insert_update(self.env, "default_image", "ticket", ticket_id, dict(image=image))