Use pyramid flash queue for messages
authorChristophe de Vienne <christophe@unlish.com>
Sat, 25 Apr 2015 20:50:57 +0200
changeset 11566 59548227ecc9
parent 11565 6398be12f8e6
child 11567 4f8aa5fcd5da
Use pyramid flash queue for messages Use a 'cubicweb' flash queue and make sure it contains only one message so that the behavior is the same as cubicweb. Also, the 'message' property now returns both the cubicweb flash queue and the default flash queue. One big difference with the former behaviour is that messages set with set_message will survive a redirection, making set_redirect_message useless in most case. Closes #5298654
pyramid_cubicweb/core.py
--- a/pyramid_cubicweb/core.py	Wed Feb 25 22:40:39 2015 +0100
+++ b/pyramid_cubicweb/core.py	Sat Apr 25 20:50:57 2015 +0200
@@ -185,6 +185,27 @@
 
     status_out = property(_get_status_out, _set_status_out)
 
+    @property
+    def message(self):
+        """Returns a '<br>' joined list of the cubicweb current message and the
+        default pyramid flash queue messages.
+        """
+        return u'\n<br>\n'.join(
+            self._request.session.pop_flash()
+            + self._request.session.pop_flash('cubicweb'))
+
+    def set_message(self, msg):
+        self.reset_message()
+        self._request.session.flash(msg, 'cubicweb')
+
+    def set_message_id(self, msgid):
+        self.reset_message()
+        self.set_message(
+            self._request.session.pop(msgid, u''))
+
+    def reset_message(self):
+        self._request.session.pop_flash('cubicweb')
+
 
 def render_view(request, vid, **kwargs):
     """ Helper function to render a CubicWeb view.