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
830566b4
Commit
830566b4
authored
Jun 16, 2010
by
Godefroid Chapelle
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
whitespace
parent
830c17db
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
23 deletions
+22
-23
src/Products/PageTemplates/ZopePageTemplate.py
src/Products/PageTemplates/ZopePageTemplate.py
+22
-23
No files found.
src/Products/PageTemplates/ZopePageTemplate.py
View file @
830566b4
...
@@ -36,7 +36,7 @@ from OFS.History import Historical, html_diff
...
@@ -36,7 +36,7 @@ from OFS.History import Historical, html_diff
from
OFS.Cache
import
Cacheable
from
OFS.Cache
import
Cacheable
from
OFS.Traversable
import
Traversable
from
OFS.Traversable
import
Traversable
from
OFS.PropertyManager
import
PropertyManager
from
OFS.PropertyManager
import
PropertyManager
from
Shared.DC.Scripts.Script
import
Script
from
Shared.DC.Scripts.Script
import
Script
from
Shared.DC.Scripts.Signature
import
FuncCode
from
Shared.DC.Scripts.Signature
import
FuncCode
from
webdav.Lockable
import
ResourceLockedError
from
webdav.Lockable
import
ResourceLockedError
...
@@ -52,7 +52,7 @@ from Products.PageTemplates.utils import convertToUnicode
...
@@ -52,7 +52,7 @@ from Products.PageTemplates.utils import convertToUnicode
preferred_encodings
=
[
'utf-8'
,
'iso-8859-15'
]
preferred_encodings
=
[
'utf-8'
,
'iso-8859-15'
]
if
os
.
environ
.
has_key
(
'ZPT_PREFERRED_ENCODING'
):
if
os
.
environ
.
has_key
(
'ZPT_PREFERRED_ENCODING'
):
preferred_encodings
.
insert
(
0
,
os
.
environ
[
'ZPT_PREFERRED_ENCODING'
])
preferred_encodings
.
insert
(
0
,
os
.
environ
[
'ZPT_PREFERRED_ENCODING'
])
class
Src
(
Explicit
):
class
Src
(
Explicit
):
...
@@ -107,10 +107,10 @@ class ZopePageTemplate(Script, PageTemplate, Historical, Cacheable,
...
@@ -107,10 +107,10 @@ class ZopePageTemplate(Script, PageTemplate, Historical, Cacheable,
security
.
declareProtected
(
view_management_screens
,
security
.
declareProtected
(
view_management_screens
,
'read'
,
'ZScriptHTML_tryForm'
)
'read'
,
'ZScriptHTML_tryForm'
)
def
__init__
(
self
,
id
,
text
=
None
,
content_type
=
'text/html'
,
strict
=
True
,
def
__init__
(
self
,
id
,
text
=
None
,
content_type
=
'text/html'
,
strict
=
True
,
output_encoding
=
'utf-8'
):
output_encoding
=
'utf-8'
):
self
.
id
=
id
self
.
id
=
id
self
.
expand
=
0
self
.
expand
=
0
self
.
ZBindings_edit
(
self
.
_default_bindings
)
self
.
ZBindings_edit
(
self
.
_default_bindings
)
self
.
output_encoding
=
output_encoding
self
.
output_encoding
=
output_encoding
# default content
# default content
...
@@ -124,7 +124,7 @@ class ZopePageTemplate(Script, PageTemplate, Historical, Cacheable,
...
@@ -124,7 +124,7 @@ class ZopePageTemplate(Script, PageTemplate, Historical, Cacheable,
def
pt_edit
(
self
,
text
,
content_type
,
keep_output_encoding
=
False
):
def
pt_edit
(
self
,
text
,
content_type
,
keep_output_encoding
=
False
):
text
=
text
.
strip
()
text
=
text
.
strip
()
is_unicode
=
isinstance
(
text
,
unicode
)
is_unicode
=
isinstance
(
text
,
unicode
)
encoding
=
None
encoding
=
None
output_encoding
=
None
output_encoding
=
None
...
@@ -163,7 +163,7 @@ class ZopePageTemplate(Script, PageTemplate, Historical, Cacheable,
...
@@ -163,7 +163,7 @@ class ZopePageTemplate(Script, PageTemplate, Historical, Cacheable,
preferred_encodings
)
preferred_encodings
)
output_encoding
=
encoding
output_encoding
=
encoding
# for content updated through WebDAV, FTP
# for content updated through WebDAV, FTP
if
not
keep_output_encoding
:
if
not
keep_output_encoding
:
self
.
output_encoding
=
output_encoding
self
.
output_encoding
=
output_encoding
...
@@ -192,7 +192,7 @@ class ZopePageTemplate(Script, PageTemplate, Historical, Cacheable,
...
@@ -192,7 +192,7 @@ class ZopePageTemplate(Script, PageTemplate, Historical, Cacheable,
# The ZMI edit view uses utf-8! So we can safely assume
# The ZMI edit view uses utf-8! So we can safely assume
# that 'title' and 'text' are utf-8 encoded strings - hopefully
# that 'title' and 'text' are utf-8 encoded strings - hopefully
self
.
pt_setTitle
(
title
,
'utf-8'
)
self
.
pt_setTitle
(
title
,
'utf-8'
)
text
=
unicode
(
text
,
'utf-8'
)
text
=
unicode
(
text
,
'utf-8'
)
self
.
pt_edit
(
text
,
content_type
,
True
)
self
.
pt_edit
(
text
,
content_type
,
True
)
...
@@ -227,12 +227,12 @@ class ZopePageTemplate(Script, PageTemplate, Historical, Cacheable,
...
@@ -227,12 +227,12 @@ class ZopePageTemplate(Script, PageTemplate, Historical, Cacheable,
filename
=
None
filename
=
None
text
=
file
text
=
file
else
:
else
:
if
not
file
:
if
not
file
:
raise
ValueError
(
'File not specified'
)
raise
ValueError
(
'File not specified'
)
filename
=
file
.
filename
filename
=
file
.
filename
text
=
file
.
read
()
text
=
file
.
read
()
content_type
=
guess_type
(
filename
,
text
)
content_type
=
guess_type
(
filename
,
text
)
# if not content_type in ('text/html', 'text/xml'):
# if not content_type in ('text/html', 'text/xml'):
# raise ValueError('Unsupported mimetype: %s' % content_type)
# raise ValueError('Unsupported mimetype: %s' % content_type)
...
@@ -252,9 +252,9 @@ class ZopePageTemplate(Script, PageTemplate, Historical, Cacheable,
...
@@ -252,9 +252,9 @@ class ZopePageTemplate(Script, PageTemplate, Historical, Cacheable,
rows
=
str
(
max
(
1
,
int
(
dtpref_rows
)
+
dr
))
rows
=
str
(
max
(
1
,
int
(
dtpref_rows
)
+
dr
))
cols
=
str
(
dtpref_cols
)
cols
=
str
(
dtpref_cols
)
if
cols
.
endswith
(
'%'
):
if
cols
.
endswith
(
'%'
):
cols
=
str
(
min
(
100
,
max
(
25
,
int
(
cols
[:
-
1
])
+
dc
)))
+
'%'
cols
=
str
(
min
(
100
,
max
(
25
,
int
(
cols
[:
-
1
])
+
dc
)))
+
'%'
else
:
else
:
cols
=
str
(
max
(
35
,
int
(
cols
)
+
dc
))
cols
=
str
(
max
(
35
,
int
(
cols
)
+
dc
))
e
=
(
DateTime
(
"GMT"
)
+
365
).
rfc822
()
e
=
(
DateTime
(
"GMT"
)
+
365
).
rfc822
()
setCookie
=
REQUEST
[
"RESPONSE"
].
setCookie
setCookie
=
REQUEST
[
"RESPONSE"
].
setCookie
setCookie
(
"dtpref_rows"
,
rows
,
path
=
'/'
,
expires
=
e
)
setCookie
(
"dtpref_rows"
,
rows
,
path
=
'/'
,
expires
=
e
)
...
@@ -294,7 +294,7 @@ class ZopePageTemplate(Script, PageTemplate, Historical, Cacheable,
...
@@ -294,7 +294,7 @@ class ZopePageTemplate(Script, PageTemplate, Historical, Cacheable,
def
write
(
self
,
text
):
def
write
(
self
,
text
):
if
not
isinstance
(
text
,
unicode
):
if
not
isinstance
(
text
,
unicode
):
text
,
encoding
=
convertToUnicode
(
text
,
text
,
encoding
=
convertToUnicode
(
text
,
self
.
content_type
,
self
.
content_type
,
preferred_encodings
)
preferred_encodings
)
self
.
output_encoding
=
encoding
self
.
output_encoding
=
encoding
...
@@ -351,7 +351,7 @@ class ZopePageTemplate(Script, PageTemplate, Historical, Cacheable,
...
@@ -351,7 +351,7 @@ class ZopePageTemplate(Script, PageTemplate, Historical, Cacheable,
self
.
dav__init
(
REQUEST
,
RESPONSE
)
self
.
dav__init
(
REQUEST
,
RESPONSE
)
self
.
dav__simpleifhandler
(
REQUEST
,
RESPONSE
,
refresh
=
1
)
self
.
dav__simpleifhandler
(
REQUEST
,
RESPONSE
,
refresh
=
1
)
text
=
REQUEST
.
get
(
'BODY'
,
''
)
text
=
REQUEST
.
get
(
'BODY'
,
''
)
content_type
=
guess_type
(
''
,
text
)
content_type
=
guess_type
(
''
,
text
)
self
.
pt_edit
(
text
,
content_type
)
self
.
pt_edit
(
text
,
content_type
)
RESPONSE
.
setStatus
(
204
)
RESPONSE
.
setStatus
(
204
)
return
RESPONSE
return
RESPONSE
...
@@ -369,7 +369,7 @@ class ZopePageTemplate(Script, PageTemplate, Historical, Cacheable,
...
@@ -369,7 +369,7 @@ class ZopePageTemplate(Script, PageTemplate, Historical, Cacheable,
security
.
declareProtected
(
view_management_screens
,
'html'
)
security
.
declareProtected
(
view_management_screens
,
'html'
)
def
html
(
self
):
def
html
(
self
):
return
self
.
content_type
==
'text/html'
return
self
.
content_type
==
'text/html'
security
.
declareProtected
(
view_management_screens
,
'get_size'
)
security
.
declareProtected
(
view_management_screens
,
'get_size'
)
def
get_size
(
self
):
def
get_size
(
self
):
return
len
(
self
.
read
())
return
len
(
self
.
read
())
...
@@ -416,16 +416,16 @@ class ZopePageTemplate(Script, PageTemplate, Historical, Cacheable,
...
@@ -416,16 +416,16 @@ class ZopePageTemplate(Script, PageTemplate, Historical, Cacheable,
def
__setstate__
(
self
,
state
):
def
__setstate__
(
self
,
state
):
# Perform on-the-fly migration to unicode.
# Perform on-the-fly migration to unicode.
# Perhaps it might be better to work with the 'generation' module
# Perhaps it might be better to work with the 'generation' module
# here?
# here?
_text
=
state
.
get
(
'_text'
)
_text
=
state
.
get
(
'_text'
)
if
_text
is
not
None
and
not
isinstance
(
state
[
'_text'
],
unicode
):
if
_text
is
not
None
and
not
isinstance
(
state
[
'_text'
],
unicode
):
text
,
encoding
=
convertToUnicode
(
state
[
'_text'
],
text
,
encoding
=
convertToUnicode
(
state
[
'_text'
],
state
.
get
(
'content_type'
,
'text/html'
),
state
.
get
(
'content_type'
,
'text/html'
),
preferred_encodings
)
preferred_encodings
)
state
[
'_text'
]
=
text
state
[
'_text'
]
=
text
state
[
'output_encoding'
]
=
encoding
state
[
'output_encoding'
]
=
encoding
self
.
__dict__
.
update
(
state
)
self
.
__dict__
.
update
(
state
)
def
pt_render
(
self
,
source
=
False
,
extra_context
=
{}):
def
pt_render
(
self
,
source
=
False
,
extra_context
=
{}):
...
@@ -462,7 +462,7 @@ def manage_addPageTemplate(self, id, title='', text='', encoding='utf-8',
...
@@ -462,7 +462,7 @@ def manage_addPageTemplate(self, id, title='', text='', encoding='utf-8',
if
headers
and
headers
.
has_key
(
'content_type'
):
if
headers
and
headers
.
has_key
(
'content_type'
):
content_type
=
headers
[
'content_type'
]
content_type
=
headers
[
'content_type'
]
else
:
else
:
content_type
=
guess_type
(
filename
,
text
)
content_type
=
guess_type
(
filename
,
text
)
else
:
else
:
...
@@ -473,7 +473,7 @@ def manage_addPageTemplate(self, id, title='', text='', encoding='utf-8',
...
@@ -473,7 +473,7 @@ def manage_addPageTemplate(self, id, title='', text='', encoding='utf-8',
if
headers
and
headers
.
has_key
(
'content_type'
):
if
headers
and
headers
.
has_key
(
'content_type'
):
content_type
=
headers
[
'content_type'
]
content_type
=
headers
[
'content_type'
]
else
:
else
:
content_type
=
guess_type
(
filename
,
text
)
content_type
=
guess_type
(
filename
,
text
)
# ensure that we pass unicode to the constructor to
# ensure that we pass unicode to the constructor to
# avoid further hassles with pt_edit()
# avoid further hassles with pt_edit()
...
@@ -486,12 +486,12 @@ def manage_addPageTemplate(self, id, title='', text='', encoding='utf-8',
...
@@ -486,12 +486,12 @@ def manage_addPageTemplate(self, id, title='', text='', encoding='utf-8',
self
.
_setObject
(
id
,
zpt
)
self
.
_setObject
(
id
,
zpt
)
zpt
=
getattr
(
self
,
id
)
zpt
=
getattr
(
self
,
id
)
if
RESPONSE
:
if
RESPONSE
:
if
submit
==
" Add and Edit "
:
if
submit
==
" Add and Edit "
:
RESPONSE
.
redirect
(
zpt
.
absolute_url
()
+
'/pt_editForm'
)
RESPONSE
.
redirect
(
zpt
.
absolute_url
()
+
'/pt_editForm'
)
else
:
else
:
RESPONSE
.
redirect
(
self
.
absolute_url
()
+
'/manage_main'
)
RESPONSE
.
redirect
(
self
.
absolute_url
()
+
'/manage_main'
)
else
:
else
:
return
zpt
return
zpt
from
Products.PageTemplates
import
misc_
from
Products.PageTemplates
import
misc_
...
@@ -507,4 +507,3 @@ def initialize(context):
...
@@ -507,4 +507,3 @@ def initialize(context):
)
)
context
.
registerHelp
()
context
.
registerHelp
()
context
.
registerHelpTitle
(
'Zope Help'
)
context
.
registerHelpTitle
(
'Zope Help'
)
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