Back to index

moin  1.9.0~rc2
Public Member Functions | Public Attributes
MoinMoin.action.PackagePages.PackagePages Class Reference

List of all members.

Public Member Functions

def __init__
def allowed
def render
def package
def makeform
def searchpackage
def collectpackage

Public Attributes

 request
 pagename
 page

Detailed Description

Definition at line 29 of file PackagePages.py.


Constructor & Destructor Documentation

def MoinMoin.action.PackagePages.PackagePages.__init__ (   self,
  pagename,
  request 
)

Definition at line 30 of file PackagePages.py.

00030 
00031     def __init__(self, pagename, request):
00032         self.request = request
00033         self.pagename = pagename
00034         self.page = Page(request, pagename)


Member Function Documentation

Check if user is allowed to do this. 

Definition at line 35 of file PackagePages.py.

00035 
00036     def allowed(self):
00037         """ Check if user is allowed to do this. """
00038         return not self.__class__.__name__ in self.request.cfg.actions_excluded

Here is the caller graph for this function:

def MoinMoin.action.PackagePages.PackagePages.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.

@param pagelist: pages to package
@param fileobject: open file object to write to
@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

Definition at line 166 of file PackagePages.py.

00166 
00167     def collectpackage(self, pagelist, fileobject, pkgname="", include_attachments=False):
00168         """ Expects a list of pages as an argument, and fileobject to be an open
00169         file object, which a zipfile will get written to.
00170 
00171         @param pagelist: pages to package
00172         @param fileobject: open file object to write to
00173         @param pkgname: optional file name, to prevent self packaging
00174         @rtype: string or None
00175         @return: error message, if one happened
00176         @rtype: boolean
00177         @param include_attachments: True if you want attachments collected
00178         """
00179         _ = self.request.getText
00180         COMPRESSION_LEVEL = zipfile.ZIP_DEFLATED
00181 
00182         pages = []
00183         for pagename in pagelist:
00184             pagename = wikiutil.normalize_pagename(pagename, self.request.cfg)
00185             if pagename:
00186                 page = Page(self.request, pagename)
00187                 if page.exists() and self.request.user.may.read(pagename):
00188                     pages.append(page)
00189         if not pages:
00190             return (_('No pages like "%s"!') % wikiutil.escape(pagelist))
00191 
00192         # Set zipfile output
00193         zf = zipfile.ZipFile(fileobject, "w", COMPRESSION_LEVEL)
00194 
00195         cnt = 0
00196         userid = user.getUserIdentification(self.request)
00197         script = [packLine(['MoinMoinPackage', '1']), ]
00198 
00199         for page in pages:
00200             cnt += 1
00201             files = _get_files(self.request, page.page_name)
00202             script.append(packLine(["AddRevision", str(cnt), page.page_name, userid, "Created by the PackagePages action."]))
00203 
00204             timestamp = wikiutil.version2timestamp(page.mtime_usecs())
00205             zi = zipfile.ZipInfo(filename=str(cnt), date_time=datetime.fromtimestamp(timestamp).timetuple()[:6])
00206             zi.compress_type = COMPRESSION_LEVEL
00207             zf.writestr(zi, page.get_raw_body().encode("utf-8"))
00208             if include_attachments:
00209                 for attname in files:
00210                     if attname != pkgname:
00211                         cnt += 1
00212                         zipname = "%d_attachment" % cnt
00213                         script.append(packLine(["AddAttachment", zipname, attname, page.page_name, userid, "Created by the PackagePages action."]))
00214                         filename = AttachFile.getFilename(self.request, page.page_name, attname)
00215                         zf.write(filename, zipname)
00216         script += [packLine(['Print', 'Thank you for using PackagePages!'])]
00217 
00218         zf.writestr(MOIN_PACKAGE_FILE, u"\n".join(script).encode("utf-8"))
00219         zf.close()

Here is the call graph for this function:

Here is the caller graph for this function:

def MoinMoin.action.PackagePages.PackagePages.makeform (   self,
  error = "" 
)
Display a package page form

The form might contain an error that happened when package file was not given.

Definition at line 91 of file PackagePages.py.

