Changeset 2548
- Timestamp:
- 02/26/10 14:03:36 (5 months ago)
- Location:
- branches/0.9/pylucid_project
- Files:
-
- 2 modified
-
apps/pylucid/system/pylucid_objects.py (modified) (2 diffs)
-
settings.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
branches/0.9/pylucid_project/apps/pylucid/system/pylucid_objects.py
r2330 r2548 15 15 $Author: $ 16 16 17 :copyleft: 2009 by the PyLucid team, see AUTHORS for more details.17 :copyleft: 2009-2010 by the PyLucid team, see AUTHORS for more details. 18 18 :license: GNU GPL v3 or above, see LICENSE for more details. 19 19 """ 20 20 21 21 from django.conf import settings 22 from django.utils.safestring import mark_safe 22 23 23 from pylucid.shortcuts import failsafe_message 24 from pylucid.system import extrahead 24 from pylucid_project.utils.escape import escape 25 from pylucid_project.apps.pylucid.shortcuts import failsafe_message 26 from pylucid_project.apps.pylucid.system import extrahead 25 27 28 29 # max value length in debug __setattr__ 30 MAX_VALUE_LENGTH = 150 26 31 27 32 28 33 class PyLucidRequestObjects(object): 29 34 """ PyLucid request objects """ 35 _check_setattr = False 30 36 def __init__(self, request): 31 from pylucid.models import Language # FIXME: import here, against import loop. 37 self.request = request 38 39 # FIXME: import here, against import loop: 40 from pylucid_project.apps.pylucid.models import Language 32 41 33 42 # Client prefered language instance, use default, if not exist … … 50 59 #self.page_template - The global page template as a string 51 60 #self.context - The global context 61 62 self._check_setattr = settings.DEBUG 63 64 def _setattr_debug(self, name, value): 65 """ 66 debug __setattr__ to see if new attributes would be defined or existing changed. 67 68 HowTo: http://www.pylucid.org/permalink/133/pylucid-objects#DEBUG 69 """ 70 if self._check_setattr: 71 if hasattr(self, name): 72 action = "changed" 73 else: 74 action = "set" 75 76 value_preview = repr(value) 77 if len(value_preview) > MAX_VALUE_LENGTH - 3: 78 value_preview = value_preview[:MAX_VALUE_LENGTH] + "..." 79 value_preview = escape(value_preview) 80 msg = "request.PYLUCID.<strong>%s</strong> %s to: <i>%s</i> (type: %s)" % ( 81 name, action, value_preview, escape(repr(type(value))) 82 ) 83 self.request.page_msg(mark_safe(msg)) 84 85 super(PyLucidRequestObjects, self).__setattr__(name, value) 86 87 88 if settings.PYLUCID_OBJECTS_DEBUG: 89 assert settings.DEBUG == True, "PyLucidRequestObjects works only if settings.DEBUG is on!" 90 PyLucidRequestObjects.__setattr__ = PyLucidRequestObjects._setattr_debug 91 -
branches/0.9/pylucid_project/settings.py
r2529 r2548 62 62 # Should allways be False. It's only for developing! 63 63 SQL_DEBUG = False 64 65 # See if request.PYLUCID attributes attached or changes (Works only if DEBUG==True) 66 # See also: http://www.pylucid.org/permalink/133/pylucid-objects#DEBUG 67 # Should allways be False. It's only for developing! 68 PYLUCID_OBJECTS_DEBUG = False 64 69 65 70 #______________________________________________________________________________