def process_response(self, request, response): """ calculate the statistic and replace it into the html page. """ # Put only the statistic into HTML pages if not is_html(response): # No HTML Page -> do nothing return response context = { 'total_time' : human_duration(time() - self.start_time), 'overall_time' : human_duration(time() - start_overall), } if settings.DEBUG: # compute the db time for the queries just run, this information is # only available if the debug cursor used context["queries"] = len(connection.queries) - self.old_queries stat_info = FMT_DEBUG % context else: # Used the template without queries stat_info = FMT % context # insert the page statistic response = replace_content(response, TAG, stat_info) #response = self.debug_sql_queries(response) return response
def debug_sql_queries(self, response): """ Insert all SQL queries. ONLY for developers! """ show_only = ("PyLucid_plugin", "PyLucid_preference2") sql_info = "<h2>Debug SQL queries:</h2>" if show_only: sql_info += "Show only: %s" % ", ".join(show_only) sql_info += "<pre>" for q in connection.queries: sql = q['sql'] if show_only: table_name = sql.split(' FROM "')[1].split('"', 1)[0] if table_name not in show_only: continue time = float(q['time']) sql = sql.replace(' FROM "', '\nFROM "') sql = sql.replace(' WHERE "', '\nWHERE "') sql_info += "\n%s\n%s\n" % (time, sql) sql_info += "</pre></body>" response = replace_content(response, "</body>", sql_info) return response
{% for message in page_msg %}\t{{ message }}<br /> {% endfor %} </fieldset>""" class PageMessagesMiddleware(object): def process_response(self, request, response): """ insert all page messages into the html page. """ if not is_html(response): # No HTML Page -> do nothing return response try: # get PyLucid.system.page_msg.PageMessages(): page_msg = request.page_msg except AttributeError, e: message_string = "Error getting page_msg: %s" % e else: if len(page_msg) == 0: # There exists no page messages message_string = "" else: message_string = render_string_template( TEMPLATE, context={"page_msg": page_msg} ) response = replace_content(response, TAG, message_string) return response