annotate MoinMoin/action/SubscribeUser.py @ 2489:fabbb4dbd99e

Merge devel.
author Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
date Sun, 22 Jul 2007 03:27:45 +0200
parents b902f2397c68
children 9817a90b6fde
rev   line source
66
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
1 """
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
2 MoinMoin - Subscribeuser - Action
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
3 Subscribe a user to a page
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
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: 1868
diff changeset
5 @copyright: 2003 Daniela Nicklas <nicklas@informatik.uni-stuttgart.de>,
bb2e053067fb fixing copyright headers: remove umlauts (encoding troubles), make epydoc compatible, reformat
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1868
diff changeset
6 2005 MoinMoin:AlexanderSchremmer
66
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
7 @license: GNU GPL, see COPYING for details.
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
8 """
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
9
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
10 import sys, os
474
6535fed51de5 SubscribeUser: fix: do not put silly path into pythonpath
Thomas Waldmann <tw@waldmann-edv.de>
parents: 391
diff changeset
11 #sys.path.append("YOUR CONFIG DIRECTORY HERE")
66
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
12
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
13 from MoinMoin.Page import Page
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
14 from MoinMoin import user
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
15
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
16 def show_form(pagename, request):
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
17 _ = request.getText
1068
ecece5db5288 use emit_http_headers
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 949
diff changeset
18 request.emit_http_headers()
616
3b08d9413589 move send_title/footer from wikiutil to theme.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 474
diff changeset
19 request.theme.send_title(_("Subscribe users to the page %s") % pagename, pagename=pagename)
66
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
20
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
21 request.write("""
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
22 <form action="" method="POST" enctype="multipart/form-data">
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
23 <input type="hidden" name="action" value="SubscribeUser">
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
24 Enter user names (comma separated): <input type="text" name="users" size="50">
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
25 <input type="submit" value="Subscribe">
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
26 </form>
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
27 """)
616
3b08d9413589 move send_title/footer from wikiutil to theme.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 474
diff changeset
28 request.theme.send_footer(pagename)
617
cf420addd95c removed MoinMoinNoFooter at many places, added call to theme.send_closing_html() where needed
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 616
diff changeset
29 request.theme.send_closing_html()
66
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
30
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
31 def show_result(pagename, request):
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
32 _ = request.getText
1068
ecece5db5288 use emit_http_headers
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 949
diff changeset
33 request.emit_http_headers()
66
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
34
616
3b08d9413589 move send_title/footer from wikiutil to theme.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 474
diff changeset
35 request.theme.send_title(_("Subscribed for %s:") % pagename, pagename=pagename)
66
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
36
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
37 from MoinMoin.formatter.text_html import Formatter
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
38 formatter = Formatter(request)
949
cbbde07e00c4 whitespace-only cleanup, small style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 720
diff changeset
39
66
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
40 result = subscribe_users(request, request.form['users'][0].split(","), pagename, formatter)
474
6535fed51de5 SubscribeUser: fix: do not put silly path into pythonpath
Thomas Waldmann <tw@waldmann-edv.de>
parents: 391
diff changeset
41 request.write(result)
66
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
42
616
3b08d9413589 move send_title/footer from wikiutil to theme.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 474
diff changeset
43 request.theme.send_footer(pagename)
617
cf420addd95c removed MoinMoinNoFooter at many places, added call to theme.send_closing_html() where needed
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 616
diff changeset
44 request.theme.send_closing_html()
66
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
45
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
46 def subscribe_users(request, usernamelist, pagename, formatter):
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
47 _ = request.getText
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
48
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
49 if not Page(request, pagename).exists():
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
50 return u"Page does not exist."
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
51
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
52 result = []
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
53
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
54 realusers = [] # usernames that are really wiki users
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
55
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
56 # get user object - only with IDs!
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
57 for userid in user.getUserList(request):
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
58 success = False
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
59 userobj = user.User(request, userid)
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
60
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
61 if userobj.name in usernamelist: # found a user
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
62 realusers.append(userobj.name)
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
63 if userobj.isSubscribedTo([pagename]):
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
64 success = True
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
65 elif not userobj.email:
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
66 success = False
90
246601c7b298 fix unsubscribe, use always valid interwiki links, more correct error messages, refactror subscribePage, isSubscribedTo
Nir Soffer <nirs@freeshell.org>
parents: 66
diff changeset
67 elif userobj.subscribe(pagename):
66
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
68 success = True
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
69 if success:
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
70 result.append(formatter.smiley('{OK}'))
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
71 result.append(formatter.text(" "))
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
72 else:
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
73 result.append(formatter.smiley('{X}'))
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
74 result.append(formatter.text(" "))
1816
4a31739bc6e1 Page.url(): removed escaping support
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1791
diff changeset
75 result.append(formatter.url(1, Page(request, userobj.name).url(request)))
66
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
76 result.append(formatter.text(userobj.name))
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
77 result.append(formatter.url(0))
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
78 result.append(formatter.linebreak(preformatted=0))
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
79
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
80 result.extend([''.join([formatter.smiley('{X}'), formatter.text(" " + _("Not a user:") + " " + username), formatter.linebreak(preformatted=0)]) for username in usernamelist if username not in realusers])
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
81
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
82 return ''.join(result)
949
cbbde07e00c4 whitespace-only cleanup, small style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 720
diff changeset
83
66
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
84 def execute(pagename, request):
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
85 _ = request.getText
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
86 if not request.user.may.admin(pagename):
720
7fc5e2c11a0e use send_page / msg in SubscribeUser
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 640
diff changeset
87 thispage = Page(request, pagename)
1777
ed44b93599b5 remove unneeded request param from page.send_page()
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1339
diff changeset
88 return thispage.send_page(msg=_("You are not allowed to perform this action."))
1868
64507f46beb2 reduce usage of has_key()
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1816
diff changeset
89 elif 'users' not in request.form:
66
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
90 show_form(pagename, request)
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
91 else:
949
cbbde07e00c4 whitespace-only cleanup, small style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 720
diff changeset
92 show_result(pagename, request)
66
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
93
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
94 if __name__ == '__main__':
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
95 args = sys.argv
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
96 if not len(args) > 1:
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
97 print >>sys.stderr, """Subscribe users
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
98
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
99 %(myname)s pagename username[,username[,username[,...]]] [URL]
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
100
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
101 Subscribes the users to a page.
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
102 URL is just needed for a farmconfig scenario.
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
103
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
104 Example:
105
9ad707f6b4e2 Removed reference to an evil dictator.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 90
diff changeset
105 %(myname)s FrontPage TestUser,MatthewSimpson
66
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
106
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
107 """ % {"myname": os.path.basename(args[0])}
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
108 raise SystemExit
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
109
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
110 pagename = args[1]
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
111 usernames = args[2]
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
112
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
113 if len(args) > 3:
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
114 request_url = args[3]
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
115 else:
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
116 request_url = "localhost/"
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
117
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
118 # Setup MoinMoin environment
2338
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1918
diff changeset
119 from MoinMoin.request import request_cli
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1918
diff changeset
120 request = request_cli.Request(url=request_url)
66
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
121 request.form = request.args = request.setup_args()
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
122
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
123 from MoinMoin.formatter.text_plain import Formatter
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
124 formatter = Formatter(request)
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
125
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
126 print subscribe_users(request, usernames.split(","), pagename, formatter)
474
6535fed51de5 SubscribeUser: fix: do not put silly path into pythonpath
Thomas Waldmann <tw@waldmann-edv.de>
parents: 391
diff changeset
127