Show
Ignore:
Timestamp:
05/23/08 16:33:49 (6 months ago)
Author:
JensDiemer
Message:

new page_msg system. Use a middleware to make page_msg lazy: ticket:193

  • update settings_example.py (insert new middleware)
  • change """contextpage_msg?""" to """request.page_msg"""
  • add a simple page_msg unittest (Need more tests!)
  • update _install data (Templates and index page)
Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/pylucid/PyLucid/middlewares/pagestats.py

    r1546 r1585  
    2525 
    2626from PyLucid.template_addons.filters import human_duration 
     27from PyLucid.middlewares.utils import is_html, replace_content 
    2728 
    2829# Save the start time of the current running pyhon instance 
     
    5152        """ 
    5253        # Put only the statistic into HTML pages 
    53         if not "html" in response._headers["content-type"][1]: 
     54        if not is_html(response): 
    5455            # No HTML Page -> do nothing 
    5556            return response 
     
    6970        } 
    7071 
    71         content = response.content 
    72         if not isinstance(content, unicode): 
    73             # FIXME: In my shared webhosting environment is response.content a 
    74             # string and not unicode. Why? 
    75             from django.utils.encoding import force_unicode 
    76             try: 
    77                 content = force_unicode(content) 
    78             except: 
    79                 return response 
     72        # insert the page statistic 
     73        response = replace_content(response, TAG, stat_info) 
    8074 
    81 #        content = self.debug_sql_queries(content) 
    82  
    83         # insert the page statistic 
    84         new_content = content.replace(TAG, stat_info) 
    85         response.content = new_content 
     75        #response = self.debug_sql_queries(response) 
    8676 
    8777        return response 
    8878 
    89     def debug_sql_queries(self, content): 
     79    def debug_sql_queries(self, response): 
     80        """ 
     81        Insert all SQL queries. 
     82        ONLY for developers! 
     83        """ 
    9084        show_only = ("PyLucid_plugin", "PyLucid_preference2") 
    9185        sql_info = "<h2>Debug SQL queries:</h2>" 
     
    106100            sql_info += "\n%s\n%s\n" % (time, sql) 
    107101        sql_info += "</pre></body>" 
    108         content = content.replace("</body>", sql_info) 
    109         return content 
     102 
     103        response = replace_content(response, "</body>", sql_info) 
     104 
     105        return response