[ZDP] BackTalk to Document The Zope Book (2.6 Edition)/Using Zope
Page Templates
webmaster at zope.org
webmaster at zope.org
Tue Dec 2 23:22:27 EST 2003
A comment to the paragraph below was recently added via http://zope.org/Documentation/Books/ZopeBook/2_6Edition/ZPT.stx#2-66
---------------
There are a few cosmetic problems with the file library as it
stands. The size and date displays of the default content are very
pretty, but the values returned from Zope don't match the format
of the dummy content. Instead, they are "raw" numbers. You would
like the size of the files to be displayed in K or MB rather than
bytes. Here's a Python-based script that you can use for this::
## Script (Python) "file_size"
##
"""
Return a string describing the size of a file.
"""
bytes=context.getSize()
k=bytes/1024.0
mb=bytes/1048576.0
if mb > 1:
return "%.2f MB" % mb
if k > 1:
return "%d K" % k
return "%d bytes" % bytes
% Anonymous User - Nov. 4, 2003 10:53 am:
We are learning about TAL?
% Anonymous User - Nov. 4, 2003 10:57 am:
Might it be appropriate to state somewhere that Page Templates accomodate TAL, TALES, METAL and Python and
that TAL statements can use Python expressions if prefaced by python:? A header such as "Complex Expressions"
might then be appropriate. Or is that "Advanced Page Templates"?
I cannot penetrate TAL via this chapter.
% Anonymous User - Nov. 20, 2003 9:51 am:
So 'context' is a standard builtin Zope object, and 'getSize' is a standard builtin method of 'context' ??
Using TAL syntax we activate the 'getsize' method of 'context' by making "context/getsize" the value of some
TAL attribute (tal:something="context/getsize")??
Using python syntax we activate the 'getsize' method of 'context' by typing:
something=context.getSize() or possibly:
return context.getSize()
Am I right or wrong?
% Anonymous User - Dec. 2, 2003 11:22 pm:
'context' is specific to Python Scripts. It means the same thing as 'here' in Page Templates. They really
should have the same name in both; this is a historical wart. In a future version of zope (2.8?), 'context'
will be available in Page Templates too and we can forget about 'here'.
getSize is specific to objects that have size, such as Images and Files.
otherwise, you are right.
More information about the ZDP
mailing list