Back to index

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

List of all members.

Public Member Functions

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

Public Attributes

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

Private Attributes

 _

Detailed Description

action base class with some generic stuff to inherit

Note: the action name is the class name of the derived class

Definition at line 43 of file __init__.py.


Constructor & Destructor Documentation

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

Reimplemented in MoinMoin.action.CopyPage.CopyPage, MoinMoin.action.Load.Load, MoinMoin.action.RenamePage.RenamePage, MoinMoin.action.DeletePage.DeletePage, and MoinMoin.action.revert.revert.

Definition at line 48 of file __init__.py.

00048 
00049     def __init__(self, pagename, request):
00050         self.request = request
00051         self.form = request.form
00052         self.cfg = request.cfg
00053         self._ = _ = request.getText
00054         self.pagename = pagename
00055         self.actionname = self.__class__.__name__
00056         self.use_ticket = False # set this to True if you want to use a ticket
00057         self.user_html = '''Just checking.''' # html fragment for make_form
00058         self.form_cancel = "cancel" # form key for cancelling action
00059         self.form_cancel_label = _("Cancel") # label for the cancel button
00060         self.form_trigger = "doit" # form key for triggering action (override with e.g. 'rename')
00061         self.form_trigger_label = _("Do it.") # label for the trigger button
00062         self.page = Page(request, pagename)
00063         self.error = ''
00064         self.method = 'POST'
00065         self.enctype = 'multipart/form-data'


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 in MoinMoin.action.CopyPage.CopyPage, MoinMoin.action.DeletePage.DeletePage, MoinMoin.action.RenamePage.RenamePage, and MoinMoin.action.revert.revert.

Definition at line 79 of file __init__.py.

00079 
00080     def check_condition(self):
00081         """ Check if some other condition is not allowing us to do that action,
00082             return error msg or None if there is no problem.
00083 
00084             You can use this to e.g. check if a page exists.
00085         """
00086         return None

Here is the caller graph for this function:

Do the action and either return error msg or None, if there was no error. 

Reimplemented in MoinMoin.action.revert.revert, MoinMoin.action.CopyPage.CopyPage, MoinMoin.action.DeletePage.DeletePage, MoinMoin.action.RenamePage.RenamePage, and MoinMoin.action.Load.Load.

Definition at line 217 of file __init__.py.

00217 
00218     def do_action(self):
00219         """ Do the action and either return error msg or None, if there was no error. """
00220         return None

Here is the caller graph for this function:

def MoinMoin.action.ActionBase.do_action_finish (   self,
  success 
)
Override this to handle success or failure (with error in self.error) of your action.

Reimplemented in MoinMoin.action.CopyPage.CopyPage, MoinMoin.action.Load.Load, and MoinMoin.action.RenamePage.RenamePage.

Definition at line 222 of file __init__.py.

00222 
00223     def do_action_finish(self, success):
00224         """ Override this to handle success or failure (with error in self.error) of your action.
00225         """
00226         if success:
00227             self.render_success(self.error, "info")
00228         else:
00229             self.render_msg(self.make_form(), "dialog") # display the form again
00230 
00231 
00232 # Builtin Actions ------------------------------------------------------------

Here is the call graph for this function:

Here is the caller graph for this function:

def MoinMoin.action.ActionBase.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 in MoinMoin.action.CopyPage.CopyPage, MoinMoin.action.Load.Load, MoinMoin.action.RenamePage.RenamePage, MoinMoin.action.revert.revert, and MoinMoin.action.DeletePage.DeletePage.

Definition at line 100 of file __init__.py.

00100 
00101     def get_form_html(self, buttons_html):
00102         """ Override this to assemble the inner part of the form,
00103             for convenience we give him some pre-assembled html for the buttons.
00104         """
00105         _ = self._
00106         f = self.request.formatter
00107         prompt = _("Execute action %(actionname)s?") % {'actionname': self.actionname}
00108         return f.paragraph(1) + f.text(prompt) + f.paragraph(0) + f.rawHTML(buttons_html)

Here is the caller 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 in MoinMoin.action.CopyPage.CopyPage, MoinMoin.action.RenamePage.RenamePage, MoinMoin.action.DeletePage.DeletePage, and MoinMoin.action.revert.revert.

Definition at line 71 of file __init__.py.

00071 
00072     def is_allowed(self):
00073         """
00074         Return True if action is allowed (by ACL), or
00075         return a tuple (allowed, message) to show a
00076         message other than the default.
00077         """
00078         return True

Here is the caller graph for this function:

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:

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:

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:

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:

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 
)
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 
)
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:

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 52 of file __init__.py.

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 in MoinMoin.action.Load.Load, and MoinMoin.action.revert.revert.

Definition at line 63 of file __init__.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 56 of file __init__.py.


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