Changeset 1691 for trunk/pylucid/PyLucid/system/page_msg.py
- Timestamp:
- 07/18/08 12:58:51 (20 months ago)
- Files:
-
- 1 modified
-
trunk/pylucid/PyLucid/system/page_msg.py (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/pylucid/PyLucid/system/page_msg.py
r1634 r1691 2 2 3 3 """ 4 A small Wrapper aound djangos user messages system: 5 http://www.djangoproject.com/documentation/authentication/#messages 4 The PyLucid page message system 5 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 6 6 7 enhanced features: 8 - easy callable to print a messages 9 - simple color output: self.page_msg.green() 10 - use pprint for dicts and lists 11 - special debug mode: Inserts informationen, where from the message has come. 7 A small Wrapper aound djangos user messages system. 12 8 13 In PyLucid modules/plugins, you can use the old system, but it use the django 14 messages to store the data: 15 self.page_msg("I am a new django user message in the old PyLucid style ;)") 16 self.page_msg.red("Alert!") 9 enhanced features: 10 - easy callable to print a messages 11 - simple color output: self.page_msg.green() 12 - use pprint for dicts and lists 13 - special debug mode: 14 Inserts informationen, where from the message has come. 15 16 Can also used in Plugin for storing internal messages. 17 18 Links 19 ~~~~~ 20 http://www.pylucid.org/_goto/134/plugin-output/ 21 http://www.djangoproject.com/documentation/authentication/#messages 17 22 18 23 19 Last commit info:20 ---------------------------------- 21 $LastChangedDate$22 $Rev$23 $Author$24 Last commit info: 25 ~~~~~~~~~~~~~~~~~ 26 $LastChangedDate$ 27 $Rev$ 28 $Author$ 24 29 25 Created by Jens Diemer 26 27 license: 28 GNU General Public License v2 or above 29 http://www.opensource.org/licenses/gpl-license.php 30 :copyleft: 2008 by the PyLucid team, see AUTHORS for more details. 31 :license: GNU GPL v3 or above, see LICENSE for more details. 30 32 """ 31 33 … … 43 45 class PageMessages(object): 44 46 """ 45 http://www.djangoproject.com/documentation/authentication/#messages47 The page message container. 46 48 """ 47 def __init__(self, request): 48 try: 49 self.messages = request.user.get_and_delete_messages() 50 except AttributeError: 51 # In the _install section we have no user 52 self.messages = [] 49 def __init__(self, request, use_django_msg=True, html=True): 50 self.html = html # Should we generate colored html output? 51 52 self.messages = [] 53 if use_django_msg: 54 try: 55 self.messages = request.user.get_and_delete_messages() 56 except AttributeError: 57 # In the _install section we have no user 58 pass 53 59 54 60 self.debug_mode = getattr(request, "debug", False) … … 80 86 81 87 def append_color_data(self, color, *msg): 82 msg = '<span style="color:%s;">%s</span>' % ( 83 color, self.prepare(*msg) 84 ) 88 if self.html: 89 msg = '<span style="color:%s;">%s</span>' % ( 90 color, self.prepare(*msg) 91 ) 92 else: 93 msg = self.prepare(*msg) 94 85 95 #~ self.request.user.message_set.create(message=msg) 86 96 msg = mark_safe(msg) # turn djngo auto-escaping off … … 130 140 for line in item: 131 141 line = self.encode_and_prepare(line) 132 result.append("%s<br />\n" % line) 142 if self.html: 143 result.append("%s<br />\n" % line) 144 else: 145 result.append("%s\n" % line) 133 146 else: 134 147 item = self.encode_and_prepare(item) … … 150 163 151 164 return escape(txt) 152 153 165 154 166 #________________________________________________________________