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 %} -
page message - {% for message in messages %} - {{ message }}
- {% endfor %} -
- {% 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"""
page message +{% for message in page_msg %} + {{ message }}
+{% endfor %} +
""" + +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 += "" - content = content.replace("", sql_info) - return content \ No newline at end of file + + response = replace_content(response, "", sql_info) + + return response \ No newline at end of file Index: /home/jens/workspace/PyLucid_trunk/pylucid/PyLucid/middlewares/utils.py =================================================================== --- /home/jens/workspace/PyLucid_trunk/pylucid/PyLucid/middlewares/utils.py (revision 0) +++ /home/jens/workspace/PyLucid_trunk/pylucid/PyLucid/middlewares/utils.py (revision 0) @@ -0,0 +1,47 @@ + # -*- coding: utf-8 -*- + +""" + PyLucid shared middleware utils + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + Last commit info: + ~~~~~~~~~~~~~~~~~ + $LastChangedDate: $ + $Rev: $ + $Author: $ + + :copyleft: 2008 by Jens Diemer + :license: GNU GPL v3, see LICENSE.txt for more details. +""" + +def is_html(response): + """ + returns a Bool if the response is a html page or not. + """ + if not "html" in response._headers["content-type"][1]: + # Isn't a HTML page + return False + else: + # Is a HTML Page + return True + +def replace_content(response, old, new): + """ + -replace 'old' with 'new' in the response content. + -returns the response object + """ + 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 + + # replace + new_content = content.replace(old, new) + response.content = new_content + + return response Index: /home/jens/workspace/PyLucid_trunk/pylucid/PyLucid/models.py =================================================================== --- /home/jens/workspace/PyLucid_trunk/pylucid/PyLucid/models.py (revision 1580) +++ /home/jens/workspace/PyLucid_trunk/pylucid/PyLucid/models.py (working copy) @@ -578,6 +578,10 @@ """ evaluate the pformat string into a dict and return it. """ + if self.pref_data_string == None: + # Plugin has no preferences inserted + return None + data_dict = data_eval(self.pref_data_string) preference_cache[self.plugin_name] = data_dict return data_dict Index: /home/jens/workspace/PyLucid_trunk/pylucid/PyLucid/plugins_internal/admin_menu/admin_menu.py =================================================================== --- /home/jens/workspace/PyLucid_trunk/pylucid/PyLucid/plugins_internal/admin_menu/admin_menu.py (revision 1580) +++ /home/jens/workspace/PyLucid_trunk/pylucid/PyLucid/plugins_internal/admin_menu/admin_menu.py (working copy) @@ -28,6 +28,8 @@ """ Render the front menu """ + self.page_msg("from admin menu!") + current_page_id = self.current_page.id edit_link = self.URLs.adminLink("PyLucid/page/%s/" % current_page_id) Index: /home/jens/workspace/PyLucid_trunk/pylucid/PyLucid/plugins_internal/back_links/back_links.py =================================================================== --- /home/jens/workspace/PyLucid_trunk/pylucid/PyLucid/plugins_internal/back_links/back_links.py (revision 1580) +++ /home/jens/workspace/PyLucid_trunk/pylucid/PyLucid/plugins_internal/back_links/back_links.py (working copy) @@ -35,16 +35,34 @@ from PyLucid.system.BasePlugin import PyLucidBasePlugin -from PyLucid.models import Page, Preference +from PyLucid.models import Page, Plugin class back_links(PyLucidBasePlugin): - def lucidTag(self, print_last_page=False, print_index=False, index="Index"): + def lucidTag(self, **kwargs): """ generate the backlinks + TODO: **kwargs only for Backwards-incompatible changes info """ + if self.request.debug == True and kwargs != {}: + self.page_msg( + "DeprecationWarning:" + " kwargs in back_links plugin are obsolete. Please remove them." + ) + return + + # Get the preferences from the database: + preferences = self.get_preferences() + if preferences == None: + # preferences not in database -> reinit required + if self.request.debug == True: + self.page_msg.red( + "reinit 'back_links' plugin required!" + ) + return + current_page = self.context["PAGE"] - if print_last_page == True: + if preferences["print_last_page"] == True: print_page = current_page else: print_page = current_page.parent @@ -52,7 +70,7 @@ # There exist no higher-ranking page return "" - data = self.backlink_data(print_page) + data = self._backlink_data(print_page) data.reverse() context = { @@ -57,12 +75,12 @@ context = { "pages": data, - "print_index": print_index, - "index": index, + "print_index": preferences["print_index"], + "index": preferences["index"], } self._render_template("back_links", context)#, debug=True) - def backlink_data(self, parent_page): + def _backlink_data(self, parent_page): """ make a list of all pages in the current way back to the index page. """ Index: /home/jens/workspace/PyLucid_trunk/pylucid/PyLucid/plugins_internal/back_links/back_links_cfg.py =================================================================== --- /home/jens/workspace/PyLucid_trunk/pylucid/PyLucid/plugins_internal/back_links/back_links_cfg.py (revision 1580) +++ /home/jens/workspace/PyLucid_trunk/pylucid/PyLucid/plugins_internal/back_links/back_links_cfg.py (working copy) @@ -11,6 +11,29 @@ """ #_____________________________________________________________________________ +# preferences + +from django import newforms as forms +from django.utils.translation import ugettext as _ + +class PreferencesForm(forms.Form): + print_last_page = forms.BooleanField( + initial = False, + help_text = _( + "if == True: then the actual page will be the last page in the bar." + " Otherwise the parentpage." + ), + ) + print_index = forms.BooleanField( + initial = False, + help_text = _('If == True: display a link to the index ("/")'), + ) + index = forms.CharField( + initial = _("Index"), + help_text = _('the name that is printed for the indexpage'), + ) + +#_____________________________________________________________________________ # plugin administration data plugin_manager_data = { Index: /home/jens/workspace/PyLucid_trunk/pylucid/PyLucid/plugins_internal/filemanager/filemanager.py =================================================================== --- /home/jens/workspace/PyLucid_trunk/pylucid/PyLucid/plugins_internal/filemanager/filemanager.py (revision 1580) +++ /home/jens/workspace/PyLucid_trunk/pylucid/PyLucid/plugins_internal/filemanager/filemanager.py (working copy) @@ -251,7 +251,7 @@ def __init__(self, context): self.context = context self.request = context["request"] - self.page_msg = context["page_msg"] + self.page_msg = request.page_msg def new_dir_path(self, path_info, must_exist=True): """ Index: /home/jens/workspace/PyLucid_trunk/pylucid/PyLucid/plugins_internal/main_menu/main_menu.py =================================================================== --- /home/jens/workspace/PyLucid_trunk/pylucid/PyLucid/plugins_internal/main_menu/main_menu.py (revision 1580) +++ /home/jens/workspace/PyLucid_trunk/pylucid/PyLucid/plugins_internal/main_menu/main_menu.py (working copy) @@ -41,6 +41,8 @@ """ write the current opened tree menu """ + self.page_msg("from main_menu") + current_page = self.context["PAGE"] self.current_page_id = current_page.id Index: /home/jens/workspace/PyLucid_trunk/pylucid/PyLucid/settings_example.py =================================================================== --- /home/jens/workspace/PyLucid_trunk/pylucid/PyLucid/settings_example.py (revision 1580) +++ /home/jens/workspace/PyLucid_trunk/pylucid/PyLucid/settings_example.py (working copy) @@ -86,6 +86,8 @@ # Insert a statistic line into the generated page: 'PyLucid.middlewares.pagestats.PageStatsMiddleware', + 'PyLucid.middlewares.pagemessages.PageMessagesMiddleware', + # PyLucidCommonMiddleware loads the django middlewares: # - 'django.contrib.sessions.middleware.SessionMiddleware' # - 'django.contrib.auth.middleware.AuthenticationMiddleware' Index: /home/jens/workspace/PyLucid_trunk/pylucid/PyLucid/system/BasePlugin.py =================================================================== --- /home/jens/workspace/PyLucid_trunk/pylucid/PyLucid/system/BasePlugin.py (revision 1580) +++ /home/jens/workspace/PyLucid_trunk/pylucid/PyLucid/system/BasePlugin.py (working copy) @@ -51,11 +51,11 @@ self.plugin_name = self.__class__.__name__ self.internal_page = InternalPage(context, self.plugin_name) + self.request = context["request"] + self.response = response self.context = context - self.response = response - self.request = context["request"] - self.page_msg = context["page_msg"] + self.page_msg = self.request.page_msg self.URLs = context["URLs"] self.current_page = self.context["PAGE"] @@ -60,6 +60,18 @@ self.current_page = self.context["PAGE"] + self.__preference_cache = None + + def get_preferences(self): + """ + returns the preferences from the database as a dict + """ + if self.__preference_cache == None: + self.__preference_cache = Plugin.objects.get_preferences( + self.plugin_name + ) + return self.__preference_cache + def build_menu(self): """ Build a simple menu for all plugin methods witch have a "menu_section" Index: /home/jens/workspace/PyLucid_trunk/pylucid/PyLucid/system/internal_page.py =================================================================== --- /home/jens/workspace/PyLucid_trunk/pylucid/PyLucid/system/internal_page.py (revision 1580) +++ /home/jens/workspace/PyLucid_trunk/pylucid/PyLucid/system/internal_page.py (working copy) @@ -36,8 +36,9 @@ "custom_internal_page_root" - filesystem path to customized internal pages """ def __init__(self, context, plugin_name): - self.page_msg = context["page_msg"] - self.URLs = context["URLs"] + self.request = context["request"] + self.page_msg = self.request.page_msg + self.URLs = context["URLs"] self.plugin_name = plugin_name Index: /home/jens/workspace/PyLucid_trunk/pylucid/PyLucid/system/markups/tinyTextile.py =================================================================== --- /home/jens/workspace/PyLucid_trunk/pylucid/PyLucid/system/markups/tinyTextile.py (revision 1580) +++ /home/jens/workspace/PyLucid_trunk/pylucid/PyLucid/system/markups/tinyTextile.py (working copy) @@ -24,9 +24,9 @@ Last commit info: ~~~~~~~~~~~~~~~~~ - $LastChangedDate$ - $Rev$ - $Author$ + $LastChangedDate:2008-05-13 18:26:55 +0200 (Di, 13 Mai 2008) $ + $Rev:1561 $ + $Author:JensDiemer $ :copyleft: 2007-2008 by Jens Diemer :license: GNU GPL v3, see LICENSE.txt for more details. @@ -33,7 +33,7 @@ """ -__version__ = "$Rev$" +__version__ = "$Rev:1561 $" import sys, re @@ -45,7 +45,7 @@ def __init__(self, out_obj, context): self.out = out_obj self.context = context - self.page_msg = context["page_msg"] + self.page_msg = context["request"].page_msg # Blockelements self.block_rules = self._compile_rules([ Index: /home/jens/workspace/PyLucid_trunk/pylucid/PyLucid/system/page_msg.py =================================================================== --- /home/jens/workspace/PyLucid_trunk/pylucid/PyLucid/system/page_msg.py (revision 1580) +++ /home/jens/workspace/PyLucid_trunk/pylucid/PyLucid/system/page_msg.py (working copy) @@ -45,14 +45,14 @@ http://www.djangoproject.com/documentation/authentication/#messages """ def __init__(self, context): + request = context["request"] + try: - self.messages = context["messages"] - except KeyError: - # No django messages inserted by RequestContext - # In the _install section we use no RequestContext ;) + self.messages = request.user.get_and_delete_messages() + except AttributeError: + # In the _install section we have no user self.messages = [] - request = context["request"] self.debug_mode = getattr(request, "debug", False) self._charset = settings.DEFAULT_CHARSET @@ -84,7 +84,7 @@ msg = '%s' % ( color, self.prepare(*msg) ) - + print "page_msg:", msg #~ self.request.user.message_set.create(message=msg) msg = mark_safe(msg) # turn djngo auto-escaping off self.messages.append(msg) @@ -156,6 +156,17 @@ return repr(txt) #________________________________________________________________ + + def __repr__(self): + return "page messages: %s" % repr(self.messages) + + def __str__(self): + return "pages messages: %s" % ", ".join(self.messages) + + def __unicode__(self): + return u"page messages: %s" % u", ".join(self.messages) + + #________________________________________________________________ # Some methods for the django template engine: def __iter__(self): Index: /home/jens/workspace/PyLucid_trunk/pylucid/PyLucid/system/plugin_manager.py =================================================================== --- /home/jens/workspace/PyLucid_trunk/pylucid/PyLucid/system/plugin_manager.py (revision 1580) +++ /home/jens/workspace/PyLucid_trunk/pylucid/PyLucid/system/plugin_manager.py (working copy) @@ -52,7 +52,7 @@ msg = "Error run plugin/plugin '%s.%s: %s" % ( plugin_name, method_name, msg ) - context["page_msg"](msg) + request.page_msg(msg) msg2 = '["%s.%s" error.]' % ( plugin_name, method_name ) @@ -58,7 +58,7 @@ ) local_response.write(msg2) -# context["page_msg"](plugin_name, method_name) +# request.page_msg(plugin_name, method_name) try: plugin = Plugin.objects.get(plugin_name=plugin_name) except Plugin.DoesNotExist, e: @@ -72,7 +72,7 @@ plugin_name = plugin.plugin_name, debug = request.debug, ) -# context["page_msg"](plugin_config.plugin_manager_data) +# request.page_msg(plugin_config.plugin_manager_data) try: method_cfg = plugin_config.plugin_manager_data[method_name] except KeyError: @@ -81,7 +81,7 @@ error("Can't get config for the method '%s'." % method_name) return -# context["page_msg"](method_cfg) +# request.page_msg(method_cfg) if method_cfg["must_login"]: # User must be login to use this method # http://www.djangoproject.com/documentation/authentication/ @@ -145,9 +145,9 @@ raise msg = "Run plugin %s.%s Error" % (plugin_name, method_name) - context["page_msg"].red("%s:" % msg) + request.page_msg.red("%s:" % msg) import sys, traceback - context["page_msg"]("
%s
" % traceback.format_exc()) + request.page_msg("
%s
" % traceback.format_exc()) return msg + "(Look in the page_msg)" Index: /home/jens/workspace/PyLucid_trunk/pylucid/PyLucid/system/URLs.py =================================================================== --- /home/jens/workspace/PyLucid_trunk/pylucid/PyLucid/system/URLs.py (revision 1580) +++ /home/jens/workspace/PyLucid_trunk/pylucid/PyLucid/system/URLs.py (working copy) @@ -10,7 +10,7 @@ The view put a instance in context["URLs"]. The BasePlugin bind the class to self. So every plugin can easy access the methods with self.URLs. - + more info: http://pylucid.org/_goto/62/self-URLs/ Last commit info: @@ -101,7 +101,7 @@ def __init__(self, context): self.context = context self.request = context["request"] - self.page_msg = context["page_msg"] + self.page_msg = self.request.page_msg self.current_plugin = None Index: /home/jens/workspace/PyLucid_trunk/pylucid/PyLucid/tools/content_processors.py =================================================================== --- /home/jens/workspace/PyLucid_trunk/pylucid/PyLucid/tools/content_processors.py (revision 1580) +++ /home/jens/workspace/PyLucid_trunk/pylucid/PyLucid/tools/content_processors.py (working copy) @@ -127,7 +127,8 @@ Makrups IDs defined in ./PyLucid/models.py """ - page_msg = context["page_msg"] + request = context["request"] + page_msg = request.page_msg if markup_no == 2: # textile content = apply_tinytextile(content, context) Index: /home/jens/workspace/PyLucid_trunk/pylucid/PyLucid/urls.py =================================================================== --- /home/jens/workspace/PyLucid_trunk/pylucid/PyLucid/urls.py (revision 1580) +++ /home/jens/workspace/PyLucid_trunk/pylucid/PyLucid/urls.py (working copy) @@ -116,6 +116,7 @@ # A normal CMS page url simply consists of the page shortcuts. # The shortcuts contains only these chars: [a-zA-Z0-9_/-] urls += (r'([\w/-]*)', 'PyLucid.index.index'), +urls += (r'^$', 'PyLucid.index.index'), urlpatterns = patterns('', *urls)