← Back to team overview

zim-wiki team mailing list archive

Re: Getting dates into template

 

On 23 February 2012 10:57, Jaap Karssenberg <jaap.karssenberg@xxxxxxxxx> wrote:
> On Thu, Feb 23, 2012 at 10:33 AM, Iago Mosqueira <iago.mosqueira@xxxxxxxxx>
> wrote:
>>
>> Hi,
>>
>> I am trying to modify the Calendar.txt template when used in weekly mode
>> to show
>>
>> ===== Mon 1 Jan =====
>>
>> ===== Tue 2 Jan ======
>>
>> and so on. The calendar plugin only gives variables for the start and
>> end dates of the week, so how I can tell strftime to output the other
>> days? I tried with
>>
>> strftime("%a %d %b", calendar_plugin.date + datetime.timedelta(days=1))
>>
>> but did not work. I am probably doing something very wrong, as I have
>> never programmed in python before.
>
>
> The reason it does not work is that the template does not allow arbitrary
> python code. The few functions that are available are hard coded in the
> template formatting.
>
> So doing something like this would require additional functions to the
> template engine.
>
> Regards,
>
> Jaap
>

Hi,

Many thanks for the quick reply. I have hacked calendar.py slightly to
achieve what I wanted, by exporting mon_date to fri_date. Please find
a diff file attached, but this cannot probably be considered a proper
submission, first python ever for me.

Regards,


Iago
87,91d86
< 			mon_date = date + datetime.timedelta(1)
< 			tue_date = date + datetime.timedelta(2)
< 			wed_date = date + datetime.timedelta(3)
< 			thu_date = date + datetime.timedelta(4)
< 			fri_date = date + datetime.timedelta(5)
110c105
< 	return type, date, end_date, mon_date, tue_date, wed_date, thu_date, fri_date
---
> 	return type, date, end_date
252,256d246
< 				'mon_date': daterange[3],
< 				'tue_date': daterange[4],
< 				'wed_date': daterange[5],
< 				'thu_date': daterange[6],
< 				'fri_date': daterange[7],

Follow ups

References