annotate MoinMoin/action/SubscribeUser.py @ 1068:ecece5db5288

use emit_http_headers
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Thu, 27 Jul 2006 01:18:14 +0200
parents cbbde07e00c4
children 544b931cd965
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
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
5 @copyright: Daniela Nicklas <nicklas@informatik.uni-stuttgart.de>, 2003
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
6 @copyright: 2005 MoinMoin:AlexanderSchremmer
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
7
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
8 @license: GNU GPL, see COPYING for details.
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
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
11 import sys, os
474
6535fed51de5 SubscribeUser: fix: do not put silly path into pythonpath
Thomas Waldmann <tw@waldmann-edv.de>
parents: 391
diff changeset
12 #sys.path.append("YOUR CONFIG DIRECTORY HERE")
66
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
13
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
14 from MoinMoin import wikiutil
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
15 from MoinMoin.Page import Page
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
16 from MoinMoin import user
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
17
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
18 def show_form(pagename, request):
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
19 _ = request.getText
1068
ecece5db5288 use emit_http_headers
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 949
diff changeset
20 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
21 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
22
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
23 request.write("""
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
24 <form action="" method="POST" enctype="multipart/form-data">
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
25 <input type="hidden" name="action" value="SubscribeUser">
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
26 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
27 <input type="submit" value="Subscribe">
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
28 </form>
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
29 """)
616
3b08d9413589 move send_title/footer from wikiutil to theme.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 474
diff changeset
30 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
31 request.theme.send_closing_html()
66
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
32
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
33 def show_result(pagename, request):
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
34 _ = request.getText
1068
ecece5db5288 use emit_http_headers
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 949
diff changeset
35 request.emit_http_headers()
66
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
36
616
3b08d9413589 move send_title/footer from wikiutil to theme.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 474
diff changeset
37 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
38
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
39 from MoinMoin.formatter.text_html import Formatter
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
40 formatter = Formatter(request)
949
cbbde07e00c4 whitespace-only cleanup, small style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 720
diff changeset
41
66
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
42 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
43 request.write(result)
66
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
44
616
3b08d9413589 move send_title/footer from wikiutil to theme.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 474
diff changeset
45 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
46 request.theme.send_closing_html()
66
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
47
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
48 def subscribe_users(request, usernamelist, pagename, formatter):
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
49 _ = request.getText
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
50
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
51 if not Page(request, pagename).exists():
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
52 return u"Page does not exist."
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 result = []
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 realusers = [] # usernames that are really wiki users
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
57
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
58 # get user object - only with IDs!
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
59 for userid in user.getUserList(request):
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
60 success = False
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
61 userobj = user.User(request, userid)
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
62
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
63 if userobj.name in usernamelist: # found a user
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
64 realusers.append(userobj.name)
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
65 if userobj.isSubscribedTo([pagename]):
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
66 success = True
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
67 elif not userobj.email:
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
68 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
69 elif userobj.subscribe(pagename):
66
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
70 success = True
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
71 if success:
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
72 result.append(formatter.smiley('{OK}'))
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
73 result.append(formatter.text(" "))
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
74 else:
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
75 result.append(formatter.smiley('{X}'))
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
76 result.append(formatter.text(" "))
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
77 result.append(formatter.url(1, Page(request, userobj.name).url(request)))
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
78 result.append(formatter.text(userobj.name))
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
79 result.append(formatter.url(0))
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
80 result.append(formatter.linebreak(preformatted=0))
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 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
83
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
84 return ''.join(result)
949
cbbde07e00c4 whitespace-only cleanup, small style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 720
diff changeset
85
66
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
86 def execute(pagename, request):
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
87 _ = request.getText
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
88 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
89 thispage = Page(request, pagename)
7fc5e2c11a0e use send_page / msg in SubscribeUser
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 640
diff changeset
90 return thispage.send_page(request, msg=_("You are not allowed to perform this action."))
66
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
91 elif not request.form.has_key('users'):
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
92 show_form(pagename, request)
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
93 else:
949
cbbde07e00c4 whitespace-only cleanup, small style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 720
diff changeset
94 show_result(pagename, request)
66
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
95
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
96 if __name__ == '__main__':
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
97 args = sys.argv
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
98 if not len(args) > 1:
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
99 print >>sys.stderr, """Subscribe users
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 %(myname)s pagename username[,username[,username[,...]]] [URL]
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
102
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
103 Subscribes the users to a page.
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
104 URL is just needed for a farmconfig scenario.
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
105
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
106 Example:
105
9ad707f6b4e2 Removed reference to an evil dictator.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 90
diff changeset
107 %(myname)s FrontPage TestUser,MatthewSimpson
66
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
108
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
109 """ % {"myname": os.path.basename(args[0])}
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
110 raise SystemExit
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
111
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
112 pagename = args[1]
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
113 usernames = args[2]
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
114
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
115 if len(args) > 3:
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
116 request_url = args[3]
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
117 else:
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
118 request_url = "localhost/"
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
119
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
120 # Setup MoinMoin environment
640
80d0ad85a2d8 splitted request.py into request/*, please help fixing/testing, see CHANGES
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 617
diff changeset
121 from MoinMoin.request import CLI
80d0ad85a2d8 splitted request.py into request/*, please help fixing/testing, see CHANGES
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 617
diff changeset
122 request = CLI.Request(url=request_url)
66
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
123 request.form = request.args = request.setup_args()
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
124
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
125 from MoinMoin.formatter.text_plain import Formatter
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
126 formatter = Formatter(request)
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
127
20993d3996e9 Added SubscribeUser.py action.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
diff changeset
128 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
129