Ñò üù¼Ic @ sÝ d d k Z d d k l Z l Z d d k l Z y d d k Z Wn e j o d d k Z n Xd g Z d e i j Z e e ƒ Z d e f d „ ƒ YZ h d d 6d d 6d d 6d d 6d d 6Z d „ Z d „ Z d S( iÿÿÿÿN( t quotet unquote( t getLoggert Flasht WEBFLASH_DEBUGc B s³ e Z d Z d Z d Z d Z d d d d d e d „ Z d „ Z d „ Z e e e ƒ Z d d d d „ Z d „ Z d „ Z e d d d „ Z d „ Z d „ Z d d d „ Z RS( s§ A flash message creator. *Parameters (all optional):* `cookie_name` The name of the cookie that will be used as transport `default_status` The CSS class that will be added to the flash container when it is not passed explicitly when calling the Flash instance. `get_response` A callable that will provide the response object of the framework if no explicit response is passed when calling the Flash instance. `js_path` Shall you want to override the JS code that will display the flash message then pass the path to where the file lives. Note that this is a path within the file-system, not a URL `debug` Should the JS code be provided in an uncompressed form (provided that js_path has not been overriden) and reloaded every time a page is rendered? Flash needs a Reponse object with a `set_cookie` method, like WebOb's :class:`webob.Response`. We'll mock one for demonstration purposes:: >>> class MyResponse(object): ... def set_cookie(self, name, value): ... pass The :class:`Flash` object could be instantiated once for the lifetime of an application and be kept at module scope (or a request-local object if the framework provides one). A :meth:`get_response` callable is useful in this case if the framework provides a global response to avoid passing the response object around on every call to the :class:`Flash` instance:: >>> flash = Flash(get_response=lambda: MyResponse()) Displaying the flash message is done by calling the Flash instance from your controller/view code:: >>> flash("All your data has been erased and your identity destroyed") >>> flash("Stuff broke", status="error") To insert the JavaScript code needed for Flash to work you need to insert the result of the :meth:`render` method on every page you might want to display flash messages (normally all of them, so you might want to include the call in a base template):: >>> _ = flash.render("flash-container") sq
sJ