Show
Ignore:
Timestamp:
07/18/08 12:58:51 (20 months ago)
Author:
JensDiemer
Message:

many updates for the blog plugin

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/pylucid/PyLucid/system/page_msg.py

    r1634 r1691  
    22 
    33""" 
    4 A small Wrapper aound djangos user messages system: 
    5 http://www.djangoproject.com/documentation/authentication/#messages 
     4    The PyLucid page message system 
     5    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    66 
    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. 
    128 
    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 
    1722 
    1823 
    19 Last commit info: 
    20 ---------------------------------- 
    21 $LastChangedDate$ 
    22 $Rev$ 
    23 $Author$ 
     24    Last commit info: 
     25    ~~~~~~~~~~~~~~~~~ 
     26    $LastChangedDate$ 
     27    $Rev$ 
     28    $Author$ 
    2429 
    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. 
    3032""" 
    3133 
     
    4345class PageMessages(object): 
    4446    """ 
    45     http://www.djangoproject.com/documentation/authentication/#messages 
     47    The page message container. 
    4648    """ 
    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 
    5359 
    5460        self.debug_mode = getattr(request, "debug", False) 
     
    8086 
    8187    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 
    8595        #~ self.request.user.message_set.create(message=msg) 
    8696        msg = mark_safe(msg) # turn djngo auto-escaping off 
     
    130140                for line in item: 
    131141                    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) 
    133146            else: 
    134147                item = self.encode_and_prepare(item) 
     
    150163 
    151164        return escape(txt) 
    152  
    153165 
    154166    #________________________________________________________________