Attachment 'PDFIcon1_1_0.py'
Download 1 # -*- coding: utf-8 -*-
2 """
3 MoinMoin - PDFIcon macro display a PDF icon which generate a PDF document
4
5 This macro is display a picture which is a link to ?action=CreatePdfDocument to create
6 a PDF document at once. The idear is to show a PDF ready page.
7
8 Please visit the homepage for further informations:
9 http://moinmo.in/ActionMarket/PdfAction
10
11 @copyright: 2006-2010 Raphael Bossek <raphael.bossek@solutions4linux.de>
12 @license: GNU GPL, see COPYING for details.
13 """
14
15 __version__ = u'1.1.0'
16
17 release_notes = """
18 2009-03-01 RaphaelBossek
19 * Release v1.1.0
20 * NEW: Initial support for MoinMoin 1.9 (including 1.8, 1.7, 1.6, 1.5!) and CreatePdfDocument v2.4.1
21 * NEW: Using PDF icon from MoinMoin homepage; change this
22 with `pdficon_imageurl` configuration variable, e.g. '/icons/pdf.png'.
23 Default: http://moinmo.in/ActionMarket/PdfAction?action=AttachFile&do=get&target=pdf48x48.png
24 * NEW: Using the `pdficon_action` configuration variable you are
25 able to define the name of the CreatePdfDocument action plugin.
26 Default: CreatePdfDocument
27
28 2007-08-15 RaphaelBossek
29 * Release v1.0.5
30 * Support for DOCBOOK (do not create any HTML content)
31
32 2006-11-16 RaphaelBossek
33 * Release v1.0.4
34 * Fixed URL for sub-pages.
35
36 2006-11-14 RaphaelBossek
37 * Release v1.0.3
38 * Moin 1.6 support added.
39
40 2006-09-12 RaphaelBossek
41 * Release v1.0.2
42 * Use the same workding for link description as the action macro. The same translation
43 for both can be used.
44
45 2006-09-06 RaphaelBossek
46 * Release v1.0.1
47 * Update to new action name, CreatePdfDocument
48
49 2006-08-31 RaphaelBossek
50 * Initial release v1.0.0
51 """
52
53 import re
54 from MoinMoin import wikiutil
55 from MoinMoin.version import release as moinmoin_release
56 if moinmoin_release[:4] in ['1.5.', '1.6.', '1.7.', '1.8.']:
57 class Version:
58 def __init__(self, version):
59 VERSION_RE = re.compile(r"(?P<major>\d+)\.(?P<minor>\d+)\.(?P<release>\d+)(-(?P<additional>.+))?", re.VERBOSE)
60 match = VERSION_RE.match(version)
61 v = match.groupdict()
62 self.major = int(v['major'])
63 self.minor = int(v['minor'])
64 self.release = int(v['release'])
65 moinmoin_version = Version(moinmoin_release)
66 else:
67 # Since MoinMoin 1.9
68 moinmoin_version = wikiutil.Version(version=moinmoin_release)
69
70
71 def is_moinmoin_version_eqless(major, minor):
72 return moinmoin_version.major <= major and moinmoin_version.minor <= minor
73
74
75 def merge_form_query(request):
76 """
77 This function intent to unifiy the way MoinMoin 1.9 differenciante
78 between form and query key/value pairs.
79 Since MoinMoin 1.9 key/value pairs are stored it two different dictonaries:
80 -- key/value which are set by query/url are within request.values
81 -- key/value which are set by from are within request.form
82 Until MoinMoin 1.8 key/value paires are stored only within request.form. Also
83 values are arrays; we use only the first array entry.
84 """
85 ret = {}
86 if is_moinmoin_version_eqless(1,8):
87 for k,v in request.form.iteritems():
88 ret[k] = v[0]
89 else:
90 # Since MoinMoin 1.9 werkzeug.datastructures.dict is used as datatype.
91 for k,v in request.form.iteritems():
92 ret[k] = v
93 # Sine MoinMoin 1.9 self.request.values is of type CombinedMultiDict
94 for k,v in request.values.iteritems():
95 ret[k] = v
96 return ret
97
98
99 def execute(macro, args):
100 if not getattr(macro.request.cfg, u'pdficon_imageurl', None):
101 #macro.request.cfg.pdficon_imageurl = u'/icons/pdf.png'
102 macro.request.cfg.pdficon_imageurl = u'http://moinmo.in/ActionMarket/PdfAction?action=AttachFile&do=get&target=pdf48x48.png'
103 if not getattr(macro.request.cfg, u'pdficon_action', None):
104 macro.request.cfg.pdficon_action = u'CreatePdfDocument'
105
106 form_wrapper = merge_form_query(macro.request)
107 if is_moinmoin_version_eqless(1,5):
108 is_print = form_wrapper.get(u'action', u'') == u'print' \
109 or (form_wrapper.get(u'action', u'') == macro.request.cfg.pdficon_action \
110 and form_wrapper.get(u'generate', u'') == u'1')
111 else:
112 # Since MoinMoin 1.6
113 is_print = macro.request.action == u'print'\
114 or (macro.request.action == macro.request.cfg.pdficon_action \
115 and form_wrapper.get(u'generate', u'') == u'1')
116
117 if not is_print:
118 if is_moinmoin_version_eqless(1,6):
119 url = macro.request.getQualifiedURL() + macro.request.getPathinfo()
120 else:
121 # Since MoinMoin 1.7
122 url = macro.request.getQualifiedURL() + macro.request.page.url(macro.request)
123 url = url + u'?action=%(action)s&generate=1' % ({'action': macro.request.cfg.pdficon_action})
124 return macro.formatter.rawHTML(u'<div style="float:right;"><a href="%s"><img src="%s" style="margin:.3em 0;" title="%s" border="0" /></a></div>\n' % (url, macro.request.cfg.pdficon_imageurl, macro.request.getText(u'Create Pdf Document'),))
125 return u''
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.You are not allowed to attach a file to this page.