diff MoinMoin/action/PackagePages.py @ 4065:d54e233a8784

package pages: feature added to optionally include attachments.
author Reimar Bauer <rb.proj AT googlemail DOT com>
date Mon, 01 Sep 2008 09:16:49 +0200
parents e458af23d64d
children 62177a952833
line wrap: on
line diff
--- a/MoinMoin/action/PackagePages.py	Sun Aug 31 22:14:02 2008 +0200
+++ b/MoinMoin/action/PackagePages.py	Mon Sep 01 09:16:49 2008 +0200
@@ -70,6 +70,7 @@
         # Get new name from form and normalize.
         pagelist = form.get('pagelist', [u''])[0]
         packagename = form.get('packagename', [u''])[0]
+        include_attachments = form.get('include_attachments', [False])[0]
 
         if not form.get('submit', [None])[0]:
             self.request.theme.add_msg(self.makeform(), "dialog")
@@ -91,7 +92,7 @@
 
         # Generate a package
         output = open(fpath, "wb")
-        package = self.collectpackage(unpackLine(pagelist, ","), output, target)
+        package = self.collectpackage(unpackLine(pagelist, ","), output, target, include_attachments)
 
         if package:
             self.request.theme.add_msg(self.makeform(), "dialog")
@@ -119,6 +120,7 @@
             'action': self.__class__.__name__,
             'pagename': wikiutil.escape(self.pagename, True),
             'pagename_quoted': wikiutil.quoteWikinameURL(self.pagename),
+            'include_attachments_label': _('Include all attachments?'),
             'package': _('Package pages'),
             'cancel': _('Cancel'),
             'newname_label': _("Package name"),
@@ -142,6 +144,11 @@
         </td>
     </tr>
     <tr>
+        <td class="label">
+        %(include_attachments_label)s<input type="checkbox" name="include_attachments" value="0" %(include_attachments_label)s>
+    </td>
+    </tr>
+    <tr>
         <td></td>
         <td class="buttons">
             <input type="submit" name="submit" value="%(package)s">
@@ -172,7 +179,7 @@
                 titles.append(title.page_name)
         return titles
 
-    def collectpackage(self, pagelist, fileobject, pkgname=""):
+    def collectpackage(self, pagelist, fileobject, pkgname="", include_attachments=False):
         """ Expects a list of pages as an argument, and fileobject to be an open
         file object, which a zipfile will get written to.
 
@@ -181,6 +188,8 @@
         @param pkgname: optional file name, to prevent self packaging
         @rtype: string or None
         @return: error message, if one happened
+        @rtype: boolean
+        @param include_attachments: True if you want attachments collected
         """
         _ = self.request.getText
         COMPRESSION_LEVEL = zipfile.ZIP_DEFLATED
@@ -211,13 +220,14 @@
             zi = zipfile.ZipInfo(filename=str(cnt), date_time=datetime.fromtimestamp(timestamp).timetuple()[:6])
             zi.compress_type = COMPRESSION_LEVEL
             zf.writestr(zi, page.get_raw_body().encode("utf-8"))
-            for attname in files:
-                if attname != pkgname:
-                    cnt += 1
-                    zipname = "%d_attachment" % cnt
-                    script.append(packLine(["AddAttachment", zipname, attname, page.page_name, userid, "Created by the PackagePages action."]))
-                    filename = AttachFile.getFilename(self.request, page.page_name, attname)
-                    zf.write(filename, zipname)
+            if include_attachments:
+                for attname in files:
+                    if attname != pkgname:
+                        cnt += 1
+                        zipname = "%d_attachment" % cnt
+                        script.append(packLine(["AddAttachment", zipname, attname, page.page_name, userid, "Created by the PackagePages action."]))
+                        filename = AttachFile.getFilename(self.request, page.page_name, attname)
+                        zf.write(filename, zipname)
         script += [packLine(['Print', 'Thank you for using PackagePages!'])]
 
         zf.writestr(MOIN_PACKAGE_FILE, u"\n".join(script).encode("utf-8"))