Back to index

moin  1.9.0~rc2
Public Member Functions | Public Attributes
MoinMoin.action.CopyPage.CopyPage Class Reference
Inheritance diagram for MoinMoin.action.CopyPage.CopyPage:
Inheritance graph
[legend]
Collaboration diagram for MoinMoin.action.CopyPage.CopyPage:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def is_allowed
def check_condition
def do_action
def do_action_finish
def get_form_html
def is_excluded
def ticket_ok
def make_buttons
def make_form
def render_msg
def render_success
def render_cancel
def render

Public Attributes

 use_ticket
 form_trigger
 form_trigger_label
 subpages
 users_subpages
 page
 newpagename
 request
 form
 cfg
 pagename
 actionname
 user_html
 form_cancel
 form_cancel_label
 error
 method
 enctype

Detailed Description

Copy page action

Note: the action name is the class name

Definition at line 18 of file CopyPage.py.


Constructor & Destructor Documentation

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

Reimplemented from MoinMoin.action.ActionBase.

Definition at line 23 of file CopyPage.py.

00023 
00024     def __init__(self, pagename, request):
00025         ActionBase.__init__(self, pagename, request)
00026         self.use_ticket = True
00027         _ = self._
00028         self.form_trigger = 'copy'
00029         self.form_trigger_label = _('Copy Page')
00030         filterfn = re.compile(ur"^%s/.*$" % re.escape(pagename), re.U).match
00031         pages = request.rootpage.getPageList(user='', exists=1, filter=filterfn)
00032         subpagenames = request.rootpage.getPageList(user='', exists=1, filter=filterfn)
00033         self.subpages = subpagenames
00034         self.users_subpages = [pagename for pagename in subpagenames if self.request.user.may.read(pagename)]


Member Function Documentation

Check if some other condition is not allowing us to do that action,
    return error msg or None if there is no problem.

    You can use this to e.g. check if a page exists.

Reimplemented from MoinMoin.action.ActionBase.

Definition at line 39 of file CopyPage.py.

00039 
00040     def check_condition(self):
00041         _ = self._
00042         if not self.page.exists():
00043             return _('This page is already deleted or was never created!')
00044         else:
00045             return None

copy this page to "pagename" 

Reimplemented from MoinMoin.action.ActionBase.

Definition at line 46 of file CopyPage.py.

00046 
00047     def do_action(self):
00048         """ copy this page to "pagename" """
00049         _ = self._
00050         # Currently we only check TextCha for upload (this is what spammers ususally do),
00051         # but it could be extended to more/all attachment write access
00052         if not TextCha(self.request).check_answer_from_form():
00053             return status, _('TextCha: Wrong answer! Go back and try again...')
00054 
00055         form = self.form
00056         newpagename = form.get('newpagename', u'')
00057         newpagename = wikiutil.normalize_pagename(newpagename, self.cfg)
00058         comment = form.get('comment', u'')
00059         comment = wikiutil.clean_input(comment)
00060 
00061         self.page = PageEditor(self.request, self.pagename)
00062         success, msgs = self.page.copyPage(newpagename, comment)
00063 
00064         copy_subpages = 0
00065         try:
00066             copy_subpages = int(form['copy_subpages'])
00067         except:
00068             pass
00069 
00070         if copy_subpages and self.subpages or (not self.users_subpages and self.subpages):
00071             for name in self.subpages:
00072                 self.page = PageEditor(self.request, name)
00073                 new_subpagename = name.replace(self.pagename, newpagename, 1)
00074                 success_i, msg = self.page.copyPage(new_subpagename, comment)
00075                 msgs = "%s %s" % (msgs, msg)
00076 
00077         self.newpagename = newpagename # keep there for finish
00078         return success, msgs

Override this to handle success or failure (with error in self.error) of your action.

Reimplemented from MoinMoin.action.ActionBase.

Definition at line 79 of file CopyPage.py.

00079 
00080     def do_action_finish(self, success):
00081         if success:
00082             url = Page(self.request, self.newpagename).url(self.request)
00083             self.request.http_redirect(url)
00084         else:
00085             self.render_msg(self.make_form(), "dialog")

Here is the call graph for this function:

def MoinMoin.action.CopyPage.CopyPage.get_form_html (   self,
  buttons_html 
)
Override this to assemble the inner part of the form,
    for convenience we give him some pre-assembled html for the buttons.

Reimplemented from MoinMoin.action.ActionBase.

Definition at line 86 of file CopyPage.py.

