[Checkins] SVN: z3c.jbot/trunk/ Added support for CMF objects (Zope 2 CMF directory views).
Malthe Borch
mborch at gmail.com
Thu Oct 15 13:54:18 EDT 2009
Log message for revision 105092:
Added support for CMF objects (Zope 2 CMF directory views).
Changed:
U z3c.jbot/trunk/CHANGES.txt
U z3c.jbot/trunk/README.txt
U z3c.jbot/trunk/z3c/jbot/__init__.py
U z3c.jbot/trunk/z3c/jbot/manager.py
-=-
Modified: z3c.jbot/trunk/CHANGES.txt
===================================================================
--- z3c.jbot/trunk/CHANGES.txt 2009-10-15 16:36:56 UTC (rev 105091)
+++ z3c.jbot/trunk/CHANGES.txt 2009-10-15 17:54:18 UTC (rev 105092)
@@ -1,6 +1,10 @@
Changes
=======
+In next release...
+
+- Added support for CMF skin objects.
+
0.4 (2009-10-15)
----------------
Modified: z3c.jbot/trunk/README.txt
===================================================================
--- z3c.jbot/trunk/README.txt 2009-10-15 16:36:56 UTC (rev 105091)
+++ z3c.jbot/trunk/README.txt 2009-10-15 17:54:18 UTC (rev 105092)
@@ -1,18 +1,23 @@
Overview
========
-The ``z3c.jbot`` (or "Just a bunch of templates") package allows
-drop-in page template overrides. It works on Zope 2 and Zope 3. The
-Chameleon rendering engine is supported [#]_.
+The ``z3c.jbot`` (or "Just a bunch of templates") package allows easy
+customization of existing templates and images. It works on Zope 2 and
+Zope 3.
-Any template that is defined as a class-attribute can be overriden
-using jbot, e.g. those used in views, viewlets and portlets. The
-template overrides may be registered for any request layer or only a
-specific layer.
+The Chameleon rendering engine is supported [#]_.
-To override a particular template, first determine its *canonical
+Use of this package adds a small (2-3 ms per request on Plone) to the
+total application response time.
+
+.. [#] To enable Chameleon on Zope 2, use the ``five.pt`` package (CMF-apps like Plone should use ``cmf.pt`` which adds full support).
+
+Usage
+-----
+
+To override a particular file, first determine its *canonical
filename*. It's defined as the path relative to the package within
-which the template is located; directory separators are replaced with
+which the file is located; directory separators are replaced with
dots.
Example:
@@ -30,11 +35,20 @@
directory="<path>"
layer="<layer>" />
-Use of this package adds a small (2-3 ms per request on Plone) to the
-total application response time.
+Templates in views, viewlets and portlets
+-----------------------------------------
-.. [#] To enable Chameleon on Zope 2, use the ``five.pt`` package (CMF-apps like Plone should use ``cmf.pt`` which adds full support).
+Any template that is defined as a class-attribute can be overriden
+using jbot, e.g. those used in views, viewlets and portlets. The
+template overrides may be registered for any request layer or only a
+specific layer.
+CMF objects
+-----------
+
+Any skin-object (e.g. images, templates) on the file system (directory
+views) can be overridden.
+
Author
------
Modified: z3c.jbot/trunk/z3c/jbot/__init__.py
===================================================================
--- z3c.jbot/trunk/z3c/jbot/__init__.py 2009-10-15 16:36:56 UTC (rev 105091)
+++ z3c.jbot/trunk/z3c/jbot/__init__.py 2009-10-15 17:54:18 UTC (rev 105092)
@@ -28,6 +28,7 @@
# register template; this call returns ``True`` if the
# template was invalidated (changed filename)
if manager.registerTemplate(inst, template):
+ inst._v_last_read = False
break
return inst
@@ -53,3 +54,39 @@
for pt_class in PT_CLASSES:
pt_class.__get__ = get
logger.info(repr(pt_class))
+
+try:
+ import Products.CMFCore.FSObject
+except ImportError:
+ pass
+else:
+ fs_class = Products.CMFCore.FSObject.FSObject
+
+ def get_skin_obj(obj, view=None, cls=None):
+ layer = utility.getLayer()
+ key = layer, obj
+ inst = registry.get(key)
+ if inst is None:
+ cls = type(obj)
+ inst = registry[key] = cls.__new__(cls)
+ inst.__dict__ = obj.__dict__.copy()
+
+ for manager in utility.getManagers():
+ # register template; this call returns ``True`` if the
+ # template was invalidated (changed filename)
+ if manager.registerTemplate(inst, obj):
+ inst._parsed = False
+ inst.getObjectFSPath()
+
+ return inst
+
+ def get_filename(obj, *args):
+ return obj._filepath
+
+ def set_filename(obj, value, *args):
+ obj._filepath = value
+
+ fs_class.__get__ = get_skin_obj
+ fs_class.filename = property(get_filename, set_filename)
+
+ logger.info(repr(fs_class))
Modified: z3c.jbot/trunk/z3c/jbot/manager.py
===================================================================
--- z3c.jbot/trunk/z3c/jbot/manager.py 2009-10-15 16:36:56 UTC (rev 105091)
+++ z3c.jbot/trunk/z3c/jbot/manager.py 2009-10-15 17:54:18 UTC (rev 105092)
@@ -76,8 +76,7 @@
self.directories.add(directory)
for filename in os.listdir(directory):
- if filename.endswith('.pt'):
- self.paths[filename] = "%s/%s" % (directory, filename)
+ self.paths[filename] = "%s/%s" % (directory, filename)
for template, filename in self.templates.items():
if filename is IGNORE:
@@ -101,7 +100,6 @@
self.registerTemplate(inst, template)
del self.templates[template]
inst.filename = inst._filename
- inst._v_last_read = False
def unregisterAllDirectories(self):
for directory in tuple(self.directories):
@@ -131,20 +129,17 @@
return
filename = path.replace(os.path.sep, '.')
- if filename in paths:
- path = paths[filename]
+ if filename not in paths:
+ self.templates[token] = IGNORE
+ return
- # save original filename
- template._filename = template.filename
+ path = paths[filename]
- # save template and registry and assign path
- template.filename = path
- self.templates[token] = filename
- else:
- self.templates[token] = IGNORE
- return False
+ # save original filename
+ template._filename = template.filename
- # force cook
- template._v_last_read = False
+ # save template and registry and assign path
+ template.filename = path
+ self.templates[token] = filename
return True
More information about the checkins
mailing list