Attachment 'macro_template.py'

Download

   1 # -*- coding: UTF8 -*-
   2 """
   3     MoinMoin - ... macro
   4 
   5     Allows to ... .
   6 
   7     @copyright: 20??-20?? Autho Name <author@url.org>,
   8     @license: GNU GPL, see COPYING for details.
   9 """
  10 
  11 from MoinMoin import wikiutil
  12 from MoinMoin.Page import Page
  13 from MoinMoin.parser.text_moin_wiki import Parser as MoinParser
  14 
  15 
  16 class arg_to_dict(dict):
  17     def __init__(self, needle):
  18         dict.__init__(self)
  19         if needle!=None:
  20             for entry in needle.split(','):
  21                 try:
  22                     if entry.split('=')[1].strip() != '':
  23                         self[entry.split('=')[0].strip()]=entry.split('=')[1].strip()
  24                     else:
  25                         self[entry.split('=')[0].strip()]=None
  26                 except:
  27                     self[entry.split('=')[0].strip()]=None
  28 
  29 
  30 class Macro:
  31     def __init__(self, macro, needle):
  32         self.request = macro.request
  33         self.pagename = self.request.page.page_name
  34         self.formatter=self.request.formatter
  35         self.page = Page(self.request, self.pagename)
  36         self.pagepath=self.page.getPageBasePath()[1]
  37         self.url=self.request.href(self.request.page.page_name)
  38         self.url_full=self.request.getQualifiedURL(self.url)
  39         self.title = self.page.split_title()
  40         self.formargs=self.request.values
  41         self.macroargs=arg_to_dict(needle)
  42     def do(self):
  43         moin_output="""
  44 == Page Information ==
  45  * Moin-Pagename: %s
  46  * Moin-Pagetitle: %s
  47  * Moin-Pagepath: %s
  48  * Page-Url: %s
  49  * Full Page-Url: %s
  50  
  51 == Url/ Form data ==
  52 """%(self.pagename, self.title, self.pagepath, self.url, self.url_full)
  53         for key in self.formargs.keys():
  54             moin_output+=u" * %s=%s\n"%(key, self.formargs.get(key))
  55         moin_output+="== Acl ==\n"
  56         if self.request.user.may.read(self.pagename):
  57             moin_output+=u" * You have read rights.\n"
  58         else:
  59             moin_output+=" * You don't have read rights.\n"
  60         if self.request.user.may.write(self.pagename):
  61             moin_output+=u" * You have write rights.\n"
  62         else:
  63             moin_output+=u" * You don't have write rights.\n"
  64         moin_output+="== Macro data ==\n"
  65         for key in self.macroargs.keys():
  66             moin_output+=u" * %s=%s\n"%(key, self.macroargs.get(key))
  67         parser=MoinParser(moin_output, self.request)
  68         parser.format(self.formatter)
  69         return ''
  70 
  71 
  72 def execute(macro, needle):
  73     return Macro(macro, needle).do()

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2012-01-12 21:16:36, 2.4 KB) [[attachment:action_template.py]]
  • [get | view] (2012-01-12 21:16:11, 2.4 KB) [[attachment:macro_template.py]]
  • [get | view] (2012-01-12 21:15:50, 2.2 KB) [[attachment:parser_template.py]]
  • [get | view] (2014-01-19 09:43:21, 11.2 KB) [[attachment:template.zip]]
  • [get | view] (2014-01-13 08:09:48, 10.1 KB) [[attachment:template_old.zip]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.