annotate MoinMoin/action/revert.py @ 2333:88c539512520

s/page_edit/notify
author Karol Nowak <grzywacz@sul.uni.lodz.pl>
date Wed, 27 Jun 2007 13:25:40 +0200
parents 38f4f0311a98
children 10be78f1fa97
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>,
bb2e053067fb fixing copyright headers: remove umlauts (encoding troubles), make epydoc compatible, reformat
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1881
diff changeset
6 2006 MoinMoin:ThomasWaldmann
1104
abe498212fb8 move revert code to action/revert.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
7 @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
8 """
abe498212fb8 move revert code to action/revert.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
9 from MoinMoin.Page import Page
abe498212fb8 move revert code to action/revert.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
10
abe498212fb8 move revert code to action/revert.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
11 def execute(pagename, request):
abe498212fb8 move revert code to action/revert.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
12 """ restore another revision of a page as a new current revision """
abe498212fb8 move revert code to action/revert.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
13 from MoinMoin.PageEditor import PageEditor
abe498212fb8 move revert code to action/revert.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
14 _ = request.getText
1861
d7812ed6da4c fix revert action bug when called for current revision
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1777
diff changeset
15 msg = None
d7812ed6da4c fix revert action bug when called for current revision
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1777
diff changeset
16 rev = request.rev
d7812ed6da4c fix revert action bug when called for current revision
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1777
diff changeset
17 pg = Page(request, pagename, rev=rev)
1104
abe498212fb8 move revert code to action/revert.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
18
abe498212fb8 move revert code to action/revert.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
19 if not request.user.may.revert(pagename):
1861
d7812ed6da4c fix revert action bug when called for current revision
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1777
diff changeset
20 msg = _('You are not allowed to revert this page!')
d7812ed6da4c fix revert action bug when called for current revision
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1777
diff changeset
21 elif rev is None:
d7812ed6da4c fix revert action bug when called for current revision
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1777
diff changeset
22 msg = _('You were viewing the current revision of this page when you called the revert action. '
d7812ed6da4c fix revert action bug when called for current revision
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1777
diff changeset
23 'If you want to revert to an older revision, first view that older revision and '
d7812ed6da4c fix revert action bug when called for current revision
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1777
diff changeset
24 'then call revert to this (older) revision again.')
d7812ed6da4c fix revert action bug when called for current revision
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1777
diff changeset
25 else:
d7812ed6da4c fix revert action bug when called for current revision
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1777
diff changeset
26 newpg = PageEditor(request, pagename)
1881
f96a8fa611e8 revert:cache refreshed
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1861
diff changeset
27
1861
d7812ed6da4c fix revert action bug when called for current revision
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1777
diff changeset
28 revstr = '%08d' % rev
d7812ed6da4c fix revert action bug when called for current revision
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1777
diff changeset
29 try:
2333
88c539512520 s/page_edit/notify
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2330
diff changeset
30 msg = newpg.saveText(pg.get_raw_body(), 0, extra=revstr, action="SAVE/REVERT", notify=False)
1861
d7812ed6da4c fix revert action bug when called for current revision
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1777
diff changeset
31 pg = newpg
d7812ed6da4c fix revert action bug when called for current revision
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1777
diff changeset
32 except newpg.SaveError, msg:
d7812ed6da4c fix revert action bug when called for current revision
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1777
diff changeset
33 msg = unicode(msg)
d7812ed6da4c fix revert action bug when called for current revision
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1777
diff changeset
34 request.reset()
1881
f96a8fa611e8 revert:cache refreshed
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1861
diff changeset
35
f96a8fa611e8 revert:cache refreshed
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1861
diff changeset
36 key = request.form.get('key', ['text_html'])[0]
f96a8fa611e8 revert:cache refreshed
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1861
diff changeset
37
f96a8fa611e8 revert:cache refreshed
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1861
diff changeset
38 # Remove cache entry (if exists)
f96a8fa611e8 revert:cache refreshed
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1861
diff changeset
39 pg = Page(request, pagename)
f96a8fa611e8 revert:cache refreshed
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1861
diff changeset
40 from MoinMoin import caching
f96a8fa611e8 revert:cache refreshed
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1861
diff changeset
41 caching.CacheEntry(request, pg, key, scope='item').remove()
f96a8fa611e8 revert:cache refreshed
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1861
diff changeset
42 caching.CacheEntry(request, pg, "pagelinks", scope='item').remove()
2065
23d90aae61b5 Send events when an user subscribes to a page and when page gets reverted.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 1918
diff changeset
43
23d90aae61b5 Send events when an user subscribes to a page and when page gets reverted.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 1918
diff changeset
44 # Notify observers
23d90aae61b5 Send events when an user subscribes to a page and when page gets reverted.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 1918
diff changeset
45 from MoinMoin.events import PageRevertedEvent, send_event
23d90aae61b5 Send events when an user subscribes to a page and when page gets reverted.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 1918
diff changeset
46 e = PageRevertedEvent(request, pagename, request.rev, revstr)
23d90aae61b5 Send events when an user subscribes to a page and when page gets reverted.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 1918
diff changeset
47 send_event(e)
1881
f96a8fa611e8 revert:cache refreshed
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1861
diff changeset
48
1861
d7812ed6da4c fix revert action bug when called for current revision
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1777
diff changeset
49 pg.send_page(msg=msg)