[ZDP] BackTalk to Document The Zope Book (2.6 Edition)/Using Zope Page Templates

webmaster at zope.org webmaster at zope.org
Thu Nov 20 09:51:01 EST 2003


A comment to the paragraph below was recently added via http://zope.org/Documentation/Books/ZopeBook/2_6Edition/ZPT.stx#2-68

---------------

    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?



More information about the ZDP mailing list