00086 
00087     def get_form_html(self, buttons_html):
00088         _ = self._
00089         if self.users_subpages:
00090             subpages = ' '.join(self.users_subpages)
00091 
00092             d = {
00093                 'textcha': TextCha(self.request).render(),
00094                 'subpage': subpages,
00095                 'subpages_checked': ('', 'checked')[self.request.args.get('subpages_checked', '0') == '1'],
00096                 'subpage_label': _('Copy all /subpages too?'),
00097                 'pagename': wikiutil.escape(self.pagename, True),
00098                 'newname_label': _("New name"),
00099                 'comment_label': _("Optional reason for the copying"),
00100                 'buttons_html': buttons_html,
00101                 'querytext': _('Really copy this page?')
00102                 }
00103 
00104             return '''
00105 <strong>%(querytext)s</strong>
00106 <br>
00107 <br>
00108 %(textcha)s
00109 <table>
00110     <tr>
00111     <dd>
00112         %(subpage_label)s<input type="checkbox" name="copy_subpages" value="1" %(subpages_checked)s>
00113     </dd>
00114     <dd>
00115         <class="label"><subpage> %(subpage)s</subpage>
00116     </dd>
00117     </tr>
00118 </table>
00119 <table>
00120     <tr>
00121         <td class="label"><label>%(newname_label)s</label></td>
00122         <td class="content">
00123             <input type="text" name="newpagename" value="%(pagename)s" size="80">
00124         </td>
00125     </tr>
00126     <tr>
00127         <td class="label"><label>%(comment_label)s</label></td>
00128         <td class="content">
00129             <input type="text" name="comment" size="80" maxlength="200">
00130         </td>
00131     </tr>
00132     <tr>
00133         <td></td>
00134         <td class="buttons">
00135             %(buttons_html)s
00136         </td>
00137     </tr>
00138 </table>
00139 ''' % d
00140 
00141         else:
00142             d = {
00143                 'textcha': TextCha(self.request).render(),
00144                 'pagename': wikiutil.escape(self.pagename, True),
00145                 'newname_label': _("New name"),
00146                 'comment_label': _("Optional reason for the copying"),
00147                 'buttons_html': buttons_html,
00148                 }
00149             return '''
00150 %(textcha)s
00151 <table>
00152     <tr>
00153         <td class="label"><label>%(newname_label)s</label></td>
00154         <td class="content">
00155             <input type="text" name="newpagename" value="%(pagename)s" size="80">
00156         </td>
00157     </tr>
00158     <tr>
00159         <td class="label"><label>%(comment_label)s</label></td>
00160         <td class="content">
00161             <input type="text" name="comment" size="80" maxlength="200">
00162         </td>
00163     </tr>
00164     <tr>
00165         <td></td>
00166         <td class="buttons">
00167             %(buttons_html)s
00168         </td>
00169     </tr>
00170 </table>
00171 ''' % d

Here is the call graph for this function:

Return True if action is allowed (by ACL), or
return a tuple (allowed, message) to show a
message other than the default.

Reimplemented from MoinMoin.action.ActionBase.

Definition at line 35 of file CopyPage.py.

00035 
00036     def is_allowed(self):
00037         may = self.request.user.may
00038         return may.read(self.pagename)

def MoinMoin.action.ActionBase.is_excluded (   self) [inherited]
Return True if action is excluded 

Definition at line 67 of file __init__.py.

00067 
00068     def is_excluded(self):
00069         """ Return True if action is excluded """
00070         return self.actionname in self.cfg.actions_excluded

Here is the caller graph for this function:

def MoinMoin.action.ActionBase.make_buttons (   self) [inherited]
return a list of form buttons for the action form 

Definition at line 109 of file __init__.py.

00109 
00110     def make_buttons(self):
00111         """ return a list of form buttons for the action form """
00112         return [
00113             (self.form_trigger, self.form_trigger_label),
00114             (self.form_cancel, self.form_cancel_label),
00115         ]

Here is the caller graph for this function:

def MoinMoin.action.ActionBase.make_form (   self) [inherited]
Make some form html for later display.

The form might contain an error that happened when trying to do the action.

Definition at line 116 of file __init__.py.

00116 
00117     def make_form(self):
00118         """ Make some form html for later display.
00119 
00120         The form might contain an error that happened when trying to do the action.
00121         """
00122         from MoinMoin.widget.dialog import Dialog
00123         _ = self._
00124 
00125         if self.error:
00126             error_html = u'<p class="error">%s</p>\n' % self.error
00127         else:
00128             error_html = ''
00129 
00130         buttons = self.make_buttons()
00131         buttons_html = []
00132         for button in buttons:
00133             buttons_html.append('<input type="submit" name="%s" value="%s">' % button)
00134         buttons_html = "".join(buttons_html)
00135 
00136         if self.use_ticket:
00137             ticket_html = '<input type="hidden" name="ticket" value="%s">' % wikiutil.createTicket(self.request)
00138         else:
00139             ticket_html = ''
00140 
00141         d = {
00142             'method': self.method,
00143             'url': self.request.href(self.pagename),
00144             'enctype': self.enctype,
00145             'error_html': error_html,
00146             'actionname': self.actionname,
00147             'ticket_html': ticket_html,
00148             'user_html': self.get_form_html(buttons_html),
00149         }
00150 
00151         form_html = '''
00152 %(error_html)s
00153 <form action="%(url)s" method="%(method)s" enctype="%(enctype)s">
00154 <div>
00155 <input type="hidden" name="action" value="%(actionname)s">
00156 %(ticket_html)s
00157 %(user_html)s
00158 </div>
00159 </form>''' % d
00160 
00161         return Dialog(self.request, content=form_html)

