annotate data/plugin/macro/PdfList.py @ 653:127da830be6c

updated copyright
author Reimar Bauer <rb.proj AT googlemail DOT com>
date Tue, 19 Apr 2016 16:29:54 +0200
parents 8abf42ff06e3
children 8c828d7b6cd4
rev   line source
649
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
1 """
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
2 MoinMoin - PdfList Macro
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
3
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
4 A macro to produce a list of attached pdf by reading meta data
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
5
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
6 Usage: <<PdfList([pagename])>>
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
7
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
8 If pagename isn't set, the current pagename is used.
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
9
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
10
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
11 @copyright: 2004 Jacob Cohen, Nigel Metheringham,
653
127da830be6c updated copyright
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 651
diff changeset
12 2006-2016 MoinMoin:ReimarBauer
649
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
13 @license: GNU GPL, see COPYING for details.
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
14 """
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
15
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
16 import os
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
17 import re
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
18 import mimetypes
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
19 from MoinMoin.action.AttachFile import getAttachDir, getAttachUrl, _get_files
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
20 from MoinMoin import wikiutil
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
21 from MoinMoin import config
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
22
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
23 # ToDo change to pyPDF2
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
24 try:
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
25 from pyPdf import PdfFileReader
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
26 except ImportError:
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
27 try:
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
28 from MoinMoin.support.pyPdf import PdfFileReader
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
29 except ImportError:
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
30 PdfFileReader = None
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
31
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
32 def _build_filelist(request, pagename, showheader, readonly, mime_type='application/pdf', filterfn=None):
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
33
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
34 _ = request.getText
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
35
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
36 fmt = request.html_formatter
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
37
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
38 # access directory
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
39 attach_dir = getAttachDir(request, pagename)
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
40 files = _get_files(request, pagename)
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
41
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
42 if mime_type != '*':
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
43 files = [fname for fname in files if mime_type == mimetypes.guess_type(fname)[0]]
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
44 if filterfn is not None:
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
45 files = [fname for fname in files if filterfn(fname)]
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
46
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
47 html = []
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
48 if files:
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
49 if showheader:
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
50 html.append(fmt.rawHTML(_(
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
51 "To refer to attachments on a page, use '''{{{attachment:filename}}}''', \n"
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
52 "as shown below in the list of files. \n"
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
53 "Do '''NOT''' use the URL of the {{{[get]}}} link, \n"
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
54 "since this is subject to change and can break easily.",
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
55 wiki=True
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
56 )))
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
57
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
58 label_get = _("get")
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
59 label_edit = _("edit")
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
60 label_view = _("view")
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
61 may_write = request.user.may.write(pagename)
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
62
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
63
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
64 html.append(u"""\
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
65 <script>
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
66 function checkAll(bx, targets_name) {
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
67 var cbs = document.getElementsByTagName('input');
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
68 for(var i=0; i < cbs.length; i++) {
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
69 if(cbs[i].type == 'checkbox' && cbs[i].name == targets_name) {
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
70 cbs[i].checked = bx.checked;
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
71 }
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
72 }
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
73 }
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
74 </script>
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
75 <form method="POST">
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
76 <input type="hidden" name="action" value="AttachFile">
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
77 <input type="hidden" name="do" value="multifile">
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
78 """)
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
79
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
80
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
81 # ToDo use to DataBrowserWidget
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
82 html.append('<table>')
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
83 html.append('<tr><td><b>Author</b></td><td><b>Title</b></td><td></td><td></td></tr>')
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
84 for file in files:
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
85 html.append('<tr>')
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
86 html.append('<td>')
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
87
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
88 fullpath = os.path.join(attach_dir, file).encode(config.charset)
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
89 pdf = PdfFileReader(open(fullpath, 'rb'))
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
90 pdf_meta = pdf.documentInfo
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
91 xmp_meta = pdf.xmpMetadata
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
92 try:
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
93 pdf_meta = {"/Title": wikiutil.escape(xmp_meta.dc_title['x-default']),
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
94 "/Author": wikiutil.escape(pdf_meta['/Author'])}
651
8abf42ff06e3 macro: PdfList typo fixed
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 650
diff changeset
95 except (AttributeError, KeyError):
649
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
96 pass
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
97
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
98
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
99 links = []
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
100
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
101 links.append(fmt.url(1, getAttachUrl(pagename, file, request)) +
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
102 fmt.text(label_get) +
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
103 fmt.url(0))
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
104
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
105 links.append(fmt.url(1, getAttachUrl(pagename, file, request, do='view')) +
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
106 fmt.text(label_view) +
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
107 fmt.url(0))
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
108
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
109 if may_write and not readonly:
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
110 edit_url = getAttachUrl(pagename, file, request, do='modify')
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
111 if edit_url:
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
112 links.append(fmt.url(1, edit_url) +
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
113 fmt.text(label_edit) +
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
114 fmt.url(0))
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
115
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
116
650
cd3309f76490 macro: PdfList, issue witout any meta solved
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 649
diff changeset
117 title = None
cd3309f76490 macro: PdfList, issue witout any meta solved
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 649
diff changeset
118 author = None
cd3309f76490 macro: PdfList, issue witout any meta solved
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 649
diff changeset
119 if pdf_meta.has_key('/Title'):
cd3309f76490 macro: PdfList, issue witout any meta solved
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 649
diff changeset
120 title = pdf_meta['/Title']
cd3309f76490 macro: PdfList, issue witout any meta solved
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 649
diff changeset
121 if pdf_meta.has_key('/Author'):
cd3309f76490 macro: PdfList, issue witout any meta solved
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 649
diff changeset
122 author = pdf_meta['/Author']
cd3309f76490 macro: PdfList, issue witout any meta solved
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 649
diff changeset
123
cd3309f76490 macro: PdfList, issue witout any meta solved
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 649
diff changeset
124
cd3309f76490 macro: PdfList, issue witout any meta solved
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 649
diff changeset
125 if author or title:
cd3309f76490 macro: PdfList, issue witout any meta solved
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 649
diff changeset
126 html.append("%(/Author)s</td><td>%(/Title)s</td><td>" % {"/Title": wikiutil.escape(title),
cd3309f76490 macro: PdfList, issue witout any meta solved
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 649
diff changeset
127 "/Author": wikiutil.escape(author)})
cd3309f76490 macro: PdfList, issue witout any meta solved
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 649
diff changeset
128
cd3309f76490 macro: PdfList, issue witout any meta solved
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 649
diff changeset
129 else:
649
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
130 html.append('</td><td>%(filename)s</td><td>' % {"filename": file})
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
131
650
cd3309f76490 macro: PdfList, issue witout any meta solved
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 649
diff changeset
132
649
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
133 html.append("%s" % "&nbsp;</td><td> ".join(links))
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
134 html.append('</td>')
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
135 html.append('</tr>')
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
136
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
137
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
138 html.append('</table>')
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
139 html.append("</form>")
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
140 html.append("...based on PDF Meta information")
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
141
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
142 else:
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
143 if showheader:
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
144 html.append(fmt.paragraph(1))
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
145 html.append(fmt.text(_("No attachments stored for %(pagename)s") % {
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
146 'pagename': pagename}))
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
147 html.append(fmt.paragraph(0))
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
148
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
149 html.append(fmt.table(0))
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
150 return ''.join(html)
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
151
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
152 def macro_PdfList(macro, pagename=None, mime_type=u'*', search_term=u'.+'):
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
153 # defaults if we don't get anything better
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
154 if PdfFileReader is None:
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
155 return u"please install pyPdf"
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
156 if not pagename:
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
157 pagename = macro.formatter.page.page_name
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
158 filterfn = re.compile(search_term, re.U).search
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
159 return _build_filelist(macro.request, pagename, 0, 1, mime_type='application/pdf', filterfn=filterfn)
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
160
4b31e0f1bcc8 macro: PdfList based on pyPdf.PdfFileReader, reads Author and Title from each attached PDF file and outputs a table for easy access
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
161