annotate data/plugin/action/RecommendPage.py @ 653:127da830be6c

updated copyright
author Reimar Bauer <rb.proj AT googlemail DOT com>
date Tue, 19 Apr 2016 16:29:54 +0200
parents 2f092fcc3999
children
rev   line source
513
438f1d16e63f action.RecommendPage: By this action one user can point another one to an usefully interesting page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
1 # -*- coding: iso-8859-1 -*-
438f1d16e63f action.RecommendPage: By this action one user can point another one to an usefully interesting page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
2 """
438f1d16e63f action.RecommendPage: By this action one user can point another one to an usefully interesting page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
3 MoinMoin - RecommendPage Action Macro
438f1d16e63f action.RecommendPage: By this action one user can point another one to an usefully interesting page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
4
438f1d16e63f action.RecommendPage: By this action one user can point another one to an usefully interesting page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
5 By this action one user can point another one to an usefully interesting page.
438f1d16e63f action.RecommendPage: By this action one user can point another one to an usefully interesting page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
6 The hint becomes written to a page named user/RecommendedPage and the user
438f1d16e63f action.RecommendPage: By this action one user can point another one to an usefully interesting page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
7 becomes subscribed to that page.
438f1d16e63f action.RecommendPage: By this action one user can point another one to an usefully interesting page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
8
653
127da830be6c updated copyright
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 648
diff changeset
9 @copyright: 2005-2016 by MoinMoin:ReimarBauer
513
438f1d16e63f action.RecommendPage: By this action one user can point another one to an usefully interesting page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
10 @license: GNU GPL, see COPYING for details.
438f1d16e63f action.RecommendPage: By this action one user can point another one to an usefully interesting page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
11 """
438f1d16e63f action.RecommendPage: By this action one user can point another one to an usefully interesting page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
12 from MoinMoin import wikiutil, user
438f1d16e63f action.RecommendPage: By this action one user can point another one to an usefully interesting page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
13 from MoinMoin.Page import Page
438f1d16e63f action.RecommendPage: By this action one user can point another one to an usefully interesting page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
14 from MoinMoin.PageEditor import PageEditor
438f1d16e63f action.RecommendPage: By this action one user can point another one to an usefully interesting page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
15
438f1d16e63f action.RecommendPage: By this action one user can point another one to an usefully interesting page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
16 def RecommendPage(request, pagename, username):
438f1d16e63f action.RecommendPage: By this action one user can point another one to an usefully interesting page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
17 err = None
438f1d16e63f action.RecommendPage: By this action one user can point another one to an usefully interesting page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
18 name = "%(username)s/RecommendedPage" % {"username": username}
438f1d16e63f action.RecommendPage: By this action one user can point another one to an usefully interesting page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
19 page = PageEditor(request, name)
438f1d16e63f action.RecommendPage: By this action one user can point another one to an usefully interesting page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
20 if request.user.may.write(name):
438f1d16e63f action.RecommendPage: By this action one user can point another one to an usefully interesting page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
21 if user.getUserId(request, username) is not None:
438f1d16e63f action.RecommendPage: By this action one user can point another one to an usefully interesting page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
22 uid = user.getUserId(request, username)
438f1d16e63f action.RecommendPage: By this action one user can point another one to an usefully interesting page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
23 recom_user = user.User(request, id=uid)
438f1d16e63f action.RecommendPage: By this action one user can point another one to an usefully interesting page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
24 subscription_list = recom_user.getSubscriptionList()
438f1d16e63f action.RecommendPage: By this action one user can point another one to an usefully interesting page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
25 if name not in subscription_list:
438f1d16e63f action.RecommendPage: By this action one user can point another one to an usefully interesting page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
26 recom_user.subscribe(name)
438f1d16e63f action.RecommendPage: By this action one user can point another one to an usefully interesting page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
27 recom_user.save()
438f1d16e63f action.RecommendPage: By this action one user can point another one to an usefully interesting page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
28
438f1d16e63f action.RecommendPage: By this action one user can point another one to an usefully interesting page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
29 newtext = u" * [[%(pagename)s]] <<ShortText(%(pagename)s)>> ...\n %(username)s\n" % {
438f1d16e63f action.RecommendPage: By this action one user can point another one to an usefully interesting page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
30 "pagename": pagename,
438f1d16e63f action.RecommendPage: By this action one user can point another one to an usefully interesting page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
31 "username": "@SIG@"}
438f1d16e63f action.RecommendPage: By this action one user can point another one to an usefully interesting page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
32 if not page.exists():
438f1d16e63f action.RecommendPage: By this action one user can point another one to an usefully interesting page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
33 return True, PageEditor.saveText(page, newtext, 0)
438f1d16e63f action.RecommendPage: By this action one user can point another one to an usefully interesting page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
34 else:
438f1d16e63f action.RecommendPage: By this action one user can point another one to an usefully interesting page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
35 body = page.get_data()
438f1d16e63f action.RecommendPage: By this action one user can point another one to an usefully interesting page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
36 meta = page.get_meta()
438f1d16e63f action.RecommendPage: By this action one user can point another one to an usefully interesting page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
37 text_meta = ''
438f1d16e63f action.RecommendPage: By this action one user can point another one to an usefully interesting page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
38 for command, attrib in meta:
438f1d16e63f action.RecommendPage: By this action one user can point another one to an usefully interesting page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
39 text_meta = '#%s %s\n%s' % (command, attrib, text_meta)
438f1d16e63f action.RecommendPage: By this action one user can point another one to an usefully interesting page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
40
438f1d16e63f action.RecommendPage: By this action one user can point another one to an usefully interesting page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
41 text = "%s\n%s\n%s\n" % (text_meta, newtext, body)
438f1d16e63f action.RecommendPage: By this action one user can point another one to an usefully interesting page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
42 return True, PageEditor.saveText(page, text, 0)
438f1d16e63f action.RecommendPage: By this action one user can point another one to an usefully interesting page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
43 else:
438f1d16e63f action.RecommendPage: By this action one user can point another one to an usefully interesting page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
44 return False, "You are not allowed to edit this page."
438f1d16e63f action.RecommendPage: By this action one user can point another one to an usefully interesting page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
45
438f1d16e63f action.RecommendPage: By this action one user can point another one to an usefully interesting page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
46 def execute(pagename, request):
438f1d16e63f action.RecommendPage: By this action one user can point another one to an usefully interesting page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
47 _ = request.getText
438f1d16e63f action.RecommendPage: By this action one user can point another one to an usefully interesting page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
48 actname = __name__.split('.')[-1]
438f1d16e63f action.RecommendPage: By this action one user can point another one to an usefully interesting page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
49 thispage = Page(request, pagename)
438f1d16e63f action.RecommendPage: By this action one user can point another one to an usefully interesting page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
50 if not (request.user.valid and request.user.may.read(pagename)):
438f1d16e63f action.RecommendPage: By this action one user can point another one to an usefully interesting page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
51 msg = _("You are not allowed to do %(action_name)s on this page.") % {"action_name": actname}
438f1d16e63f action.RecommendPage: By this action one user can point another one to an usefully interesting page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
52 request.theme.add_msg(msg, "warning")
438f1d16e63f action.RecommendPage: By this action one user can point another one to an usefully interesting page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
53 return thispage.send_page()
438f1d16e63f action.RecommendPage: By this action one user can point another one to an usefully interesting page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
54
438f1d16e63f action.RecommendPage: By this action one user can point another one to an usefully interesting page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
55 if request.method == 'POST' and request.form.has_key('button'):
438f1d16e63f action.RecommendPage: By this action one user can point another one to an usefully interesting page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
56 if not wikiutil.checkTicket(request, request.form.get('ticket', '')):
438f1d16e63f action.RecommendPage: By this action one user can point another one to an usefully interesting page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
57 msg=_('Please use the interactive user interface to recommend pages!')
438f1d16e63f action.RecommendPage: By this action one user can point another one to an usefully interesting page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
58 request.theme.add_msg(msg, "warning")
438f1d16e63f action.RecommendPage: By this action one user can point another one to an usefully interesting page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
59 return thispage.send_page()
438f1d16e63f action.RecommendPage: By this action one user can point another one to an usefully interesting page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
60
438f1d16e63f action.RecommendPage: By this action one user can point another one to an usefully interesting page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
61 selected_users = request.values.getlist('username') or [request.user.name]
438f1d16e63f action.RecommendPage: By this action one user can point another one to an usefully interesting page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
62 recommendation_send_to = []
438f1d16e63f action.RecommendPage: By this action one user can point another one to an usefully interesting page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
63 for username in selected_users:
438f1d16e63f action.RecommendPage: By this action one user can point another one to an usefully interesting page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
64 status, msg = RecommendPage(request, pagename, username)
438f1d16e63f action.RecommendPage: By this action one user can point another one to an usefully interesting page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
65 if status:
438f1d16e63f action.RecommendPage: By this action one user can point another one to an usefully interesting page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
66 recommendation_send_to.append(username)
438f1d16e63f action.RecommendPage: By this action one user can point another one to an usefully interesting page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
67
438f1d16e63f action.RecommendPage: By this action one user can point another one to an usefully interesting page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
68 no_recommendation_for = set(selected_users) - set(recommendation_send_to)
438f1d16e63f action.RecommendPage: By this action one user can point another one to an usefully interesting page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
69 msg = []
438f1d16e63f action.RecommendPage: By this action one user can point another one to an usefully interesting page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
70 msg.append("recommended to read %(pagename)s for %(username)s" % {
438f1d16e63f action.RecommendPage: By this action one user can point another one to an usefully interesting page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
71 "pagename": pagename,
438f1d16e63f action.RecommendPage: By this action one user can point another one to an usefully interesting page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
72 "username": ', '.join(recommendation_send_to)})
438f1d16e63f action.RecommendPage: By this action one user can point another one to an usefully interesting page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
73 if no_recommendation_for:
438f1d16e63f action.RecommendPage: By this action one user can point another one to an usefully interesting page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
74 msg.append("You can't send a recommendation to %(username)s" % {
438f1d16e63f action.RecommendPage: By this action one user can point another one to an usefully interesting page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
75 "username": ', '.join(no_recommendation_for)})
438f1d16e63f action.RecommendPage: By this action one user can point another one to an usefully interesting page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
76
438f1d16e63f action.RecommendPage: By this action one user can point another one to an usefully interesting page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
77 request.theme.add_msg('<br>'.join(msg), "info")
438f1d16e63f action.RecommendPage: By this action one user can point another one to an usefully interesting page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
78 thispage.send_page()
438f1d16e63f action.RecommendPage: By this action one user can point another one to an usefully interesting page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
79 return
438f1d16e63f action.RecommendPage: By this action one user can point another one to an usefully interesting page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
80
438f1d16e63f action.RecommendPage: By this action one user can point another one to an usefully interesting page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
81 users = user.getUserList(request)
648
2f092fcc3999 macro: RecomendedPage ignore disabled user
Reimar Bauer <rb.proj@gmail.com>
parents: 513
diff changeset
82 html = ["<OPTION>%s</OPTION>" % user.User(request, id=uid).name for uid in users if not user.User(request, id=uid).disabled]
513
438f1d16e63f action.RecommendPage: By this action one user can point another one to an usefully interesting page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
83 html.sort()
438f1d16e63f action.RecommendPage: By this action one user can point another one to an usefully interesting page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
84
438f1d16e63f action.RecommendPage: By this action one user can point another one to an usefully interesting page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
85 formhtml = """
438f1d16e63f action.RecommendPage: By this action one user can point another one to an usefully interesting page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
86 <form method="post" >
438f1d16e63f action.RecommendPage: By this action one user can point another one to an usefully interesting page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
87 <strong>%(querytext)s</strong><BR>
438f1d16e63f action.RecommendPage: By this action one user can point another one to an usefully interesting page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
88 <select name="username" size="%(len)s" multiple>
438f1d16e63f action.RecommendPage: By this action one user can point another one to an usefully interesting page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
89 %(option)s
438f1d16e63f action.RecommendPage: By this action one user can point another one to an usefully interesting page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
90 </select>
438f1d16e63f action.RecommendPage: By this action one user can point another one to an usefully interesting page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
91 <input type="hidden" name="action" value="%(actname)s">
438f1d16e63f action.RecommendPage: By this action one user can point another one to an usefully interesting page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
92 <input type="submit" name="button" value="%(button)s">
438f1d16e63f action.RecommendPage: By this action one user can point another one to an usefully interesting page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
93 <br>
438f1d16e63f action.RecommendPage: By this action one user can point another one to an usefully interesting page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
94 (no selection recommends to: %(user)s)
438f1d16e63f action.RecommendPage: By this action one user can point another one to an usefully interesting page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
95 <input type="hidden" name="ticket" value="%(ticket)s">
438f1d16e63f action.RecommendPage: By this action one user can point another one to an usefully interesting page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
96 <p>
438f1d16e63f action.RecommendPage: By this action one user can point another one to an usefully interesting page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
97 </form>""" % {
438f1d16e63f action.RecommendPage: By this action one user can point another one to an usefully interesting page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
98 'querytext': 'Recommend page to',
438f1d16e63f action.RecommendPage: By this action one user can point another one to an usefully interesting page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
99 'actname': 'RecommendPage',
438f1d16e63f action.RecommendPage: By this action one user can point another one to an usefully interesting page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
100 'ticket': wikiutil.createTicket(request),
438f1d16e63f action.RecommendPage: By this action one user can point another one to an usefully interesting page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
101 'option': ' '.join(html),
438f1d16e63f action.RecommendPage: By this action one user can point another one to an usefully interesting page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
102 'user': request.user.name,
438f1d16e63f action.RecommendPage: By this action one user can point another one to an usefully interesting page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
103 'len': min([3, len(html)]),
438f1d16e63f action.RecommendPage: By this action one user can point another one to an usefully interesting page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
104 'button': 'Recommend'}
438f1d16e63f action.RecommendPage: By this action one user can point another one to an usefully interesting page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
105
438f1d16e63f action.RecommendPage: By this action one user can point another one to an usefully interesting page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
106 request.theme.add_msg(formhtml, "info")
438f1d16e63f action.RecommendPage: By this action one user can point another one to an usefully interesting page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
107 thispage.send_page()
438f1d16e63f action.RecommendPage: By this action one user can point another one to an usefully interesting page.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
108 return