annotate MoinMoin/action/PackagePages.py @ 5806:f94598e95801

fix pep8 issue
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Fri, 02 Dec 2011 20:53:35 +0100
parents 89882824b375
children
rev   line source
112
902ef76b6e5c Added PackagePages action, really.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
1 # -*- coding: iso-8859-1 -*-
902ef76b6e5c Added PackagePages action, really.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
2 """
902ef76b6e5c Added PackagePages action, really.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
3 MoinMoin - PackagePages action
902ef76b6e5c Added PackagePages action, really.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
4
902ef76b6e5c Added PackagePages action, really.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
5 This action allows you to package pages.
902ef76b6e5c Added PackagePages action, really.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
6
610
8dac4b68072b refactor RenamePage and DeletePage action to use ActionBase base class, move rename page code to PageEditor
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 566
diff changeset
7 TODO: use ActionBase class
8dac4b68072b refactor RenamePage and DeletePage action to use ActionBase base class, move rename page code to PageEditor
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 566
diff changeset
8
112
902ef76b6e5c Added PackagePages action, really.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
9 @copyright: 2005 MoinMoin:AlexanderSchremmer
4597
790e2dc06e9b action PackagePages: creates package files in memory and sends them to the caller
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 4425
diff changeset
10 2007-2009 MoinMoin:ReimarBauer
112
902ef76b6e5c Added PackagePages action, really.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
11 @license: GNU GPL, see COPYING for details.
902ef76b6e5c Added PackagePages action, really.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
12 """
4597
790e2dc06e9b action PackagePages: creates package files in memory and sends them to the caller
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 4425
diff changeset
13 import cStringIO
112
902ef76b6e5c Added PackagePages action, really.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
14 import os
902ef76b6e5c Added PackagePages action, really.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
15 import zipfile
902ef76b6e5c Added PackagePages action, really.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
16 from datetime import datetime
902ef76b6e5c Added PackagePages action, really.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
17
902ef76b6e5c Added PackagePages action, really.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
18 from MoinMoin import wikiutil, config, user
902ef76b6e5c Added PackagePages action, really.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
19 from MoinMoin.Page import Page
902ef76b6e5c Added PackagePages action, really.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
20 from MoinMoin.action.AttachFile import _addLogEntry
902ef76b6e5c Added PackagePages action, really.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
21 from MoinMoin.packages import MOIN_PACKAGE_FILE, packLine, unpackLine
1718
1d0663c1c44f PackagePages:added storing of attachments, form pagename text field gots current page name
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1317
diff changeset
22 from MoinMoin.action import AttachFile
1d0663c1c44f PackagePages:added storing of attachments, form pagename text field gots current page name
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1317
diff changeset
23 from MoinMoin.action.AttachFile import _get_files
3062
94941d9d30ee refactored action.PackagePages for CloneWikiPagesByPackagePages (Thanks to Federico Lorenzi) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3040
diff changeset
24 from MoinMoin.search import searchPages
112
902ef76b6e5c Added PackagePages action, really.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
25
1920
b06ef2a53efa 'make pylint', fixed lots of minor stuff found by pylint (and there is still lots left to do)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1868
diff changeset
26 class ActionError(Exception):
b06ef2a53efa 'make pylint', fixed lots of minor stuff found by pylint (and there is still lots left to do)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1868
diff changeset
27 pass
112
902ef76b6e5c Added PackagePages action, really.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
28
902ef76b6e5c Added PackagePages action, really.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
29 class PackagePages:
902ef76b6e5c Added PackagePages action, really.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
30 def __init__(self, pagename, request):
902ef76b6e5c Added PackagePages action, really.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
31 self.request = request
902ef76b6e5c Added PackagePages action, really.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
32 self.pagename = pagename
902ef76b6e5c Added PackagePages action, really.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
33 self.page = Page(request, pagename)
902ef76b6e5c Added PackagePages action, really.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
34
902ef76b6e5c Added PackagePages action, really.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
35 def allowed(self):
902ef76b6e5c Added PackagePages action, really.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
36 """ Check if user is allowed to do this. """
4726
be20177b2c0e action PackagePages: since we don't store the package file on the given page we don't need to check for write rights on that page
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 4597
diff changeset
37 return not self.__class__.__name__ in self.request.cfg.actions_excluded
949
cbbde07e00c4 whitespace-only cleanup, small style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 876
diff changeset
38
112
902ef76b6e5c Added PackagePages action, really.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
39 def render(self):
902ef76b6e5c Added PackagePages action, really.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
40 """ Render action
902ef76b6e5c Added PackagePages action, really.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
41
902ef76b6e5c Added PackagePages action, really.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
42 This action returns a wiki page with optional message, or
902ef76b6e5c Added PackagePages action, really.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
43 redirects to new page.
902ef76b6e5c Added PackagePages action, really.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
44 """
902ef76b6e5c Added PackagePages action, really.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
45 _ = self.request.getText
949
cbbde07e00c4 whitespace-only cleanup, small style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 876
diff changeset
46
4425
e78462e0c7f1 pre-1.9: request.form has qs args and post data, 1.9: .form only post data, .args only qs args, .values both
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 4423
diff changeset
47 if 'cancel' in self.request.values:
112
902ef76b6e5c Added PackagePages action, really.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
48 # User canceled
1777
ed44b93599b5 remove unneeded request param from page.send_page()
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1744
diff changeset
49 return self.page.send_page()
112
902ef76b6e5c Added PackagePages action, really.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
50
902ef76b6e5c Added PackagePages action, really.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
51 try:
902ef76b6e5c Added PackagePages action, really.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
52 if not self.allowed():
2966
ba14d391c2ba Refactor all modules to use the new add_msg interface in 1.7 (done by Frederico Lorenzi). Should not be backported to 1.6 but
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 2708
diff changeset
53 self.request.theme.add_msg(_('You are not allowed to edit this page.'), "error")
ba14d391c2ba Refactor all modules to use the new add_msg interface in 1.7 (done by Frederico Lorenzi). Should not be backported to 1.6 but
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 2708
diff changeset
54 raise ActionError
112
902ef76b6e5c Added PackagePages action, really.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
55 elif not self.page.exists():
3122
a1322262398a refactored _() getText calls to match new api
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3070
diff changeset
56 self.request.theme.add_msg(_('This page is already deleted or was never created!'))
2966
ba14d391c2ba Refactor all modules to use the new add_msg interface in 1.7 (done by Frederico Lorenzi). Should not be backported to 1.6 but
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 2708
diff changeset
57 raise ActionError
949
cbbde07e00c4 whitespace-only cleanup, small style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 876
diff changeset
58
112
902ef76b6e5c Added PackagePages action, really.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
59 self.package()
902ef76b6e5c Added PackagePages action, really.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
60 except ActionError, e:
2966
ba14d391c2ba Refactor all modules to use the new add_msg interface in 1.7 (done by Frederico Lorenzi). Should not be backported to 1.6 but
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 2708
diff changeset
61 return self.page.send_page()
112
902ef76b6e5c Added PackagePages action, really.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
62
902ef76b6e5c Added PackagePages action, really.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
63 def package(self):
3062
94941d9d30ee refactored action.PackagePages for CloneWikiPagesByPackagePages (Thanks to Federico Lorenzi) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3040
diff changeset
64 """ Calls collectpackage() with the arguments specified. """
112
902ef76b6e5c Added PackagePages action, really.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
65 _ = self.request.getText
949
cbbde07e00c4 whitespace-only cleanup, small style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 876
diff changeset
66
112
902ef76b6e5c Added PackagePages action, really.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
67 # Get new name from form and normalize.
4425
e78462e0c7f1 pre-1.9: request.form has qs args and post data, 1.9: .form only post data, .args only qs args, .values both
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 4423
diff changeset
68 pagelist = self.request.values.get('pagelist', u'')
e78462e0c7f1 pre-1.9: request.form has qs args and post data, 1.9: .form only post data, .args only qs args, .values both
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 4423
diff changeset
69 packagename = self.request.values.get('packagename', u'')
e78462e0c7f1 pre-1.9: request.form has qs args and post data, 1.9: .form only post data, .args only qs args, .values both
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 4423
diff changeset
70 include_attachments = self.request.values.get('include_attachments', False)
949
cbbde07e00c4 whitespace-only cleanup, small style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 876
diff changeset
71
4425
e78462e0c7f1 pre-1.9: request.form has qs args and post data, 1.9: .form only post data, .args only qs args, .values both
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 4423
diff changeset
72 if not self.request.values.get('submit'):
2966
ba14d391c2ba Refactor all modules to use the new add_msg interface in 1.7 (done by Frederico Lorenzi). Should not be backported to 1.6 but
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 2708
diff changeset
73 self.request.theme.add_msg(self.makeform(), "dialog")
ba14d391c2ba Refactor all modules to use the new add_msg interface in 1.7 (done by Frederico Lorenzi). Should not be backported to 1.6 but
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 2708
diff changeset
74 raise ActionError
112
902ef76b6e5c Added PackagePages action, really.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
75
902ef76b6e5c Added PackagePages action, really.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
76 target = wikiutil.taintfilename(packagename)
949
cbbde07e00c4 whitespace-only cleanup, small style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 876
diff changeset
77
112
902ef76b6e5c Added PackagePages action, really.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
78 if not target:
2966
ba14d391c2ba Refactor all modules to use the new add_msg interface in 1.7 (done by Frederico Lorenzi). Should not be backported to 1.6 but
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 2708
diff changeset
79 self.request.theme.add_msg(self.makeform(_('Invalid filename "%s"!') % wikiutil.escape(packagename)), "error")
ba14d391c2ba Refactor all modules to use the new add_msg interface in 1.7 (done by Frederico Lorenzi). Should not be backported to 1.6 but
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 2708
diff changeset
80 raise ActionError
949
cbbde07e00c4 whitespace-only cleanup, small style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 876
diff changeset
81
4597
790e2dc06e9b action PackagePages: creates package files in memory and sends them to the caller
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 4425
diff changeset
82 request = self.request
790e2dc06e9b action PackagePages: creates package files in memory and sends them to the caller
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 4425
diff changeset
83 filelike = cStringIO.StringIO()
790e2dc06e9b action PackagePages: creates package files in memory and sends them to the caller
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 4425
diff changeset
84 package = self.collectpackage(unpackLine(pagelist, ","), filelike, target, include_attachments)
5591
1dff6cfdcf90 http headers: for most cases, do not use .add, but .__setitem__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4726
diff changeset
85 request.headers['Content-Type'] = 'application/zip'
1dff6cfdcf90 http headers: for most cases, do not use .add, but .__setitem__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4726
diff changeset
86 request.headers['Content-Length'] = filelike.tell()
1dff6cfdcf90 http headers: for most cases, do not use .add, but .__setitem__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4726
diff changeset
87 request.headers['Content-Disposition'] = 'inline; filename="%s"' % target
4597
790e2dc06e9b action PackagePages: creates package files in memory and sends them to the caller
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 4425
diff changeset
88 request.write(filelike.getvalue())
790e2dc06e9b action PackagePages: creates package files in memory and sends them to the caller
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 4425
diff changeset
89 filelike.close()
112
902ef76b6e5c Added PackagePages action, really.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
90
902ef76b6e5c Added PackagePages action, really.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
91 def makeform(self, error=""):
3475
44a2f2f0d755 MoinMoin.action.PackagePages: fixed doc string
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3474
diff changeset
92 """ Display a package page form
112
902ef76b6e5c Added PackagePages action, really.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
93
3475
44a2f2f0d755 MoinMoin.action.PackagePages: fixed doc string
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3474
diff changeset
94 The form might contain an error that happened when package file was not given.
112
902ef76b6e5c Added PackagePages action, really.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
95 """
902ef76b6e5c Added PackagePages action, really.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
96 from MoinMoin.widget.dialog import Dialog
902ef76b6e5c Added PackagePages action, really.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
97 _ = self.request.getText
902ef76b6e5c Added PackagePages action, really.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
98
3474
b485c2b6b2b9 MoinMoin.action.PackagePages: shows only class error on error
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3273
diff changeset
99 if error:
b485c2b6b2b9 MoinMoin.action.PackagePages: shows only class error on error
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3273
diff changeset
100 error = u'<p class="error">%s</p>\n' % error
112
902ef76b6e5c Added PackagePages action, really.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
101
902ef76b6e5c Added PackagePages action, really.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
102 d = {
4235
a6c315ff8d66 Make more use of werkzeugs Href object for URL-generation in MoinMoin
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4210
diff changeset
103 'url': self.request.href(self.pagename),
112
902ef76b6e5c Added PackagePages action, really.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
104 'error': error,
902ef76b6e5c Added PackagePages action, really.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
105 'action': self.__class__.__name__,
3273
9c6900a92a64 more wikiutil.escape fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3213
diff changeset
106 'pagename': wikiutil.escape(self.pagename, True),
4065
d54e233a8784 package pages: feature added to optionally include attachments.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3775
diff changeset
107 'include_attachments_label': _('Include all attachments?'),
112
902ef76b6e5c Added PackagePages action, really.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
108 'package': _('Package pages'),
902ef76b6e5c Added PackagePages action, really.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
109 'cancel': _('Cancel'),
902ef76b6e5c Added PackagePages action, really.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
110 'newname_label': _("Package name"),
566
f52e03acf42a Changed i18n string in PackagePages
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 522
diff changeset
111 'list_label': _("List of page names - separated by a comma"),
112
902ef76b6e5c Added PackagePages action, really.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
112 }
902ef76b6e5c Added PackagePages action, really.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
113 form = '''
902ef76b6e5c Added PackagePages action, really.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
114 %(error)s
4235
a6c315ff8d66 Make more use of werkzeugs Href object for URL-generation in MoinMoin
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4210
diff changeset
115 <form method="post" action="%(url)s">
112
902ef76b6e5c Added PackagePages action, really.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
116 <input type="hidden" name="action" value="%(action)s">
902ef76b6e5c Added PackagePages action, really.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
117 <table>
902ef76b6e5c Added PackagePages action, really.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
118 <tr>
902ef76b6e5c Added PackagePages action, really.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
119 <td class="label"><label>%(newname_label)s</label></td>
902ef76b6e5c Added PackagePages action, really.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
120 <td class="content">
2708
5092edd82058 bug fix for non css browsers like w3m: for input fields set size of textarea and text to cols="80"
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2286
diff changeset
121 <input type="text" name="packagename" value="package.zip" size="80">
112
902ef76b6e5c Added PackagePages action, really.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
122 </td>
902ef76b6e5c Added PackagePages action, really.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
123 </tr>
902ef76b6e5c Added PackagePages action, really.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
124 <tr>
902ef76b6e5c Added PackagePages action, really.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
125 <td class="label"><label>%(list_label)s</label></td>
902ef76b6e5c Added PackagePages action, really.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
126 <td class="content">
3273
9c6900a92a64 more wikiutil.escape fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3213
diff changeset
127 <input type="text" name="pagelist" size="80" maxlength="200" value="%(pagename)s">
112
902ef76b6e5c Added PackagePages action, really.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
128 </td>
902ef76b6e5c Added PackagePages action, really.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
129 </tr>
902ef76b6e5c Added PackagePages action, really.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
130 <tr>
4065
d54e233a8784 package pages: feature added to optionally include attachments.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3775
diff changeset
131 <td class="label">
d54e233a8784 package pages: feature added to optionally include attachments.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3775
diff changeset
132 %(include_attachments_label)s<input type="checkbox" name="include_attachments" value="0" %(include_attachments_label)s>
d54e233a8784 package pages: feature added to optionally include attachments.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3775
diff changeset
133 </td>
d54e233a8784 package pages: feature added to optionally include attachments.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3775
diff changeset
134 </tr>
d54e233a8784 package pages: feature added to optionally include attachments.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3775
diff changeset
135 <tr>
112
902ef76b6e5c Added PackagePages action, really.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
136 <td></td>
902ef76b6e5c Added PackagePages action, really.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
137 <td class="buttons">
902ef76b6e5c Added PackagePages action, really.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
138 <input type="submit" name="submit" value="%(package)s">
902ef76b6e5c Added PackagePages action, really.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
139 <input type="submit" name="cancel" value="%(cancel)s">
902ef76b6e5c Added PackagePages action, really.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
140 </td>
902ef76b6e5c Added PackagePages action, really.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
141 </tr>
902ef76b6e5c Added PackagePages action, really.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
142 </table>
902ef76b6e5c Added PackagePages action, really.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
143 </form>''' % d
949
cbbde07e00c4 whitespace-only cleanup, small style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 876
diff changeset
144
cbbde07e00c4 whitespace-only cleanup, small style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 876
diff changeset
145 return Dialog(self.request, content=form)
cbbde07e00c4 whitespace-only cleanup, small style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 876
diff changeset
146
3062
94941d9d30ee refactored action.PackagePages for CloneWikiPagesByPackagePages (Thanks to Federico Lorenzi) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3040
diff changeset
147 def searchpackage(self, request, searchkey):
94941d9d30ee refactored action.PackagePages for CloneWikiPagesByPackagePages (Thanks to Federico Lorenzi) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3040
diff changeset
148 """ Search MoinMoin for the string specified and return a list of
94941d9d30ee refactored action.PackagePages for CloneWikiPagesByPackagePages (Thanks to Federico Lorenzi) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3040
diff changeset
149 matching pages, provided they are not system pages and not
94941d9d30ee refactored action.PackagePages for CloneWikiPagesByPackagePages (Thanks to Federico Lorenzi) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3040
diff changeset
150 present in the underlay.
3070
ed1a433803c6 PEP8 fixes
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3062
diff changeset
151
3062
94941d9d30ee refactored action.PackagePages for CloneWikiPagesByPackagePages (Thanks to Federico Lorenzi) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3040
diff changeset
152 @param request: current request
94941d9d30ee refactored action.PackagePages for CloneWikiPagesByPackagePages (Thanks to Federico Lorenzi) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3040
diff changeset
153 @param searchkey: string to search for
94941d9d30ee refactored action.PackagePages for CloneWikiPagesByPackagePages (Thanks to Federico Lorenzi) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3040
diff changeset
154 @rtype: list
94941d9d30ee refactored action.PackagePages for CloneWikiPagesByPackagePages (Thanks to Federico Lorenzi) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3040
diff changeset
155 @return: list of pages matching searchkey
94941d9d30ee refactored action.PackagePages for CloneWikiPagesByPackagePages (Thanks to Federico Lorenzi) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3040
diff changeset
156 """
94941d9d30ee refactored action.PackagePages for CloneWikiPagesByPackagePages (Thanks to Federico Lorenzi) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3040
diff changeset
157
94941d9d30ee refactored action.PackagePages for CloneWikiPagesByPackagePages (Thanks to Federico Lorenzi) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3040
diff changeset
158 pagelist = searchPages(request, searchkey)
3070
ed1a433803c6 PEP8 fixes
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3062
diff changeset
159
3062
94941d9d30ee refactored action.PackagePages for CloneWikiPagesByPackagePages (Thanks to Federico Lorenzi) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3040
diff changeset
160 titles = []
94941d9d30ee refactored action.PackagePages for CloneWikiPagesByPackagePages (Thanks to Federico Lorenzi) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3040
diff changeset
161 for title in pagelist.hits:
94941d9d30ee refactored action.PackagePages for CloneWikiPagesByPackagePages (Thanks to Federico Lorenzi) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3040
diff changeset
162 if not wikiutil.isSystemPage(request, title.page_name) or not title.page.getPageStatus()[0]:
94941d9d30ee refactored action.PackagePages for CloneWikiPagesByPackagePages (Thanks to Federico Lorenzi) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3040
diff changeset
163 titles.append(title.page_name)
94941d9d30ee refactored action.PackagePages for CloneWikiPagesByPackagePages (Thanks to Federico Lorenzi) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3040
diff changeset
164 return titles
94941d9d30ee refactored action.PackagePages for CloneWikiPagesByPackagePages (Thanks to Federico Lorenzi) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3040
diff changeset
165
4065
d54e233a8784 package pages: feature added to optionally include attachments.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3775
diff changeset
166 def collectpackage(self, pagelist, fileobject, pkgname="", include_attachments=False):
3062
94941d9d30ee refactored action.PackagePages for CloneWikiPagesByPackagePages (Thanks to Federico Lorenzi) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3040
diff changeset
167 """ Expects a list of pages as an argument, and fileobject to be an open
94941d9d30ee refactored action.PackagePages for CloneWikiPagesByPackagePages (Thanks to Federico Lorenzi) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3040
diff changeset
168 file object, which a zipfile will get written to.
3070
ed1a433803c6 PEP8 fixes
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3062
diff changeset
169
3062
94941d9d30ee refactored action.PackagePages for CloneWikiPagesByPackagePages (Thanks to Federico Lorenzi) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3040
diff changeset
170 @param pagelist: pages to package
94941d9d30ee refactored action.PackagePages for CloneWikiPagesByPackagePages (Thanks to Federico Lorenzi) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3040
diff changeset
171 @param fileobject: open file object to write to
94941d9d30ee refactored action.PackagePages for CloneWikiPagesByPackagePages (Thanks to Federico Lorenzi) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3040
diff changeset
172 @param pkgname: optional file name, to prevent self packaging
94941d9d30ee refactored action.PackagePages for CloneWikiPagesByPackagePages (Thanks to Federico Lorenzi) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3040
diff changeset
173 @rtype: string or None
94941d9d30ee refactored action.PackagePages for CloneWikiPagesByPackagePages (Thanks to Federico Lorenzi) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3040
diff changeset
174 @return: error message, if one happened
4065
d54e233a8784 package pages: feature added to optionally include attachments.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3775
diff changeset
175 @rtype: boolean
d54e233a8784 package pages: feature added to optionally include attachments.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3775
diff changeset
176 @param include_attachments: True if you want attachments collected
3062
94941d9d30ee refactored action.PackagePages for CloneWikiPagesByPackagePages (Thanks to Federico Lorenzi) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3040
diff changeset
177 """
94941d9d30ee refactored action.PackagePages for CloneWikiPagesByPackagePages (Thanks to Federico Lorenzi) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3040
diff changeset
178 _ = self.request.getText
94941d9d30ee refactored action.PackagePages for CloneWikiPagesByPackagePages (Thanks to Federico Lorenzi) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3040
diff changeset
179 COMPRESSION_LEVEL = zipfile.ZIP_DEFLATED
94941d9d30ee refactored action.PackagePages for CloneWikiPagesByPackagePages (Thanks to Federico Lorenzi) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3040
diff changeset
180
94941d9d30ee refactored action.PackagePages for CloneWikiPagesByPackagePages (Thanks to Federico Lorenzi) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3040
diff changeset
181 pages = []
94941d9d30ee refactored action.PackagePages for CloneWikiPagesByPackagePages (Thanks to Federico Lorenzi) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3040
diff changeset
182 for pagename in pagelist:
4146
3b36f0cfc656 (Re)moved normalizePagename from Request into wikiutil library
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 3475
diff changeset
183 pagename = wikiutil.normalize_pagename(pagename, self.request.cfg)
3062
94941d9d30ee refactored action.PackagePages for CloneWikiPagesByPackagePages (Thanks to Federico Lorenzi) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3040
diff changeset
184 if pagename:
94941d9d30ee refactored action.PackagePages for CloneWikiPagesByPackagePages (Thanks to Federico Lorenzi) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3040
diff changeset
185 page = Page(self.request, pagename)
94941d9d30ee refactored action.PackagePages for CloneWikiPagesByPackagePages (Thanks to Federico Lorenzi) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3040
diff changeset
186 if page.exists() and self.request.user.may.read(pagename):
94941d9d30ee refactored action.PackagePages for CloneWikiPagesByPackagePages (Thanks to Federico Lorenzi) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3040
diff changeset
187 pages.append(page)
94941d9d30ee refactored action.PackagePages for CloneWikiPagesByPackagePages (Thanks to Federico Lorenzi) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3040
diff changeset
188 if not pages:
3122
a1322262398a refactored _() getText calls to match new api
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3070
diff changeset
189 return (_('No pages like "%s"!') % wikiutil.escape(pagelist))
3062
94941d9d30ee refactored action.PackagePages for CloneWikiPagesByPackagePages (Thanks to Federico Lorenzi) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3040
diff changeset
190
94941d9d30ee refactored action.PackagePages for CloneWikiPagesByPackagePages (Thanks to Federico Lorenzi) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3040
diff changeset
191 # Set zipfile output
94941d9d30ee refactored action.PackagePages for CloneWikiPagesByPackagePages (Thanks to Federico Lorenzi) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3040
diff changeset
192 zf = zipfile.ZipFile(fileobject, "w", COMPRESSION_LEVEL)
94941d9d30ee refactored action.PackagePages for CloneWikiPagesByPackagePages (Thanks to Federico Lorenzi) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3040
diff changeset
193
94941d9d30ee refactored action.PackagePages for CloneWikiPagesByPackagePages (Thanks to Federico Lorenzi) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3040
diff changeset
194 cnt = 0
94941d9d30ee refactored action.PackagePages for CloneWikiPagesByPackagePages (Thanks to Federico Lorenzi) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3040
diff changeset
195 userid = user.getUserIdentification(self.request)
94941d9d30ee refactored action.PackagePages for CloneWikiPagesByPackagePages (Thanks to Federico Lorenzi) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3040
diff changeset
196 script = [packLine(['MoinMoinPackage', '1']), ]
94941d9d30ee refactored action.PackagePages for CloneWikiPagesByPackagePages (Thanks to Federico Lorenzi) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3040
diff changeset
197
94941d9d30ee refactored action.PackagePages for CloneWikiPagesByPackagePages (Thanks to Federico Lorenzi) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3040
diff changeset
198 for page in pages:
94941d9d30ee refactored action.PackagePages for CloneWikiPagesByPackagePages (Thanks to Federico Lorenzi) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3040
diff changeset
199 cnt += 1
94941d9d30ee refactored action.PackagePages for CloneWikiPagesByPackagePages (Thanks to Federico Lorenzi) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3040
diff changeset
200 files = _get_files(self.request, page.page_name)
94941d9d30ee refactored action.PackagePages for CloneWikiPagesByPackagePages (Thanks to Federico Lorenzi) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3040
diff changeset
201 script.append(packLine(["AddRevision", str(cnt), page.page_name, userid, "Created by the PackagePages action."]))
94941d9d30ee refactored action.PackagePages for CloneWikiPagesByPackagePages (Thanks to Federico Lorenzi) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3040
diff changeset
202
94941d9d30ee refactored action.PackagePages for CloneWikiPagesByPackagePages (Thanks to Federico Lorenzi) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3040
diff changeset
203 timestamp = wikiutil.version2timestamp(page.mtime_usecs())
5806
f94598e95801 fix pep8 issue
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5788
diff changeset
204
5788
89882824b375 avoid strange exception in zipfile.py for pre-1980 timestamps
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5591
diff changeset
205 # avoid getting strange exceptions from zipfile in case of pre-1980 timestamps
89882824b375 avoid strange exception in zipfile.py for pre-1980 timestamps
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5591
diff changeset
206 nineteeneighty = (10 * 365 + 3) * 24 * 3600 # 1970 + 10y + 3d
89882824b375 avoid strange exception in zipfile.py for pre-1980 timestamps
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5591
diff changeset
207 timestamp = max(nineteeneighty, timestamp) # zip can not store timestamps before 1980
89882824b375 avoid strange exception in zipfile.py for pre-1980 timestamps
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5591
diff changeset
208
3062
94941d9d30ee refactored action.PackagePages for CloneWikiPagesByPackagePages (Thanks to Federico Lorenzi) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3040
diff changeset
209 zi = zipfile.ZipInfo(filename=str(cnt), date_time=datetime.fromtimestamp(timestamp).timetuple()[:6])
94941d9d30ee refactored action.PackagePages for CloneWikiPagesByPackagePages (Thanks to Federico Lorenzi) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3040
diff changeset
210 zi.compress_type = COMPRESSION_LEVEL
94941d9d30ee refactored action.PackagePages for CloneWikiPagesByPackagePages (Thanks to Federico Lorenzi) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3040
diff changeset
211 zf.writestr(zi, page.get_raw_body().encode("utf-8"))
4065
d54e233a8784 package pages: feature added to optionally include attachments.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3775
diff changeset
212 if include_attachments:
d54e233a8784 package pages: feature added to optionally include attachments.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3775
diff changeset
213 for attname in files:
d54e233a8784 package pages: feature added to optionally include attachments.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3775
diff changeset
214 if attname != pkgname:
d54e233a8784 package pages: feature added to optionally include attachments.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3775
diff changeset
215 cnt += 1
d54e233a8784 package pages: feature added to optionally include attachments.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3775
diff changeset
216 zipname = "%d_attachment" % cnt
d54e233a8784 package pages: feature added to optionally include attachments.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3775
diff changeset
217 script.append(packLine(["AddAttachment", zipname, attname, page.page_name, userid, "Created by the PackagePages action."]))
d54e233a8784 package pages: feature added to optionally include attachments.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3775
diff changeset
218 filename = AttachFile.getFilename(self.request, page.page_name, attname)
d54e233a8784 package pages: feature added to optionally include attachments.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3775
diff changeset
219 zf.write(filename, zipname)
3062
94941d9d30ee refactored action.PackagePages for CloneWikiPagesByPackagePages (Thanks to Federico Lorenzi) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3040
diff changeset
220 script += [packLine(['Print', 'Thank you for using PackagePages!'])]
94941d9d30ee refactored action.PackagePages for CloneWikiPagesByPackagePages (Thanks to Federico Lorenzi) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3040
diff changeset
221
94941d9d30ee refactored action.PackagePages for CloneWikiPagesByPackagePages (Thanks to Federico Lorenzi) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3040
diff changeset
222 zf.writestr(MOIN_PACKAGE_FILE, u"\n".join(script).encode("utf-8"))
94941d9d30ee refactored action.PackagePages for CloneWikiPagesByPackagePages (Thanks to Federico Lorenzi) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3040
diff changeset
223 zf.close()
94941d9d30ee refactored action.PackagePages for CloneWikiPagesByPackagePages (Thanks to Federico Lorenzi) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3040
diff changeset
224
112
902ef76b6e5c Added PackagePages action, really.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
225 def execute(pagename, request):
902ef76b6e5c Added PackagePages action, really.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
226 """ Glue code for actions """
902ef76b6e5c Added PackagePages action, really.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
227 PackagePages(pagename, request).render()
949
cbbde07e00c4 whitespace-only cleanup, small style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 876
diff changeset
228