PLEASE PLEASE HELP!! Using an <dtml-if x>=y> statement with dates
I am trying to include only those dates that are before a certain date. However, if the first one is before, all of the dates are included which is not correct. I will then build this on, so that only dates that are between a certain range are included. The code that i am using, is: (obviously StartingDate is a variable that is being defined each time in DZEvent) <dtml-with ItineraryEvents> <dtml-in expr="objectValues('DZEvent')" sort=StartingDate> <dtml-let divider="'2004/01/12'" start=StartingDate> <dtml-if " divider>start"> <dtml-let start=StartingDate> The Date is: <dtml-var StartingDate> </dtml-let> </dtml-if> </dtml-let> </dtml-in> </dtml-with> Any help on or off list greatly appreciated, Tom
Read The Zope Book about DateTime objects. You need to do your comparison in the DateTime object space. On Sun, 16 Nov 2003 info@grabthebasics.com wrote:
I am trying to include only those dates that are before a certain date. However, if the first one is before, all of the dates are included which is not correct. I will then build this on, so that only dates that are between a certain range are included. The code that i am using, is: (obviously StartingDate is a variable that is being defined each time in DZEvent)
<dtml-with ItineraryEvents> <dtml-in expr="objectValues('DZEvent')" sort=StartingDate> <dtml-let divider="'2004/01/12'" start=StartingDate> <dtml-if " divider>start"> <dtml-let start=StartingDate> The Date is: <dtml-var StartingDate> </dtml-let> </dtml-if> </dtml-let> </dtml-in> </dtml-with>
Any help on or off list greatly appreciated,
Tom
On Sun, 2003-11-16 at 08:56, info@grabthebasics.com wrote:
I will then build this on, so that only dates that are between a certain range are included.
This is already something you should do in Python. If you're planning on adding any more, plan on switching. Your DTML should read like this: ----- <dtml-in pick_dates> however you're fomatting stuff goes here </dtml-in> ----- That leaves you to do the real work in a Python Script called pick_dates. Here's one stab at it: ----- from DateTime import DateTime range_start = DateTime('10/10/2003') range_end = DateTime('11/01/2003') in_range = [] for obj in context.objectValues('DSEvent'): if range_start <= obj.date_attr <= range_end: in_range.append((obj.date_attr, obj)) in_range.sort() return [item[1] for item in in_range] ----- Be sure to replace "date_attr" with whatever the correct attribute name is for your object. HTH, Dylan
participants (3)
-
Dennis Allison -
Dylan Reinhardt -
info@grabthebasics.com