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