Changeset 1585 for trunk/pylucid/PyLucid/system/page_msg.py
- Timestamp:
- 05/23/08 16:33:49 (22 months ago)
- Files:
-
- 1 modified
-
trunk/pylucid/PyLucid/system/page_msg.py (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/pylucid/PyLucid/system/page_msg.py
r1544 r1585 33 33 import os, sys, pprint, inspect 34 34 35 from django.utils.safestring import mark_safe 35 from django.utils.safestring import mark_safe, SafeData 36 from django.utils.encoding import force_unicode 37 36 38 from django.conf import settings 37 38 39 39 40 from PyLucid.tools.utils import escape … … 46 47 """ 47 48 def __init__(self, context): 49 request = context["request"] 50 48 51 try: 49 self.messages = context["messages"] 50 except KeyError: 51 # No django messages inserted by RequestContext 52 # In the _install section we use no RequestContext ;) 52 self.messages = request.user.get_and_delete_messages() 53 except AttributeError: 54 # In the _install section we have no user 53 55 self.messages = [] 54 56 55 request = context["request"]56 57 self.debug_mode = getattr(request, "debug", False) 57 58 … … 85 86 color, self.prepare(*msg) 86 87 ) 87 88 88 #~ self.request.user.message_set.create(message=msg) 89 89 msg = mark_safe(msg) # turn djngo auto-escaping off … … 93 93 """ 94 94 Append the fileinfo: Where from the announcement comes? 95 Only, if debug_mode is on.96 95 """ 97 if self.debug_mode != True:98 return ""99 100 96 try: 101 97 self_basename = os.path.basename(__file__) … … 126 122 -for dict, list use pprint ;) 127 123 """ 128 result = [self._get_fileinfo()] 124 if self.debug_mode == True: 125 result = [self._get_fileinfo()] 126 else: 127 result = [] 129 128 130 129 for item in msg: … … 141 140 142 141 result = "".join(result) 143 return escape(result)142 return result 144 143 145 144 def encode_and_prepare(self, txt): 146 145 """ 147 returns the given txt as a string object.146 Pass "safe" strings, all other would be escaped. 148 147 """ 149 if isinstance(txt, unicode):150 return txt .encode(self._charset)148 if isinstance(txt, SafeData): 149 return txt 151 150 152 # FIXME: Is that needed??? 153 try: 154 return str(txt) 155 except: 156 return repr(txt) 151 if not isinstance(txt, unicode): 152 txt = force_unicode(txt) 153 154 return escape(txt) 155 156 157 #________________________________________________________________ 158 159 def __repr__(self): 160 return "page messages: %s" % repr(self.messages) 161 162 def __str__(self): 163 return "pages messages: %s" % ", ".join(self.messages) 164 165 def __unicode__(self): 166 return u"page messages: %s" % u", ".join(self.messages) 157 167 158 168 #________________________________________________________________