Index: /home/jens/workspace/PyLucid_trunk/pylucid/PyLucid/index.py
===================================================================
--- /home/jens/workspace/PyLucid_trunk/pylucid/PyLucid/index.py (revision 1580)
+++ /home/jens/workspace/PyLucid_trunk/pylucid/PyLucid/index.py (working copy)
@@ -82,6 +82,8 @@
# django template engine:
content = replace_add_data(context, content)
+ print "XXX", request.page_msg
+
return HttpResponse(content)
@@ -97,10 +99,11 @@
context = RequestContext(request)
- context["page_msg"] = PageMessages(context)
+ request.page_msg = PageMessages(context)
# Redirect every "warning" messages into the page_msg:
- redirect_warnings(context["page_msg"])
+# redirect_warnings(request.page_msg)
+ redirect_warnings(request.page_msg)
context["PAGE"] = current_page_obj
context["URLs"] = URLs(context)
@@ -121,9 +124,17 @@
add_dynamic_context(request, context)
# Add the context to the reponse object.
- # Used in PyLucid.middlewares.additional_content
+ # Used in PyLucid middlewares
request.CONTEXT = context
+ # TODO: remove Backwards-incompatible changes in >v0.8.5
+ msg = (
+ 'Error, see: pylucid.org - Backwards-incompatible changes - page_msg'
+ )
+ context["messages"] = [mark_safe(msg)]
+
return context
Index: /home/jens/workspace/PyLucid_trunk/pylucid/PyLucid/install/BaseInstall.py
===================================================================
--- /home/jens/workspace/PyLucid_trunk/pylucid/PyLucid/install/BaseInstall.py (revision 1580)
+++ /home/jens/workspace/PyLucid_trunk/pylucid/PyLucid/install/BaseInstall.py (working copy)
@@ -129,10 +129,10 @@
self.context = get_base_context(request)
self.page_msg = PageMessages(self.context)
- self.context["page_msg"] = self.page_msg
+ self.request.page_msg = self.page_msg
- # Redirect every "warning" messages into context["page_msg"]:
- redirect_warnings(self.context["page_msg"])
+ # Redirect every "warning" messages into request.page_msg:
+ redirect_warnings(self.request.page_msg)
#___________________________________________________________________________
@@ -144,7 +144,7 @@
self.context["no_menu_link"] = True
if msg and msg != "": # insert the messages:
- self.context["page_msg"].write(msg)
+ self.request.page_msg.write(msg)
return render_to_response(
"install_generate_hash.html", self.context
@@ -171,7 +171,7 @@
except Exception, msg:
# Cookie is not set or the salt hash value compair failed
if DEBUG:
- self.context["page_msg"].write("DEBUG: %s" % msg)
+ self.request.page_msg.write("DEBUG: %s" % msg)
else:
# access ok -> start the normal _install view() method
return self.view(*args)
@@ -189,7 +189,7 @@
check_password_hash(password_hash)
except WrongPassword, msg:
# Display the form again
- self.context["page_msg"].write(msg)
+ self.request.page_msg.write(msg)
else:
# Password is ok. -> process the normal _instal view()
response = self.view(*args)
@@ -204,7 +204,7 @@
self.context["salt"] = data["salt"]
self.context["no_menu_link"] = True # no "back to menu" link
-# self.context["page_msg"].write(_("Please input the password"))
+# self.request.page_msg.write(_("Please input the password"))
return render_to_response("install_login.html", self.context)
#___________________________________________________________________________
Index: /home/jens/workspace/PyLucid_trunk/pylucid/PyLucid/install/update.py
===================================================================
--- /home/jens/workspace/PyLucid_trunk/pylucid/PyLucid/install/update.py (revision 1580)
+++ /home/jens/workspace/PyLucid_trunk/pylucid/PyLucid/install/update.py (working copy)
@@ -18,12 +18,20 @@
from django.contrib.auth.models import User
#______________________________________________________________________________
+
+import re
+from PyLucid.tools.Diff import diff_lines
+
+page_msg_re = re.compile(r""".*?({% if messages %}.*?{% endif %})*.?(?uims)""")
+new_page_msg = ""
+
class Update2(BaseInstall):
def view(self):
self._redirect_execute(self._update_tables)
+ self._redirect_execute(self._update_templates)
return self._simple_render(
- headline="Update PyLucid from v0.8.0 to v0.8.1"
+ headline="Update PyLucid from v0.8.0 to v0.8.5"
)
def _update_tables(self):
@@ -39,10 +47,21 @@
else:
print "OK"
+ def _update_templates(self):
+ print "update templates:"
+ templates = Template.objects.all()
+ for template in templates:
+ new_content = old_content = template.content
+
+ for match in page_msg_re.findall(old_content):
+ new_content = new_content.replace(match, new_page_msg)
+
+ diff = diff_lines(old_content, new_content)
+ print diff
def update2(request):
"""
- 1. update from v0.8.0 to v0.8.1
+ 1. update from v0.8.0 to v0.8.5
"""
return Update2(request).start_view()
@@ -427,18 +446,9 @@
"|"
"(.*?)"
)
-PAGE_MSG_TAG = """\
- {% if messages %}
-
- {% endif %}\
-"""
CHANGE_TAGS = {
- "page_msg": PAGE_MSG_TAG,
+ "page_msg": "",
"script_login": "{{ login_link }}",
"robots": "{{ robots }}",
"powered_by": "{{ powered_by }}",
Index: /home/jens/workspace/PyLucid_trunk/pylucid/PyLucid/middlewares/pagemessages.py
===================================================================
--- /home/jens/workspace/PyLucid_trunk/pylucid/PyLucid/middlewares/pagemessages.py (revision 0)
+++ /home/jens/workspace/PyLucid_trunk/pylucid/PyLucid/middlewares/pagemessages.py (revision 0)
@@ -0,0 +1,54 @@
+ # -*- coding: utf-8 -*-
+
+"""
+ PyLucid page messages
+ ~~~~~~~~~~~~~~~~~~~~~
+
+ Last commit info:
+ ~~~~~~~~~~~~~~~~~
+ $LastChangedDate: $
+ $Rev: $
+ $Author: $
+
+ :copyleft: 2008 by Jens Diemer
+ :license: GNU GPL v3, see LICENSE.txt for more details.
+"""
+
+from PyLucid.tools.content_processors import render_string_template
+from PyLucid.middlewares.utils import is_html, replace_content
+
+TAG = u""
+
+TEMPLATE = \
+u""""""
+
+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
Index: /home/jens/workspace/PyLucid_trunk/pylucid/PyLucid/middlewares/pagestats.py
===================================================================
--- /home/jens/workspace/PyLucid_trunk/pylucid/PyLucid/middlewares/pagestats.py (revision 1580)
+++ /home/jens/workspace/PyLucid_trunk/pylucid/PyLucid/middlewares/pagestats.py (working copy)
@@ -24,6 +24,7 @@
from django.db import connection
from PyLucid.template_addons.filters import human_duration
+from PyLucid.middlewares.utils import is_html, replace_content
# Save the start time of the current running pyhon instance
start_overall = time()
@@ -50,7 +51,7 @@
calculate the statistic and replace it into the html page.
"""
# Put only the statistic into HTML pages
- if not "html" in response._headers["content-type"][1]:
+ if not is_html(response):
# No HTML Page -> do nothing
return response
@@ -68,25 +69,18 @@
'queries' : queries,
}
- content = response.content
- if not isinstance(content, unicode):
- # FIXME: In my shared webhosting environment is response.content a
- # string and not unicode. Why?
- from django.utils.encoding import force_unicode
- try:
- content = force_unicode(content)
- except:
- return response
-
-# content = self.debug_sql_queries(content)
+ # insert the page statistic
+ response = replace_content(response, TAG, stat_info)
- # insert the page statistic
- new_content = content.replace(TAG, stat_info)
- response.content = new_content
+ #response = self.debug_sql_queries(response)
return response
- def debug_sql_queries(self, content):
+ def debug_sql_queries(self, response):
+ """
+ Insert all SQL queries.
+ ONLY for developers!
+ """
show_only = ("PyLucid_plugin", "PyLucid_preference2")
sql_info = "Debug SQL queries:
"
if show_only:
@@ -105,5 +99,7 @@
sql = sql.replace(' WHERE "', '\nWHERE "')
sql_info += "\n%s\n%s\n" % (time, sql)
sql_info += "