Back to index

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

List of all members.

Public Member Functions

def __init__
def do_action
def do_action_finish
def get_form_html
def is_excluded
def is_allowed
def check_condition
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
 pagename
 method
 enctype
 request
 form
 cfg
 actionname
 user_html
 form_cancel
 form_cancel_label
 page
 error

Detailed Description

Load page action

Note: the action name is the class name

Definition at line 18 of file Load.py.


Constructor & Destructor Documentation

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

Reimplemented from MoinMoin.action.ActionBase.

Definition at line 23 of file Load.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 = 'Load'
00029         self.form_trigger_label = _('Load')
00030         self.pagename = pagename
00031         self.method = 'POST'
00032         self.enctype = 'multipart/form-data'


Member Function Documentation

def MoinMoin.action.ActionBase.check_condition (   self) [inherited]
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:

Load 

Reimplemented from MoinMoin.action.ActionBase.

Definition at line 33 of file Load.py.

00033 
00034     def do_action(self):
00035         """ Load """
00036         status = False
00037         _ = self._
00038         form = self.form
00039         request = self.request
00040         # Currently we only check TextCha for upload (this is what spammers ususally do),
00041         # but it could be extended to more/all attachment write access
00042         if not TextCha(request).check_answer_from_form():
00043             return status, _('TextCha: Wrong answer! Go back and try again...')
00044 
00045         comment = form.get('comment', u'')
00046         comment = wikiutil.clean_input(comment)
00047 
00048         file_upload = request.files.get('file')
00049         if not file_upload:
00050             # This might happen when trying to upload file names
00051             # with non-ascii characters on Safari.
00052             return False, _("No file content. Delete non ASCII characters from the file name and try again.")
00053 
00054         filename = file_upload.filename
00055         rename = form.get('rename', '').strip()
00056         if rename:
00057             target = rename
00058         else:
00059             target = filename
00060 
00061         target = wikiutil.clean_input(target)
00062 
00063         if target:
00064             filecontent = file_upload.stream.read() # XXX reads complete file into memory!
00065             filecontent = wikiutil.decodeUnknownInput(filecontent)
00066 
00067             self.pagename = target
00068             pg = PageEditor(request, self.pagename)
00069             try:
00070                 msg = pg.saveText(filecontent, 0, comment=comment)
00071                 status = True
00072             except pg.EditConflict, e:
00073                 msg = e.message
00074             except pg.SaveError, msg:
00075                 msg = unicode(msg)
00076         else:
00077             msg = _("Pagename not specified!")
00078         return status, msg

def MoinMoin.action.Load.Load.do_action_finish (   self,
  success 
)
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 Load.py.

00079 
00080     def do_action_finish(self, success):
00081         if success:
00082             url = Page(self.request, self.pagename).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.Load.Load.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 Load.py.

00086 
00087     def get_form_html(self, buttons_html):
00088         _ = self._
00089         return """
00090 <h2>%(headline)s</h2>
00091 <p>%(explanation)s</p>
00092 <dl>
00093 <dt>%(upload_label_file)s</dt>
00094 <dd><input type="file" name="file" size="50" value=""></dd>
00095 <dt>%(upload_label_rename)s</dt>
00096 <dd><input type="text" name="rename" size="50" value="%(pagename)s"></dd>
00097 <dt>%(upload_label_comment)s</dt>
00098 <dd><input type="text" name="comment" size="80" maxlength="200"></dd>
00099 </dl>
00100 %(textcha)s
00101 <p>
00102 <input type="hidden" name="action" value="%(action_name)s">
00103 <input type="hidden" name="do" value="upload">
00104 </p>
00105 <td class="buttons">
00106 %(buttons_html)s
</td>""" % {

Here is the call graph for this function:

def MoinMoin.action.ActionBase.is_allowed (   self) [inherited]
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:

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 from MoinMoin.action.ActionBase.

Definition at line 31 of file Load.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 Load.py.

Reimplemented from MoinMoin.action.ActionBase.

Definition at line 28 of file Load.py.

Reimplemented from MoinMoin.action.ActionBase.

Definition at line 30 of file Load.py.

Reimplemented from MoinMoin.action.ActionBase.

Definition at line 29 of file Load.py.

Definition at line 49 of file __init__.py.

Reimplemented from MoinMoin.action.ActionBase.

Definition at line 25 of file Load.py.

Definition at line 56 of file __init__.py.


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