Attachment 'GuestPassFile-1.0.py'

Download

   1 # -*- coding: iso-8859-1 -*-
   2 """
   3     MoinMoin - GuestPassFile macro Version 1.0, 5.01.2013
   4     
   5     Syntax:
   6        <<GuestPasses(filename=filename)>> 
   7 
   8     @copyright: 2013 Ian Riley <ian.riley@internode.on.net>
   9     
  10     incorporting code from:
  11     
  12     @copyright: 2006-2008 MoinMoin:ThomasWaldmann,
  13                 2007 MoinMoin:ReimarBauer
  14 
  15     license: GNU GPL, see COPYING for details.
  16 """
  17 
  18 import os, time
  19 from MoinMoin import user, wikiutil
  20 from MoinMoin.action import AttachFile
  21 from MoinMoin.Page import Page
  22 from MoinMoin.util import web
  23 
  24 def execute(macro, args):
  25     request = macro.request
  26     _ = request.getText
  27     pagename = macro.formatter.page.page_name
  28     f = macro.request.formatter
  29 
  30     action =  request.values.get('action', '')
  31     passcode = request.values.get('pass', '')
  32     
  33     args_dict = {'filename': '', }
  34     
  35     if args:
  36         try:
  37             args_parser = wikiutil.ParameterParser('%(filename)s')
  38             (count, args_dict) = args_parser.parse_parameters(args)
  39         except:
  40             return _('Error: GuestPassFilee macro has bad arguments.')
  41             
  42     filename = args_dict['filename']
  43     if not filename:
  44         return _('Error: GuestPassFile macro require a filename.')
  45   
  46     fileExists = AttachFile.exists(request, pagename, filename)
  47       
  48     if passcode and not request.user.may.read(pagename):
  49         querystr={'action': action, 'pass': passcode, 'show': filename, }
  50         if fileExists:
  51             result = Page(request, pagename).link_to(request, querystr=querystr,
  52                                                  css_class='attachment',
  53                                                  text=filename)
  54         else:
  55             result = _('Attachment "%(filename)s" not availabe.') % {'filename': filename}
  56     else:
  57         querystr={'action': 'AttachFile', 'do': 'view', 'target': filename, }       
  58         if fileExists:
  59             title = _('View attachment "%(filename)s"') % {'filename': filename}
  60             css_class = 'attachment'
  61         else:
  62             title = _('Upload new attachment "%(filename)s"') % {'filename': filename}
  63             css_class = 'attachment nonexistent'
  64             querystr['do']='upload_form'
  65             querystr['ticket'] = wikiutil.createTicket(request)
  66         result = Page(request, pagename).link_to(request, querystr=querystr,
  67                                                  css_class=css_class,
  68                                                  text=filename,
  69                                                  title=title)
  70 
  71     return result

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