Help with calcualtions in DTML
Hello! I have the following listing of objects in my folder: <table> <tr> <td><p><b>Name</b></p></td> <td align="right"><p><b>Size</b></p></td> <td align="right"><p><b>date</b></p></td> </tr> <dtml-in expr="doc.objectValues()"> <tr> <td> <p><a href="<dtml-var absolute_url>"><dtml-var id></a></p> </td> <td align="right"> <p><dtml-var get_size> bytes</p> </td> <td align="right"> <p><dtml-var bobobase_modification_time fmt="%Y-%m-%d %H:%M"></p> </td> </tr> </dtml-in> </table> It gives me the name of the object, the size in bytes and the modification time in GMT. I need to do the following: express the size in kb, format the output with spaces for thousands. I also need the date displayed according to my locale (+2 GMT in Sweden) so if bobobase_modification_time is 10:48, I need to show it as 8:48, and on top of that I also need to take dayligth savings into account. How do I do it? The fmt strings are abviously adjusted to US standards, so us ISO-people need to hack our own format strings :-). I know i could calculate the size in KB myself IF I only knew how to get the get_size attribute into a calculation expression (that goes for bobobase_modification_time as well, however this returns as string. How do I get the date as a date?) Any help is appreciated and needed. Thank you. /dario PS: has anyone been thinking of renaming bobobase_modification_time to something shorter and more intuitive, like, say, modification_time? :-)) - -------------------------------------------------------------------- Dario Lopez-Kästen Systems Developer Chalmers Univ. of Technology dario@ita.chalmers.se ICQ will yield no hits IT Systems & Services
"Dario Lopez-Kästen" wrote:
Hello!
I have the following listing of objects in my folder:
<table> <tr> <td><p><b>Name</b></p></td> <td align="right"><p><b>Size</b></p></td> <td align="right"><p><b>date</b></p></td> </tr> <dtml-in expr="doc.objectValues()"> <tr> <td> <p><a href="<dtml-var absolute_url>"><dtml-var id></a></p> </td> <td align="right"> <p><dtml-var get_size> bytes</p> </td> <td align="right"> <p><dtml-var bobobase_modification_time fmt="%Y-%m-%d %H:%M"></p> </td> </tr> </dtml-in> </table>
you might want to grab a copy of the ZQR which goes through most of the zope's methods and syntax. http://www.zope.org/Members/ZQR get size in kbs assuming its an int <dtml-var "get_size/1000"> this should do the formatting (tested) <dtml-let x="_.str(get_size/1000)"> <dtml-if "_.len(x)>3"> <dtml-var "'%s %s'%(x[:-3], x[-3:])"> <dtml-else> <dtml-var x> </dtml-if> </dtml-let> the time stuff <dtml-var "bobobase_modification_time().toZone('GMT+2')">
It gives me the name of the object, the size in bytes and the modification time in GMT.
there is also a way to set this to be local time(your zope that is).... to sleepy to remember or look it up....... try searching the mailing lists... although i'm sure someone will chime in.
I need to do the following: express the size in kb, format the output with spaces for thousands.
I also need the date displayed according to my locale (+2 GMT in Sweden) so if bobobase_modification_time is 10:48, I need to show it as 8:48, and on top of that I also need to take dayligth savings into account.
How do I do it? The fmt strings are abviously adjusted to US standards, so us ISO-people need to hack our own format strings :-).
I know i could calculate the size in KB myself IF I only knew how to get the get_size attribute into a calculation expression (that goes for bobobase_modification_time as well, however this returns as string. How do I get the date as a date?)
you might want to check out some of the howtos on DTML stuff, although generally its easier to do complex calculations in a python method. bobobase_modification_time is a method that returns a date time object, its just formatted as a string on the page when you render it.
Any help is appreciated and needed. Thank you.
/dario
PS: has anyone been thinking of renaming bobobase_modification_time to something shorter and more intuitive, like, say, modification_time?
it gets my vote. Cheers Kapil
Kapil Thangavelu wrote:
http://www.zope.org/Members/ZQR
get size in kbs assuming its an int
<dtml-var "get_size/1000">
<dtml-var "get_size/1024"> pedantically yours, -- ethan mindlace fremen Zopatista Community Liason Abnegate I!
Kapil Thangavelu wrote:
http://www.zope.org/Members/ZQR
get size in kbs assuming its an int
<dtml-var "get_size/1000">
<dtml-var "get_size/1024">
pedantically yours, -- ethan mindlace fremen Zopatista Community Liason Abnegate I!
actually it turns out to be <dtml-var "size/1024"> get_size and getSize do not work for files (for reasons unknown to me; I am a Zope newbie :-). haven't tried for any other objects. Anybody knows more about the DateTime issues I posted about earlier? /dario - -------------------------------------------------------------------- Dario Lopez-Kästen Systems Developer Chalmers Univ. of Technology dario@ita.chalmers.se ICQ will yield no hits IT Systems & Services
participants (3)
-
Dario Lopez-K�sten -
ethan mindlace fremen -
Kapil Thangavelu