Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
Zope
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
Zope
Commits
f3c137f0
Commit
f3c137f0
authored
May 21, 2006
by
Philipp von Weitershausen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
More API BBB: Make method signatures of pt_render and pt_errors compatible with
old Zope 2 code.
parent
5e0f612a
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
39 additions
and
26 deletions
+39
-26
lib/python/Products/PageTemplates/PageTemplate.py
lib/python/Products/PageTemplates/PageTemplate.py
+31
-7
lib/python/Products/PageTemplates/PageTemplateFile.py
lib/python/Products/PageTemplates/PageTemplateFile.py
+2
-2
lib/python/Products/PageTemplates/ZopePageTemplate.py
lib/python/Products/PageTemplates/ZopePageTemplate.py
+2
-14
lib/python/Products/PageTemplates/tests/testZopePageTemplate.py
...thon/Products/PageTemplates/tests/testZopePageTemplate.py
+4
-3
No files found.
lib/python/Products/PageTemplates/PageTemplate.py
View file @
f3c137f0
...
...
@@ -14,11 +14,11 @@
$Id$
"""
import
sys
import
ExtensionClass
import
zope.pagetemplate.pagetemplate
from
zope.tales.expressions
import
SimpleModuleImporter
from
Products.PageTemplates.Expressions
import
getEngine
from
Products.PageTemplates.Expressions
import
SecureModuleImporter
##############################################################################
# BBB 2005/05/01 -- to be removed after 12 months
...
...
@@ -47,12 +47,13 @@ class PageTemplate(ExtensionClass.Base,
def
pt_getEngine
(
self
):
return
getEngine
()
def
pt_getContext
(
self
,
args
=
(),
options
=
{}):
c
=
super
(
PageTemplate
,
self
).
pt_getContext
(
args
,
options
)
c
.
update
({
'request'
:
None
,
'modules'
:
SimpleModuleImporter
(),
})
def
pt_getContext
(
self
):
c
=
{
'template'
:
self
,
'options'
:
{},
'nothing'
:
None
,
'request'
:
None
,
'modules'
:
SimpleModuleImporter
(),
}
parent
=
getattr
(
self
,
'aq_parent'
,
None
)
if
parent
is
not
None
:
c
[
'here'
]
=
parent
...
...
@@ -63,3 +64,26 @@ class PageTemplate(ExtensionClass.Base,
parent
=
getattr
(
self
,
'aq_parent'
,
None
)
c
[
'root'
]
=
self
return
c
# these methods are reimplemented or duplicated here because of
# different call signatures in the Zope 2 world
def
pt_render
(
self
,
source
=
False
,
extra_context
=
{}):
c
=
self
.
pt_getContext
()
c
.
update
(
extra_context
)
return
super
(
PageTemplate
,
self
).
pt_render
(
c
,
source
=
source
)
def
pt_errors
(
self
,
namespace
=
{}):
self
.
_cook_check
()
err
=
self
.
_v_errors
if
err
:
return
err
try
:
self
.
pt_render
(
source
=
True
,
extra_context
=
namespace
)
except
:
return
(
'Macro expansion failed'
,
'%s: %s'
%
sys
.
exc_info
()[:
2
])
def
__call__
(
self
,
*
args
,
**
kwargs
):
if
not
kwargs
.
has_key
(
'args'
):
kwargs
[
'args'
]
=
args
return
self
.
pt_render
(
extra_context
=
{
'options'
:
kwargs
})
lib/python/Products/PageTemplates/PageTemplateFile.py
View file @
f3c137f0
...
...
@@ -25,10 +25,10 @@ from Shared.DC.Scripts.Script import Script
from
Shared.DC.Scripts.Signature
import
FuncCode
from
Products.PageTemplates.Expressions
import
getEngine
from
Products.PageTemplates.Expressions
import
SecureModuleImporter
from
Products.PageTemplates.PageTemplate
import
PageTemplate
from
Products.PageTemplates.ZopePageTemplate
import
guess_type
from
zope.contenttype
import
guess_content_type
from
zope.pagetemplate.pagetemplate
import
PageTemplate
LOG
=
getLogger
(
'PageTemplateFile'
)
...
...
@@ -121,7 +121,7 @@ class PageTemplateFile(SimpleItem, Script, PageTemplate, Traversable):
try
:
context
=
self
.
pt_getContext
()
context
.
update
(
bound_names
)
return
self
.
pt_render
(
context
)
return
self
.
pt_render
(
extra_context
=
bound_names
)
finally
:
security
.
removeContext
(
self
)
...
...
lib/python/Products/PageTemplates/ZopePageTemplate.py
View file @
f3c137f0
...
...
@@ -35,9 +35,9 @@ from AccessControl.Permissions import view_management_screens
from
webdav.Lockable
import
ResourceLockedError
from
webdav.WriteLockInterface
import
WriteLockInterface
from
zope.contenttype
import
guess_content_type
from
zope.pagetemplate.pagetemplate
import
PageTemplate
from
zope.pagetemplate.pagetemplatefile
import
sniff_type
from
Products.PageTemplates.PageTemplate
import
PageTemplate
from
Products.PageTemplates.Expressions
import
getEngine
from
Products.PageTemplates.Expressions
import
SecureModuleImporter
...
...
@@ -123,14 +123,6 @@ class ZopePageTemplate(Script, PageTemplate, Historical, Cacheable,
self.ZBindings_edit(self._default_bindings)
self.pt_edit(text, content_type, encoding)
def pt_render(self, namespace, source=False, sourceAnnotations=False,
showtal=False):
if namespace is None:
namespace = self.pt_getContext()
return super(ZopePageTemplate, self).pt_render(namespace, source, sourceAnnotations,
showtal)
def pt_getEngine(self):
return getEngine()
...
...
@@ -288,11 +280,7 @@ class ZopePageTemplate(Script, PageTemplate, Historical, Cacheable,
security.addContext(self)
try:
# XXX: check the parameters for pt_render()! (aj)
result = self.pt_render(self.pt_getContext())
# result = self.pt_render(extra_context=bound_names)
result = self.pt_render(extra_context=bound_names)
if keyset is not None:
# Store the result in the cache.
self.ZCacheable_set(result, keywords=keyset)
...
...
lib/python/Products/PageTemplates/tests/testZopePageTemplate.py
View file @
f3c137f0
...
...
@@ -59,6 +59,7 @@ class ZPTRegressions(unittest.TestCase):
self
.
assertEqual
(
pt
.
document_src
(),
self
.
text
)
class
ZPTMacros
(
unittest
.
TestCase
):
def
setUp
(
self
):
transaction
.
begin
()
self
.
app
=
makerequest
(
Zope2
.
app
())
...
...
@@ -98,9 +99,9 @@ class ZPTMacros(unittest.TestCase):
request
=
self
.
app
.
REQUEST
self
.
_addPT
(
'pt1'
,
text
=
self
.
text
,
REQUEST
=
request
)
pt
=
self
.
app
.
pt1
pt
.
pt_render
(
None
,
source
=
1
)
self
.
assertEqual
(
pt
.
pt_errors
(
None
),
None
)
pt
.
pt_render
(
source
=
True
)
self
.
assertEqual
(
pt
.
pt_errors
(),
None
)
class
DummyFileUpload
:
def
__init__
(
self
,
data
=
''
,
filename
=
''
,
content_type
=
''
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment