annotate MoinMoin/action/revert.py @ 3357:bb04265ce89a

fix revert action. I suck.
author Johannes Berg <johannes AT sipsolutions DOT net>
date Thu, 20 Mar 2008 16:31:10 +0100
parents 2dd4904cfee4
children 80ecec6e008b
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):
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
37 _ = self._
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
38 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
39 # 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
40 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
41 '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
42 '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
43 return note
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
44
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
45 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
46 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
47 else:
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
48 return None
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
49
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
50 def do_action(self):
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
51 """ Delete pagename """
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
52 form = self.form
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
53 comment = form.get('comment', [u''])[0]
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
54 comment = wikiutil.clean_input(comment)
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
55
3357
bb04265ce89a fix revert action. I suck.
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3356
diff changeset
56 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
57 return False, u''
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
58
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
59 rev = self.request.rev
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
60 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
61
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
62 try:
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
63 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
64 # 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
65 self.request.rev = None
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
66 except PageEditor.RevertError, error:
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
67 msg = unicode(error)
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
68 except PageEditor.Unchanged, error:
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
69 msg = unicode(error)
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
70
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
71 return True, msg
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
72
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
73 def get_form_html(self, buttons_html):
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
74 _ = self._
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
75
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
76 d = {
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
77 'pagename': self.pagename,
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
78 '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
79 'buttons_html': buttons_html,
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
80 '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
81 'rev': self.request.rev
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
82 }
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
83
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
84 return '''
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
85 <strong>%(querytext)s</strong>
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
86 <table>
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
87 <tr>
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
88 <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
89 <td class="content">
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
90 <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
91 <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
92 </td>
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
93 </tr>
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
94 <tr>
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
95 <td></td>
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
96 <td class="buttons">
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
97 %(buttons_html)s
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
98 </td>
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
99 </tr>
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
100 </table>
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
101 ''' % d
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
102
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
103
1104
abe498212fb8 move revert code to action/revert.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
104
abe498212fb8 move revert code to action/revert.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
105 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
106 """ Glue code for actions """
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
107 revert(pagename, request).render()