00091 
00092     def makeform(self, error=""):
00093         """ Display a package page form
00094 
00095         The form might contain an error that happened when package file was not given.
00096         """
00097         from MoinMoin.widget.dialog import Dialog
00098         _ = self.request.getText
00099 
00100         if error:
00101             error = u'<p class="error">%s</p>\n' % error
00102 
00103         d = {
00104             'url': self.request.href(self.pagename),
00105             'error': error,
00106             'action': self.__class__.__name__,
00107             'pagename': wikiutil.escape(self.pagename, True),
00108             'include_attachments_label': _('Include all attachments?'),
00109             'package': _('Package pages'),
00110             'cancel': _('Cancel'),
00111             'newname_label': _("Package name"),
00112             'list_label': _("List of page names - separated by a comma"),
00113         }
00114         form = '''
00115 %(error)s
00116 <form method="post" action="%(url)s">
00117 <input type="hidden" name="action" value="%(action)s">
00118 <table>
00119     <tr>
00120         <td class="label"><label>%(newname_label)s</label></td>
00121         <td class="content">
00122             <input type="text" name="packagename" value="package.zip" size="80">
00123         </td>
00124     </tr>
00125     <tr>
00126         <td class="label"><label>%(list_label)s</label></td>
00127         <td class="content">
00128             <input type="text" name="pagelist" size="80" maxlength="200" value="%(pagename)s">
00129         </td>
00130     </tr>
00131     <tr>
00132         <td class="label">
00133         %(include_attachments_label)s<input type="checkbox" name="include_attachments" value="0" %(include_attachments_label)s>
00134     </td>
00135     </tr>
00136     <tr>
00137         <td></td>
00138         <td class="buttons">
00139             <input type="submit" name="submit" value="%(package)s">
00140             <input type="submit" name="cancel" value="%(cancel)s">
00141         </td>
00142     </tr>
00143 </table>
00144 </form>''' % d
00145 
00146         return Dialog(self.request, content=form)

Here is the caller graph for this function:

Calls collectpackage() with the arguments specified. 

Definition at line 63 of file PackagePages.py.

00063 
00064     def package(self):
00065         """ Calls collectpackage() with the arguments specified. """
00066         _ = self.request.getText
00067 
00068         # Get new name from form and normalize.
00069         pagelist = self.request.values.get('pagelist', u'')
00070         packagename = self.request.values.get('packagename', u'')
00071         include_attachments = self.request.values.get('include_attachments', False)
00072 
00073         if not self.request.values.get('submit'):
00074             self.request.theme.add_msg(self.makeform(), "dialog")
00075             raise ActionError
00076 
00077         target = wikiutil.taintfilename(packagename)
00078 
00079         if not target:
00080             self.request.theme.add_msg(self.makeform(_('Invalid filename "%s"!') % wikiutil.escape(packagename)), "error")
00081             raise ActionError
00082 
00083         request = self.request
00084         filelike = cStringIO.StringIO()
00085         package = self.collectpackage(unpackLine(pagelist, ","), filelike, target, include_attachments)
00086         request.content_type = 'application/zip'
00087         request.content_length = filelike.tell()
00088         request.headers.add('Content-Disposition', 'inline; filename="%s"' % target)
00089         request.write(filelike.getvalue())
00090         filelike.close()

Here is the call graph for this function:

Here is the caller graph for this function:

Render action

This action returns a wiki page with optional message, or
redirects to new page.

Definition at line 39 of file PackagePages.py.

00039 
00040     def render(self):
00041         """ Render action
00042 
00043         This action returns a wiki page with optional message, or
00044         redirects to new page.
00045         """
00046         _ = self.request.getText
00047 
00048         if 'cancel' in self.request.values:
00049             # User canceled
00050             return self.page.send_page()
00051 
00052         try:
00053             if not self.allowed():
00054                 self.request.theme.add_msg(_('You are not allowed to edit this page.'), "error")
00055                 raise ActionError
00056             elif not self.page.exists():
00057                 self.request.theme.add_msg(_('This page is already deleted or was never created!'))
00058                 raise ActionError
00059 
00060             self.package()
00061         except ActionError, e:
00062             return self.page.send_page()

Here is the call graph for this function:

def MoinMoin.action.PackagePages.PackagePages.searchpackage (   self,
  request,
  searchkey 
)
Search MoinMoin for the string specified and return a list of
matching pages, provided they are not system pages and not
present in the underlay.

@param request: current request
@param searchkey: string to search for
@rtype: list
@return: list of pages matching searchkey

Definition at line 147 of file PackagePages.py.

00147 
00148     def searchpackage(self, request, searchkey):
00149         """ Search MoinMoin for the string specified and return a list of
00150         matching pages, provided they are not system pages and not
00151         present in the underlay.
00152 
00153         @param request: current request
00154         @param searchkey: string to search for
00155         @rtype: list
00156         @return: list of pages matching searchkey
00157         """
00158 
00159         pagelist = searchPages(request, searchkey)
00160 
00161         titles = []
00162         for title in pagelist.hits:
00163             if not wikiutil.isSystemPage(request, title.page_name) or not title.page.getPageStatus()[0]:
00164                 titles.append(title.page_name)
00165         return titles

Here is the call graph for this function:


Member Data Documentation

Definition at line 33 of file PackagePages.py.

Definition at line 32 of file PackagePages.py.

Definition at line 31 of file PackagePages.py.


The documentation for this class was generated from the following file: