Skip to content
This repository has been archived by the owner on Feb 12, 2020. It is now read-only.

Commit

Permalink
Initial import.
Browse files Browse the repository at this point in the history
  • Loading branch information
malthe committed Nov 24, 2008
0 parents commit 9c66fac
Show file tree
Hide file tree
Showing 7 changed files with 142 additions and 0 deletions.
1 change: 1 addition & 0 deletions AUTHOR.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Malthe Borch <mborch@gmail.com>
17 changes: 17 additions & 0 deletions README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Overview
========

The cmf.pt package allows using the Chameleon template engine with the
Zope 2 CMF.

Usage
-----

To enable Chameleon, simply include the ZCML configuration::

<include package="five.pt" />
<include package="cmf.pt" />

For general information about Chameleon, see
http://chameleon.repoze.org/.

31 changes: 31 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from setuptools import setup, find_packages

version = '0.1'

setup(name='cmf.pt',
version=version,
description="Bridge to use Chameleon with Zope 2 and CMF.",
long_description=open("README.txt").read() + open("CHANGES.txt").read(),
classifiers=[
"Framework :: Zope2",
"Programming Language :: Python",
"Topic :: Text Processing :: Markup :: HTML",
"Topic :: Text Processing :: Markup :: XML",
"Topic :: Software Development :: Libraries :: Python Modules",
],
keywords='',
author='Malthe Borch and the Zope community',
author_email='zope-dev@zope.org',
url='',
license='ZPL',
namespace_packages=['cmf'],
packages = find_packages('src'),
package_dir = {'':'src'},
include_package_data=True,
zip_safe=False,
install_requires=[
'setuptools',
'z3c.pt',
'five.pt',
],
)
6 changes: 6 additions & 0 deletions src/cmf/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# See http://peak.telecommunity.com/DevCenter/setuptools#namespace-packages
try:
__import__('pkg_resources').declare_namespace(__name__)
except ImportError:
from pkgutil import extend_path
__path__ = extend_path(__path__, __name__)
1 change: 1 addition & 0 deletions src/cmf/pt/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#
80 changes: 80 additions & 0 deletions src/cmf/pt/cmf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import Globals

from Products.CMFCore.FSObject import FSObject
from Products.CMFCore import DirectoryView
from Products.CMFCore import permissions

from Products.CMFFormController.BaseControllerPageTemplate import \
BaseControllerPageTemplate as BaseCPT
from Products.CMFFormController.FSControllerBase import FSControllerBase

from Shared.DC.Scripts.Script import Script
from AccessControl import ClassSecurityInfo
from RestrictedPython import Utilities

from five.pt.pagetemplate import BaseTemplateFile

class FSPageTemplate(BaseTemplateFile, FSObject, Script):
meta_type = 'Filesystem Page Template'

security = ClassSecurityInfo()
security.declareObjectProtected(permissions.View)

_default_bindings = {'name_subpath': 'traverse_subpath'}

utility_builtins = Utilities.utility_builtins

def __init__(self, id, filepath, fullname=None, properties=None):
FSObject.__init__(self, id, filepath, fullname, properties)
self.ZBindings_edit(self._default_bindings)

# instantiate page template
BaseTemplateFile.__init__(self, filepath)

def _readFile(self, reparse):
# templates are lazy
if reparse:
self.read()

def __call__(self, *args, **kwargs):
kwargs['args'] = args
return BaseTemplateFile.__call__(self, self, **kwargs)

@property
def func_code(self):
return self.render.func_code

class FSControllerPageTemplate(FSPageTemplate, FSControllerBase, BaseCPT):
def __init__(self, id, filepath, fullname=None, properties=None):
FSPageTemplate.__init__(self, id, filepath, fullname, properties)
self.filepath = filepath

self._read_action_metadata(self.getId(), filepath)
self._read_validator_metadata(self.getId(), filepath)

def _readFile(self, reparse):
FSPageTemplate._readFile(self, reparse)
self._readMetadata()

def _updateFromFS(self):
# workaround for Python 2.1 multiple inheritance lameness
return self._baseUpdateFromFS()

def _readMetadata(self):
# workaround for Python 2.1 multiple inheritance lameness
return self._baseReadMetadata()

def __call__(self, *args, **kwargs):
return self._call(FSPageTemplate.__call__, *args, **kwargs)

Globals.InitializeClass(FSPageTemplate)
Globals.InitializeClass(FSControllerPageTemplate)

DirectoryView.registerFileExtension('pt', FSPageTemplate)
DirectoryView.registerFileExtension('zpt', FSPageTemplate)
DirectoryView.registerFileExtension('html', FSPageTemplate)
DirectoryView.registerFileExtension('htm', FSPageTemplate)
DirectoryView.registerFileExtension('cpt', FSControllerPageTemplate)

DirectoryView.registerMetaType('Page Template', FSPageTemplate)
DirectoryView.registerMetaType('Controller Page Template', FSControllerPageTemplate)
6 changes: 6 additions & 0 deletions src/cmf/pt/configure.zcml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<configure xmlns="http://namespaces.zope.org/zope">

<include package="five.pt" />
<include package=".cmf" />

</configure>

0 comments on commit 9c66fac

Please sign in to comment.