Details
- Applies to
MoinMoin actions (action/PackagePages.py) v1.8.2, v1.9beta2
- Purpose
- Allow to package pages found with search string
- Description
Extends original PackagePages action with search field (taking priority over pages names list) allowing user to define title search query (simple). Pages found will be packaged.
There are two patches submitted:
- 1.8 patch - just adds page search functionality, package is to be saved in the attachments list
- 1.9 patch - adds page search functionality to the mainstream version, package is to be sent to client
Patch
1 --- PackagePages.py.old 2009-01-07 01:26:50.000000000 +0100
2 +++ PackagePages.py 2009-03-26 17:50:59.000000000 +0100
3 @@ -69,6 +69,7 @@
4
5 # Get new name from form and normalize.
6 pagelist = form.get('pagelist', [u''])[0]
7 + searchpattern = form.get('searchpattern', [u''])[0]
8 packagename = form.get('packagename', [u''])[0]
9 include_attachments = form.get('include_attachments', [False])[0]
10
11 @@ -92,7 +93,16 @@
12
13 # Generate a package
14 output = open(fpath, "wb")
15 - package = self.collectpackage(unpackLine(pagelist, ","), output, target, include_attachments)
16 +
17 + # Determine where to get pages from - list or pattern search
18 + if not searchpattern:
19 + package = self.collectpackage(unpackLine(pagelist, ","), output,
20 + target, include_attachments)
21 + else:
22 + searchpages = self.searchpackage(self.request, searchpattern)
23 + package = self.collectpackage(searchpages, output, target,
24 + include_attachments)
25 + pagelist = "".join([item.join(" ,") for item in searchpages]).strip(",")
26
27 if package:
28 self.request.theme.add_msg(self.makeform(), "dialog")
29 @@ -100,7 +110,7 @@
30
31 _addLogEntry(self.request, 'ATTNEW', self.pagename, target)
32
33 - self.request.theme.add_msg(_("Created the package %s containing the pages %s.") % (wikiutil.escape(target), wikiutil.escape(pagelist)))
34 + self.request.theme.add_msg(_("Created the package %s containing the pages:<br> %s.") % (wikiutil.escape(target), wikiutil.escape(pagelist)))
35 raise ActionError
36
37 def makeform(self, error=""):
38 @@ -125,6 +135,7 @@
39 'cancel': _('Cancel'),
40 'newname_label': _("Package name"),
41 'list_label': _("List of page names - separated by a comma"),
42 + 'searchpattern_label': _("Search pattern - takes priority over list of page names if specified"),
43 }
44 form = '''
45 %(error)s
46 @@ -138,15 +149,22 @@
47 </td>
48 </tr>
49 <tr>
50 + <td class="label"><label>%(searchpattern_label)s</label></td>
51 + <td class="content">
52 + <input type="text" name="searchpattern" size="80" maxlength="200" value="">
53 + </td>
54 + </tr>
55 + <tr>
56 <td class="label"><label>%(list_label)s</label></td>
57 <td class="content">
58 <input type="text" name="pagelist" size="80" maxlength="200" value="%(pagename)s">
59 </td>
60 </tr>
61 <tr>
62 - <td class="label">
63 - %(include_attachments_label)s<input type="checkbox" name="include_attachments" value="0" %(include_attachments_label)s>
64 - </td>
65 + <td class="label"> %(include_attachments_label)s </td>
66 + <td class="content">
67 + <input type="checkbox" name="include_attachments" value="0" %(include_attachments_label)s>
68 + </td>
69 </tr>
70 <tr>
71 <td></td>
72 @@ -163,7 +181,8 @@
73 def searchpackage(self, request, searchkey):
74 """ Search MoinMoin for the string specified and return a list of
75 matching pages, provided they are not system pages and not
76 - present in the underlay.
77 + present in the underlay. The search is being performed only based on
78 + titles
79
80 @param request: current request
81 @param searchkey: string to search for
82 @@ -171,7 +190,7 @@
83 @return: list of pages matching searchkey
84 """
85
86 - pagelist = searchPages(request, searchkey)
87 + pagelist = searchPages(request, searchkey, titlesearch=1)
88
89 titles = []
90 for title in pagelist.hits:
1 --- PackagePages.old.py 2009-03-14 14:22:44.000000000 +0100
2 +++ PackagePages.py 2009-03-27 04:05:33.000000000 +0100
3 @@ -69,6 +69,7 @@
4 # Get new name from form and normalize.
5 pagelist = self.request.values.get('pagelist', u'')
6 packagename = self.request.values.get('packagename', u'')
7 + searchpattern = self.request.values.get('searchpattern', [u''])
8 include_attachments = self.request.values.get('include_attachments', False)
9
10 if not self.request.values.get('submit'):
11 @@ -83,7 +84,15 @@
12
13 request = self.request
14 filelike = cStringIO.StringIO()
15 - package = self.collectpackage(unpackLine(pagelist, ","), filelike, target, include_attachments)
16 +
17 + # Determine where to get pages from - list or pattern search
18 + if not searchpattern:
19 + package = self.collectpackage(unpackLine(pagelist, ","), filelike, target, include_attachments)
20 + else:
21 + searchpages = self.searchpackage(self.request, searchpattern)
22 + package = self.collectpackage(searchpages, filelike, target, include_attachments)
23 + pagelist = "".join([item.join(" ,") for item in searchpages]).strip(",")
24 +
25 request.content_type = 'application/zip'
26 request.content_length = filelike.tell()
27 request.headers.add('Content-Disposition', 'inline; filename="%s"' % target)
28 @@ -111,6 +120,7 @@
29 'cancel': _('Cancel'),
30 'newname_label': _("Package name"),
31 'list_label': _("List of page names - separated by a comma"),
32 + 'searchpattern_label': _("Search pattern - takes priority over list of page names if specified"),
33 }
34 form = '''
35 %(error)s
36 @@ -124,15 +134,23 @@
37 </td>
38 </tr>
39 <tr>
40 + <td class="label"><label>%(searchpattern_label)s</label></td>
41 + <td class="content">
42 + <input type="text" name="searchpattern" size="80" maxlength="200" value="">
43 + </td>
44 + </tr>
45 + <tr>
46 +
47 <td class="label"><label>%(list_label)s</label></td>
48 <td class="content">
49 <input type="text" name="pagelist" size="80" maxlength="200" value="%(pagename)s">
50 </td>
51 </tr>
52 <tr>
53 - <td class="label">
54 - %(include_attachments_label)s<input type="checkbox" name="include_attachments" value="0" %(include_attachments_label)s>
55 - </td>
56 + <td class="label"> %(include_attachments_label)s </td>
57 + <td class="content">
58 + <input type="checkbox" name="include_attachments" value="0" %(include_attachments_label)s>
59 + </td>
60 </tr>
61 <tr>
62 <td></td>
63 @@ -149,7 +167,9 @@
64 def searchpackage(self, request, searchkey):
65 """ Search MoinMoin for the string specified and return a list of
66 matching pages, provided they are not system pages and not
67 - present in the underlay.
68 + present in the underlay. The search is being performed only based on
69 + titles
70 +
71
72 @param request: current request
73 @param searchkey: string to search for
74 @@ -157,7 +177,7 @@
75 @return: list of pages matching searchkey
76 """
77
78 - pagelist = searchPages(request, searchkey)
79 + pagelist = searchPages(request, searchkey, titlesearch=1)
80
81 titles = []
82 for title in pagelist.hits:
Discussion
I consider adding this patch to 1.9. Because in 1.9 we have changed packagepage output to download and not to save on a page. If you want me to safe time please read PEP 8 and fix the indenting in your patch. Don't use tabs. The default of attchments included True is not a good idea. That can kill every server.
e.g
18 - package = self.collectpackage(unpackLine(pagelist, ","), output, target, include_attachments) 19 + 20 + # Determine where to get pages from - list or pattern search 21 + if not searchpattern: 22 + package = self.collectpackage(unpackLine(pagelist, ","), output, target, include_attachments) 23 + else: 24 + searchpages = self.searchpackage(self.request, searchpattern) 25 + package = self.collectpackage(searchpages, output, target, include_attachments) 26 + pagelist = "".join([item.replace('\\', '\\\\').replace(", ", '\\' + ", ").join(" ,") for item in searchpages]).strip(",")
for what is
pagelist = "".join([item.replace('\\', '\\\\').replace(", ", '\\' + ", ").join(" ,") for item in searchpages]).strip(",")
needed? It sounds strange '\\\\'.
-- ReimarBauer 2009-03-22 09:38:13
Hi, regarding the patch fixing, i'll do it probably by the end of next week (lots of work currently). About your last remark - honestly, i have copied it from somewhere (probably moin command-line package exporter). I'll take care of it as well -- StellarsHenson 2009-03-22 22:24:28
Hi, uploaded new patch as promised -- StellarsHenson 2009-03-26 16:56:09
Reimar, I have just added a patch against the newest mainstream version, 1.9beta2. Works fine. -- StellarsHenson 2009-03-27 03:08:42
Does this patch come into V1.9? I can't find it in the 1.9Beta4. In my opinion it's very useful. -- JosefMeier 2009-10-23 08:50:35
Plan
- Priority:
- Assigned to:
- Status: