annotate MoinMoin/action/revert.py @ 3374:043689a3b04c

action.revert: fixed doc string
author Reimar Bauer <rb.proj AT googlemail DOT com>
date Thu, 20 Mar 2008 22:03:19 +0100
parents c20aa5b0158e
children 4082eab1fe16 126559845d4b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1104
abe498212fb8 move revert code to action/revert.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1 # -*- coding: iso-8859-1 -*-
abe498212fb8 move revert code to action/revert.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
2 """
abe498212fb8 move revert code to action/revert.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
3 MoinMoin - revert a page to a previous revision
abe498212fb8 move revert code to action/revert.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
4
1918
bb2e053067fb fixing copyright headers: remove umlauts (encoding troubles), make epydoc compatible, reformat
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1881
diff changeset
5 @copyright: 2000-2004 Juergen Hermann <jh@web.de>,
3356
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
6 2006 MoinMoin:ThomasWaldmann,
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
7 2007 MoinMoin:ReimarBauer,
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
8 2008 MoinMoin:JohannesBerg
1104
abe498212fb8 move revert code to action/revert.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
9 @license: GNU GPL, see COPYING for details.
abe498212fb8 move revert code to action/revert.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
10 """
3356
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
11 from MoinMoin import wikiutil
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
12 from MoinMoin.PageEditor import PageEditor
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
13 from MoinMoin.action import ActionBase
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
14
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
15 class revert(ActionBase):
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
16 """ revert page action
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
17
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
18 Note: the action name is the class name
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
19 """
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
20 def __init__(self, pagename, request):
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
21 ActionBase.__init__(self, pagename, request)
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
22 self.use_ticket = True
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
23 _ = self._
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
24 self.form_trigger = 'revert'
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
25 self.form_trigger_label = _('Revert')
3357
bb04265ce89a fix revert action. I suck.
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3356
diff changeset
26 self.method = 'POST'
3356
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
27
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
28 def is_allowed(self):
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
29 # this is not strictly necessary because the underlying storage code checks
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
30 # as well
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
31 _ = self._
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
32 may = self.request.user.may
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
33 allowed = may.write(self.pagename) and may.delete(self.pagename)
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
34 return allowed, _('You are not allowed to revert this page!')
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
35
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
36 def check_condition(self):
3374
043689a3b04c action.revert: fixed doc string
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3373
diff changeset
37 """ checks valid page and rev """
3356
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
38 _ = self._
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
39 if not self.request.rev:
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
40 # same string as in PageEditor...
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
41 note = _('You were viewing the current revision of this page when you called the revert action. '
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
42 'If you want to revert to an older revision, first view that older revision and '
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
43 'then call revert to this (older) revision again.')
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
44 return note
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
45
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
46 if not self.page.exists():
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
47 return _('This page is already deleted or was never created!')
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
48 else:
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
49 return None
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
50
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
51 def do_action(self):
3374
043689a3b04c action.revert: fixed doc string
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3373
diff changeset
52 """ revert pagename """
3373
c20aa5b0158e action.revert: reverted to bb04265ce89a
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3367
diff changeset
53 form = self.form
c20aa5b0158e action.revert: reverted to bb04265ce89a
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3367
diff changeset
54 comment = form.get('comment', [u''])[0]
c20aa5b0158e action.revert: reverted to bb04265ce89a
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3367
diff changeset
55 comment = wikiutil.clean_input(comment)
3356
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
56
3357
bb04265ce89a fix revert action. I suck.
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3356
diff changeset
57 if self.request.request_method != 'POST':
3356
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
58 return False, u''
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
59
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
60 rev = self.request.rev
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
61 pg = PageEditor(self.request, self.pagename)
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
62
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
63 try:
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
64 msg = pg.revertPage(rev, comment)
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
65 # make it show the current version...
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
66 self.request.rev = None
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
67 except PageEditor.RevertError, error:
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
68 msg = unicode(error)
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
69 except PageEditor.Unchanged, error:
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
70 msg = unicode(error)
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
71
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
72 return True, msg
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
73
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
74 def get_form_html(self, buttons_html):
3374
043689a3b04c action.revert: fixed doc string
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3373
diff changeset
75 """ creates the form """
3356
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
76 _ = self._
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
77
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
78 d = {
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
79 'pagename': self.pagename,
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
80 'comment_label': _("Optional reason for reverting this page"),
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
81 'buttons_html': buttons_html,
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
82 'querytext': _('Really revert this page?'),
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
83 'rev': self.request.rev
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
84 }
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
85
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
86 return '''
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
87 <strong>%(querytext)s</strong>
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
88 <table>
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
89 <tr>
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
90 <td class="label"><label>%(comment_label)s</label></td>
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
91 <td class="content">
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
92 <input type="text" name="comment" size="80" maxlength="200">
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
93 <input type="hidden" name="rev" value="%(rev)d">
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
94 </td>
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
95 </tr>
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
96 <tr>
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
97 <td></td>
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
98 <td class="buttons">
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
99 %(buttons_html)s
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
100 </td>
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
101 </tr>
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
102 </table>
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
103 ''' % d
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
104
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
105
1104
abe498212fb8 move revert code to action/revert.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
106
abe498212fb8 move revert code to action/revert.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
107 def execute(pagename, request):
3356
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
108 """ Glue code for actions """
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
109 revert(pagename, request).render()