changeset 3924:14afe4d1363d beta

Fixes #852, created custom Flash() class and Message transport class to overcome issues with unicode errors.
author Marcin Kuzminski <marcin@python-works.com>
date Sat, 01 Jun 2013 01:03:31 +0200
parents f06bb68caef5
children 8ddf35e02d05
files rhodecode/lib/helpers.py
diffstat 1 files changed, 35 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/rhodecode/lib/helpers.py	Sat Jun 01 01:02:53 2013 +0200
+++ b/rhodecode/lib/helpers.py	Sat Jun 01 01:03:31 2013 +0200
@@ -355,7 +355,41 @@
     from rhodecode.model.scm import ScmModel
     return ScmModel().is_following_repo(repo_name, user_id)
 
-flash = _Flash()
+class _Message(object):
+    """A message returned by ``Flash.pop_messages()``.
+
+    Converting the message to a string returns the message text. Instances
+    also have the following attributes:
+
+    * ``message``: the message text.
+    * ``category``: the category specified when the message was created.
+    """
+
+    def __init__(self, category, message):
+        self.category=category
+        self.message=message
+
+    def __str__(self):
+        return self.message
+
+    __unicode__ = __str__
+
+    def __html__(self):
+        return escape(safe_unicode(self.message))
+
+class Flash(_Flash):
+
+    def pop_messages(self):
+        """Return all accumulated messages and delete them from the session.
+
+        The return value is a list of ``Message`` objects.
+        """
+        from pylons import session
+        messages = session.pop(self.session_key, [])
+        session.save()
+        return [_Message(*m) for m in messages]
+
+flash = Flash()
 
 #==============================================================================
 # SCM FILTERS available via h.