[Moin-devel] Macro operating on whole Page?

Iwan van der Kleyn iwan at vanderkleyn.com
Mon Feb 17 14:18:07 EST 2003


Hi there,

I'm currently trying to figure out how to write custom macros and 
actions. This because at my company, my development team has just 
started to use MoinMoin for documentation and process related info. I 
still haven't fully grasped its inner workings, nor do I had the chance 
to get to know the culture of the 'development scene' surounding it. So 
plase indulge me if I go outa line here :-)

I'm writing a few macros which are operating on the *whole* text of a 
Page from within a macro.I've created a macro [[PostDate]] which not 
just inserts the date of posting, but *replaces* the occurance of the 
macro itself. This as to avoid that the date changes like the [[Date]] 
macro.

Well, it works, but my question is if this how it's supposed to be done? 
Does anyone have other/better suggestions?

Regards,

Iwan


#______________________________________________________

def Now():
	import time
	arr = time.localtime()
	return '%s-%s-%s'% (arr[2],arr[1],arr[0])

def execute(macro, args):
	
	t = Now()	

	#if Preview then just display date
	#if not preview; page is displayed with macro for first time; display 
date & replace macro occurance in Page-text
	#make date-string permanent
	if macro.form.has_key("preview") and macro.formatter.page.isWritable() 
and macro.formatter.page.exists():
	
		from MoinMoin.PageEditor import PageEditor
		p = PageEditor(macro.formatter.page.page_name, macro.request)	
		#Load text; replace macro with date and save
		s = macro.formatter.page.get_raw_body().replace('[[PostDate]]', t)
		p.saveText(s,'0')

	return t
	





More information about the Moin-devel mailing list