Back to index

moin  1.9.0~rc2
Functions | Variables
MoinMoin.macro.RandomQuote Namespace Reference

Functions

def macro_RandomQuote

Variables

list Dependencies = ["time"]

Function Documentation

def MoinMoin.macro.RandomQuote.macro_RandomQuote (   macro,
  pagename = u'FortuneCookies' 
)

Definition at line 28 of file RandomQuote.py.

00028 
00029 def macro_RandomQuote(macro, pagename=u'FortuneCookies'):
00030     _ = macro.request.getText
00031 
00032     if macro.request.user.may.read(pagename):
00033         page = Page(macro.request, pagename)
00034         raw = page.get_raw_body()
00035     else:
00036         raw = ""
00037 
00038     # this selects lines looking like a list item
00039     # !!! TODO: make multi-line quotes possible (optionally split by "----" or something)
00040     quotes = raw.splitlines()
00041     quotes = [quote.strip() for quote in quotes]
00042     quotes = [quote[2:] for quote in quotes if quote.startswith('* ')]
00043 
00044     if not quotes:
00045         return (macro.formatter.highlight(1) +
00046                 _('No quotes on %(pagename)s.') % {'pagename': pagename} +
00047                 macro.formatter.highlight(0))
00048 
00049     quote = random.choice(quotes)
00050     page.set_raw_body(quote, 1)
00051     quote = macro.request.redirectedOutput(page.send_page,
00052         content_only=1, content_id="RandomQuote")
00053 
00054     return quote
00055 

Variable Documentation

Definition at line 26 of file RandomQuote.py.