Here is the call graph for this function:

Here is the caller graph for this function:

def MoinMoin.action.ActionBase.render (   self) [inherited]
Render action - this is the main function called by action's
    execute() function.

    We usually render a form here, check for posted forms, etc.

Definition at line 176 of file __init__.py.

00176 
00177     def render(self):
00178         """ Render action - this is the main function called by action's
00179             execute() function.
00180 
00181             We usually render a form here, check for posted forms, etc.
00182         """
00183         _ = self._
00184         form = self.form
00185 
00186         if self.form_cancel in form:
00187             self.render_cancel()
00188             return
00189 
00190         # Validate allowance, user rights and other conditions.
00191         error = None
00192         if self.is_excluded():
00193             error = _('Action %(actionname)s is excluded in this wiki!') % {'actionname': self.actionname }
00194         else:
00195             allowed = self.is_allowed()
00196             if isinstance(allowed, tuple):
00197                 allowed, msg = allowed
00198             else:
00199                 msg = _('You are not allowed to use action %(actionname)s on this page!') % {'actionname': self.actionname }
00200             if not allowed:
00201                 error = msg
00202         if error is None:
00203             error = self.check_condition()
00204         if error:
00205             self.render_msg(error, "error")
00206         elif self.form_trigger in form: # user hit the trigger button
00207             if self.ticket_ok():
00208                 success, self.error = self.do_action()
00209             else:
00210                 success = False
00211                 self.error = _('Please use the interactive user interface to use action %(actionname)s!') % {'actionname': self.actionname }
00212             self.do_action_finish(success)
00213         else:
00214             # Return a new form
00215             self.render_msg(self.make_form(), "dialog")

Here is the call graph for this function:

Here is the caller graph for this function:

def MoinMoin.action.ActionBase.render_cancel (   self) [inherited]
Called when user has hit the cancel button 

Definition at line 172 of file __init__.py.

00172 
00173     def render_cancel(self):
00174         """ Called when user has hit the cancel button """
00175         do_show(self.pagename, self.request)

Here is the call graph for this function:

Here is the caller graph for this function:

def MoinMoin.action.ActionBase.render_msg (   self,
  msg,
  msgtype 
) [inherited]
Called to display some message (can also be the action form) 

Definition at line 162 of file __init__.py.

00162 
00163     def render_msg(self, msg, msgtype):
00164         """ Called to display some message (can also be the action form) """
00165         self.request.theme.add_msg(msg, msgtype)
00166         do_show(self.pagename, self.request)

Here is the call graph for this function:

Here is the caller graph for this function:

def MoinMoin.action.ActionBase.render_success (   self,
  msg,
  msgtype 
) [inherited]
Called to display some message when the action succeeded 

Definition at line 167 of file __init__.py.

00167 
00168     def render_success(self, msg, msgtype):
00169         """ Called to display some message when the action succeeded """
00170         self.request.theme.add_msg(msg, msgtype)
00171         do_show(self.pagename, self.request)

Here is the call graph for this function:

Here is the caller graph for this function:

def MoinMoin.action.ActionBase.ticket_ok (   self) [inherited]
Return True if we check for tickets and there is some valid ticket
    in the form data or if we don't check for tickets at all.
    Use this to make sure someone really used the web interface.

Definition at line 87 of file __init__.py.

00087 
00088     def ticket_ok(self):
00089         """ Return True if we check for tickets and there is some valid ticket
00090             in the form data or if we don't check for tickets at all.
00091             Use this to make sure someone really used the web interface.
00092         """
00093         if not self.use_ticket:
00094             return True
00095         # Require a valid ticket. Make outside attacks harder by
00096         # requiring two full HTTP transactions
00097         ticket = self.form.get('ticket', '')
00098         return wikiutil.checkTicket(self.request, ticket)

Here is the caller graph for this function:


Member Data Documentation

Definition at line 54 of file __init__.py.

Definition at line 51 of file __init__.py.

Reimplemented in MoinMoin.action.Load.Load.

Definition at line 64 of file __init__.py.

Definition at line 62 of file __init__.py.

Definition at line 50 of file __init__.py.

Definition at line 57 of file __init__.py.

Definition at line 58 of file __init__.py.

Reimplemented from MoinMoin.action.ActionBase.

Definition at line 27 of file CopyPage.py.

Reimplemented from MoinMoin.action.ActionBase.

Definition at line 28 of file CopyPage.py.

Reimplemented in MoinMoin.action.Load.Load, and MoinMoin.action.revert.revert.

Definition at line 63 of file __init__.py.

Definition at line 76 of file CopyPage.py.

Reimplemented from MoinMoin.action.ActionBase.

Definition at line 60 of file CopyPage.py.

Reimplemented in MoinMoin.action.Load.Load.

Definition at line 53 of file __init__.py.

Definition at line 49 of file __init__.py.

Definition at line 32 of file CopyPage.py.

Reimplemented from MoinMoin.action.ActionBase.

Definition at line 25 of file CopyPage.py.

Definition at line 56 of file __init__.py.

Definition at line 33 of file CopyPage.py.


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