annotate MoinMoin/events/notification.py @ 2693:dde1f1ee1d80

Always add page name to results dict.
author Karol Nowak <grzywacz@sul.uni.lodz.pl>
date Fri, 17 Aug 2007 23:28:17 +0200
parents da94375a625c
children 80cf17344f98
rev   line source
2074
088edb461832 Use the same logic to generate email and jabber notifications. Both are easily
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
1 # -*- coding: iso-8859-1 -*-
088edb461832 Use the same logic to generate email and jabber notifications. Both are easily
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
2 """
088edb461832 Use the same logic to generate email and jabber notifications. Both are easily
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
3 MoinMoin - common functions for notification framework
088edb461832 Use the same logic to generate email and jabber notifications. Both are easily
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
4
088edb461832 Use the same logic to generate email and jabber notifications. Both are easily
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
5 Code for building messages informing about events (changes)
088edb461832 Use the same logic to generate email and jabber notifications. Both are easily
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
6 happening in the wiki.
088edb461832 Use the same logic to generate email and jabber notifications. Both are easily
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
7
088edb461832 Use the same logic to generate email and jabber notifications. Both are easily
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
8 @copyright: 2007 by Karol Nowak <grywacz@gmail.com>
088edb461832 Use the same logic to generate email and jabber notifications. Both are easily
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
9 @license: GNU GPL, see COPYING for details.
088edb461832 Use the same logic to generate email and jabber notifications. Both are easily
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
10 """
088edb461832 Use the same logic to generate email and jabber notifications. Both are easily
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
11
2356
1d60f9aa07d1 Email notification about new attachments. Some i18n issues left to be fixed.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2354
diff changeset
12 import MoinMoin.user
2074
088edb461832 Use the same logic to generate email and jabber notifications. Both are easily
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
13 from MoinMoin import user, wikiutil
088edb461832 Use the same logic to generate email and jabber notifications. Both are easily
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
14 from MoinMoin.Page import Page
2320
55196f5e7000 messages.py -> notification.py; a broken commit
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
15 from MoinMoin.events import EventResult
55196f5e7000 messages.py -> notification.py; a broken commit
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
16
55196f5e7000 messages.py -> notification.py; a broken commit
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
17 class Result(EventResult):
55196f5e7000 messages.py -> notification.py; a broken commit
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
18 """ A base class for results of notification handlers"""
55196f5e7000 messages.py -> notification.py; a broken commit
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
19 pass
55196f5e7000 messages.py -> notification.py; a broken commit
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
20
55196f5e7000 messages.py -> notification.py; a broken commit
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
21 class Failure(Result):
55196f5e7000 messages.py -> notification.py; a broken commit
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
22 """ Used to report a failure in sending notifications """
55196f5e7000 messages.py -> notification.py; a broken commit
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
23 def __init__(self, reason, recipients = None):
55196f5e7000 messages.py -> notification.py; a broken commit
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
24 """
55196f5e7000 messages.py -> notification.py; a broken commit
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
25 @param recipients: a set of recipients
55196f5e7000 messages.py -> notification.py; a broken commit
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
26 @type recipients: set
55196f5e7000 messages.py -> notification.py; a broken commit
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
27 """
55196f5e7000 messages.py -> notification.py; a broken commit
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
28 self.reason = reason
55196f5e7000 messages.py -> notification.py; a broken commit
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
29 self.recipient = None
2336
10be78f1fa97 Merge main.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2329
diff changeset
30
2320
55196f5e7000 messages.py -> notification.py; a broken commit
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
31 def __str__(self):
55196f5e7000 messages.py -> notification.py; a broken commit
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
32 return self.reason or u""
2336
10be78f1fa97 Merge main.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2329
diff changeset
33
2320
55196f5e7000 messages.py -> notification.py; a broken commit
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
34
55196f5e7000 messages.py -> notification.py; a broken commit
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
35 class Success(Result):
55196f5e7000 messages.py -> notification.py; a broken commit
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
36 """ Used to indicate successfull notifications """
2336
10be78f1fa97 Merge main.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2329
diff changeset
37
2320
55196f5e7000 messages.py -> notification.py; a broken commit
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
38 def __init__(self, recipients):
55196f5e7000 messages.py -> notification.py; a broken commit
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
39 """
55196f5e7000 messages.py -> notification.py; a broken commit
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
40 @param recipients: a set of recipients
55196f5e7000 messages.py -> notification.py; a broken commit
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
41 @type recipients: set
55196f5e7000 messages.py -> notification.py; a broken commit
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
42 """
55196f5e7000 messages.py -> notification.py; a broken commit
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
43 self.recipients = recipients
2074
088edb461832 Use the same logic to generate email and jabber notifications. Both are easily
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
44
2505
0a90c1bad60f Again, some fixes suggested by pylint.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2426
diff changeset
45 class UnknownChangeType(Exception):
2320
55196f5e7000 messages.py -> notification.py; a broken commit
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
46 """ Used to signal an invalid page change event """
2111
a3377b242e21 First try to reduce code duplication. More tomorrow after some sleep...
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2109
diff changeset
47 pass
2074
088edb461832 Use the same logic to generate email and jabber notifications. Both are easily
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
48
2638
6e84127a1860 Finally all known bugs fixed, OOB is used to send links with jabber. More...
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2633
diff changeset
49 def page_link(request, page, querystr):
6e84127a1860 Finally all known bugs fixed, OOB is used to send links with jabber. More...
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2633
diff changeset
50 """Create an absolute url to a given page with optional action
6e84127a1860 Finally all known bugs fixed, OOB is used to send links with jabber. More...
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2633
diff changeset
51
6e84127a1860 Finally all known bugs fixed, OOB is used to send links with jabber. More...
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2633
diff changeset
52 @param page: a page to link to
6e84127a1860 Finally all known bugs fixed, OOB is used to send links with jabber. More...
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2633
diff changeset
53 @type page: MoinMoin.Page.Page
6e84127a1860 Finally all known bugs fixed, OOB is used to send links with jabber. More...
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2633
diff changeset
54 @param querystr: a dict passed to wikiutil.makeQueryString
6e84127a1860 Finally all known bugs fixed, OOB is used to send links with jabber. More...
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2633
diff changeset
55
6e84127a1860 Finally all known bugs fixed, OOB is used to send links with jabber. More...
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2633
diff changeset
56 """
6e84127a1860 Finally all known bugs fixed, OOB is used to send links with jabber. More...
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2633
diff changeset
57 query = wikiutil.makeQueryString(querystr, True)
6e84127a1860 Finally all known bugs fixed, OOB is used to send links with jabber. More...
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2633
diff changeset
58 return request.getQualifiedURL(page.url(request, query, relative=False))
6e84127a1860 Finally all known bugs fixed, OOB is used to send links with jabber. More...
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2633
diff changeset
59
2116
7f579f5fd44b Improve docstrings. s/type/msgtype/ to avoid name conflict with builtin.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2113
diff changeset
60 def page_change_message(msgtype, request, page, lang, **kwargs):
7f579f5fd44b Improve docstrings. s/type/msgtype/ to avoid name conflict with builtin.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2113
diff changeset
61 """Prepare a notification text for a page change of given type
2337
1d85514968a2 Fix remaining excessive white space characters.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
62
2688
da94375a625c Towards full data forms support. Not finished, probably broken. Don't merge.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2638
diff changeset
63 @param msgtype: a type of message to send (page_changed, page_renamed, ...)
2116
7f579f5fd44b Improve docstrings. s/type/msgtype/ to avoid name conflict with builtin.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2113
diff changeset
64 @type msgtype: str or unicode
7f579f5fd44b Improve docstrings. s/type/msgtype/ to avoid name conflict with builtin.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2113
diff changeset
65 @param **kwargs: a dictionary of additional parameters, which depend on msgtype
2337
1d85514968a2 Fix remaining excessive white space characters.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
66
2688
da94375a625c Towards full data forms support. Not finished, probably broken. Don't merge.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2638
diff changeset
67 @return: dictionary containing data about the changed page
da94375a625c Towards full data forms support. Not finished, probably broken. Don't merge.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2638
diff changeset
68 @rtype: dict
2337
1d85514968a2 Fix remaining excessive white space characters.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
69
2116
7f579f5fd44b Improve docstrings. s/type/msgtype/ to avoid name conflict with builtin.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2113
diff changeset
70 """
2320
55196f5e7000 messages.py -> notification.py; a broken commit
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
71 from MoinMoin.action.AttachFile import getAttachUrl
2337
1d85514968a2 Fix remaining excessive white space characters.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
72
2074
088edb461832 Use the same logic to generate email and jabber notifications. Both are easily
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
73 _ = request.getText
088edb461832 Use the same logic to generate email and jabber notifications. Both are easily
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
74 page._ = lambda s, formatted=True, r=request, l=lang: r.getText(s, formatted=formatted, lang=l)
2111
a3377b242e21 First try to reduce code duplication. More tomorrow after some sleep...
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2109
diff changeset
75 querystr = {}
2693
dde1f1ee1d80 Always add page name to results dict.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2688
diff changeset
76 changes = {'page_name': page.page_name}
2337
1d85514968a2 Fix remaining excessive white space characters.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
77
1d85514968a2 Fix remaining excessive white space characters.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
78 if msgtype == "page_changed":
2111
a3377b242e21 First try to reduce code duplication. More tomorrow after some sleep...
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2109
diff changeset
79 revisions = kwargs['revisions']
a3377b242e21 First try to reduce code duplication. More tomorrow after some sleep...
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2109
diff changeset
80 if len(kwargs['revisions']) >= 2:
a3377b242e21 First try to reduce code duplication. More tomorrow after some sleep...
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2109
diff changeset
81 querystr = {'action': 'diff',
2074
088edb461832 Use the same logic to generate email and jabber notifications. Both are easily
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
82 'rev2': str(revisions[0]),
088edb461832 Use the same logic to generate email and jabber notifications. Both are easily
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
83 'rev1': str(revisions[1])}
2337
1d85514968a2 Fix remaining excessive white space characters.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
84
2638
6e84127a1860 Finally all known bugs fixed, OOB is used to send links with jabber. More...
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2633
diff changeset
85 pagelink = page_link(request, page, querystr)
2337
1d85514968a2 Fix remaining excessive white space characters.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
86
2116
7f579f5fd44b Improve docstrings. s/type/msgtype/ to avoid name conflict with builtin.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2113
diff changeset
87 if msgtype == "page_changed":
2688
da94375a625c Towards full data forms support. Not finished, probably broken. Don't merge.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2638
diff changeset
88 changes['text'] = _("Dear Wiki user,\n\n"
2074
088edb461832 Use the same logic to generate email and jabber notifications. Both are easily
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
89 'You have subscribed to a wiki page or wiki category on "%(sitename)s" for change notification.\n\n'
2638
6e84127a1860 Finally all known bugs fixed, OOB is used to send links with jabber. More...
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2633
diff changeset
90 'The "%(pagename)s" page has been changed by %(editor)s:\n\n', formatted=False) % {
6e84127a1860 Finally all known bugs fixed, OOB is used to send links with jabber. More...
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2633
diff changeset
91 'pagename': page.page_name,
2074
088edb461832 Use the same logic to generate email and jabber notifications. Both are easily
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
92 'editor': page.uid_override or user.getUserIdentification(request),
088edb461832 Use the same logic to generate email and jabber notifications. Both are easily
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
93 'sitename': page.cfg.sitename or request.getBaseURL(),
2111
a3377b242e21 First try to reduce code duplication. More tomorrow after some sleep...
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2109
diff changeset
94 }
2337
1d85514968a2 Fix remaining excessive white space characters.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
95
2111
a3377b242e21 First try to reduce code duplication. More tomorrow after some sleep...
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2109
diff changeset
96 # append a diff (or append full page text if there is no diff)
a3377b242e21 First try to reduce code duplication. More tomorrow after some sleep...
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2109
diff changeset
97 if len(revisions) < 2:
2688
da94375a625c Towards full data forms support. Not finished, probably broken. Don't merge.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2638
diff changeset
98 changes['diff'] = _("New page:\n", formatted=False) + page.get_raw_body()
2111
a3377b242e21 First try to reduce code duplication. More tomorrow after some sleep...
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2109
diff changeset
99 else:
a3377b242e21 First try to reduce code duplication. More tomorrow after some sleep...
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2109
diff changeset
100 lines = wikiutil.pagediff(request, page.page_name, revisions[1],
a3377b242e21 First try to reduce code duplication. More tomorrow after some sleep...
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2109
diff changeset
101 page.page_name, revisions[0])
a3377b242e21 First try to reduce code duplication. More tomorrow after some sleep...
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2109
diff changeset
102 if lines:
2688
da94375a625c Towards full data forms support. Not finished, probably broken. Don't merge.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2638
diff changeset
103 changes['diff'] = '\n'.join(lines)
2111
a3377b242e21 First try to reduce code duplication. More tomorrow after some sleep...
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2109
diff changeset
104 else:
2688
da94375a625c Towards full data forms support. Not finished, probably broken. Don't merge.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2638
diff changeset
105 changes['diff'] = _("No differences found!\n", formatted=False)
2337
1d85514968a2 Fix remaining excessive white space characters.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
106
2116
7f579f5fd44b Improve docstrings. s/type/msgtype/ to avoid name conflict with builtin.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2113
diff changeset
107 elif msgtype == "page_deleted":
2688
da94375a625c Towards full data forms support. Not finished, probably broken. Don't merge.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2638
diff changeset
108 changes['text'] = _("Dear wiki user,\n\n"
2111
a3377b242e21 First try to reduce code duplication. More tomorrow after some sleep...
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2109
diff changeset
109 'You have subscribed to a wiki page "%(sitename)s" for change notification.\n\n'
2688
da94375a625c Towards full data forms support. Not finished, probably broken. Don't merge.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2638
diff changeset
110 'The page "%(pagename)s" has been deleted by %(editor)s:\n\n', formatted=False) % {
2638
6e84127a1860 Finally all known bugs fixed, OOB is used to send links with jabber. More...
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2633
diff changeset
111 'pagename': page.page_name,
2111
a3377b242e21 First try to reduce code duplication. More tomorrow after some sleep...
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2109
diff changeset
112 'editor': page.uid_override or user.getUserIdentification(request),
a3377b242e21 First try to reduce code duplication. More tomorrow after some sleep...
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2109
diff changeset
113 'sitename': page.cfg.sitename or request.getBaseURL(),
a3377b242e21 First try to reduce code duplication. More tomorrow after some sleep...
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2109
diff changeset
114 }
2337
1d85514968a2 Fix remaining excessive white space characters.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
115
2329
9a71ea0c941b Add support for PageRenamed event. Not tested yet.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2321
diff changeset
116 elif msgtype == "page_renamed":
2688
da94375a625c Towards full data forms support. Not finished, probably broken. Don't merge.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2638
diff changeset
117 changes['text'] = _("Dear wiki user,\n\n"
2329
9a71ea0c941b Add support for PageRenamed event. Not tested yet.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2321
diff changeset
118 'You have subscribed to a wiki page "%(sitename)s" for change notification.\n\n'
2688
da94375a625c Towards full data forms support. Not finished, probably broken. Don't merge.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2638
diff changeset
119 'The page "%(pagename)s" has been renamed from "%(oldname)s" by %(editor)s:\n',
2638
6e84127a1860 Finally all known bugs fixed, OOB is used to send links with jabber. More...
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2633
diff changeset
120 formatted=False) % {
2329
9a71ea0c941b Add support for PageRenamed event. Not tested yet.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2321
diff changeset
121 'editor': page.uid_override or user.getUserIdentification(request),
2638
6e84127a1860 Finally all known bugs fixed, OOB is used to send links with jabber. More...
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2633
diff changeset
122 'pagename': page.page_name,
2329
9a71ea0c941b Add support for PageRenamed event. Not tested yet.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2321
diff changeset
123 'sitename': page.cfg.sitename or request.getBaseURL(),
9a71ea0c941b Add support for PageRenamed event. Not tested yet.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2321
diff changeset
124 'oldname': kwargs['old_name']
9a71ea0c941b Add support for PageRenamed event. Not tested yet.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2321
diff changeset
125 }
2688
da94375a625c Towards full data forms support. Not finished, probably broken. Don't merge.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2638
diff changeset
126
da94375a625c Towards full data forms support. Not finished, probably broken. Don't merge.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2638
diff changeset
127 changes['old_name'] = kwargs['old_name']
da94375a625c Towards full data forms support. Not finished, probably broken. Don't merge.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2638
diff changeset
128
2111
a3377b242e21 First try to reduce code duplication. More tomorrow after some sleep...
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2109
diff changeset
129 else:
a3377b242e21 First try to reduce code duplication. More tomorrow after some sleep...
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2109
diff changeset
130 raise UnknownChangeType()
2337
1d85514968a2 Fix remaining excessive white space characters.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
131
2688
da94375a625c Towards full data forms support. Not finished, probably broken. Don't merge.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2638
diff changeset
132 changes['editor'] = page.uid_override or user.getUserIdentification(request)
2356
1d60f9aa07d1 Email notification about new attachments. Some i18n issues left to be fixed.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2354
diff changeset
133 if 'comment' in kwargs and kwargs['comment']:
2688
da94375a625c Towards full data forms support. Not finished, probably broken. Don't merge.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2638
diff changeset
134 changes['comment'] = kwargs['comment']
2337
1d85514968a2 Fix remaining excessive white space characters.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
135
2688
da94375a625c Towards full data forms support. Not finished, probably broken. Don't merge.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2638
diff changeset
136 return changes
2337
1d85514968a2 Fix remaining excessive white space characters.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
137
2356
1d60f9aa07d1 Email notification about new attachments. Some i18n issues left to be fixed.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2354
diff changeset
138 def user_created_message(request, sitename, username, email):
1d60f9aa07d1 Email notification about new attachments. Some i18n issues left to be fixed.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2354
diff changeset
139 """Formats a message used to notify about accounts being created
1d60f9aa07d1 Email notification about new attachments. Some i18n issues left to be fixed.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2354
diff changeset
140
1d60f9aa07d1 Email notification about new attachments. Some i18n issues left to be fixed.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2354
diff changeset
141 @return: a dict containing message body and subject
1d60f9aa07d1 Email notification about new attachments. Some i18n issues left to be fixed.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2354
diff changeset
142 """
1d60f9aa07d1 Email notification about new attachments. Some i18n issues left to be fixed.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2354
diff changeset
143 _ = request.getText
2354
ebc8fc2a482a Add user_created_message() to share some code. Some fixes to support subjects.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2337
diff changeset
144 subject = _("New user account created on %(sitename)s") % {'sitename': sitename or "Wiki"}
ebc8fc2a482a Add user_created_message() to share some code. Some fixes to support subjects.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2337
diff changeset
145 body = _("""Dear Superuser, a new user has just been created. Details follow:
2356
1d60f9aa07d1 Email notification about new attachments. Some i18n issues left to be fixed.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2354
diff changeset
146
2354
ebc8fc2a482a Add user_created_message() to share some code. Some fixes to support subjects.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2337
diff changeset
147 User name: %(username)s
ebc8fc2a482a Add user_created_message() to share some code. Some fixes to support subjects.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2337
diff changeset
148 Email address: %(useremail)s""", formatted=False) % {
ebc8fc2a482a Add user_created_message() to share some code. Some fixes to support subjects.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2337
diff changeset
149 'username': username,
ebc8fc2a482a Add user_created_message() to share some code. Some fixes to support subjects.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2337
diff changeset
150 'useremail': email,
ebc8fc2a482a Add user_created_message() to share some code. Some fixes to support subjects.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2337
diff changeset
151 }
2356
1d60f9aa07d1 Email notification about new attachments. Some i18n issues left to be fixed.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2354
diff changeset
152
2354
ebc8fc2a482a Add user_created_message() to share some code. Some fixes to support subjects.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2337
diff changeset
153 return {'subject': subject, 'body': body}
2356
1d60f9aa07d1 Email notification about new attachments. Some i18n issues left to be fixed.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2354
diff changeset
154
2638
6e84127a1860 Finally all known bugs fixed, OOB is used to send links with jabber. More...
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2633
diff changeset
155 def attachment_added(request, _, page_name, attach_name, attach_size):
2356
1d60f9aa07d1 Email notification about new attachments. Some i18n issues left to be fixed.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2354
diff changeset
156 """Formats a message used to notify about new attachments
1d60f9aa07d1 Email notification about new attachments. Some i18n issues left to be fixed.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2354
diff changeset
157
2638
6e84127a1860 Finally all known bugs fixed, OOB is used to send links with jabber. More...
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2633
diff changeset
158 @param _: a gettext function
2688
da94375a625c Towards full data forms support. Not finished, probably broken. Don't merge.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2638
diff changeset
159 @return: a dict with notification data
2356
1d60f9aa07d1 Email notification about new attachments. Some i18n issues left to be fixed.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2354
diff changeset
160
2638
6e84127a1860 Finally all known bugs fixed, OOB is used to send links with jabber. More...
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2633
diff changeset
161 """
2356
1d60f9aa07d1 Email notification about new attachments. Some i18n issues left to be fixed.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2354
diff changeset
162 page = Page(request, page_name)
2688
da94375a625c Towards full data forms support. Not finished, probably broken. Don't merge.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2638
diff changeset
163 data = {}
2356
1d60f9aa07d1 Email notification about new attachments. Some i18n issues left to be fixed.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2354
diff changeset
164
2688
da94375a625c Towards full data forms support. Not finished, probably broken. Don't merge.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2638
diff changeset
165 data['subject'] = _("New attachment added to page %(pagename)s on %(sitename)s") % {
2356
1d60f9aa07d1 Email notification about new attachments. Some i18n issues left to be fixed.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2354
diff changeset
166 'pagename': page_name,
1d60f9aa07d1 Email notification about new attachments. Some i18n issues left to be fixed.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2354
diff changeset
167 'sitename': request.cfg.sitename or request.getBaseURL(),
1d60f9aa07d1 Email notification about new attachments. Some i18n issues left to be fixed.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2354
diff changeset
168 }
1d60f9aa07d1 Email notification about new attachments. Some i18n issues left to be fixed.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2354
diff changeset
169
2688
da94375a625c Towards full data forms support. Not finished, probably broken. Don't merge.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2638
diff changeset
170 data['text'] = _("Dear Wiki user,\n\n"
2356
1d60f9aa07d1 Email notification about new attachments. Some i18n issues left to be fixed.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2354
diff changeset
171 'You have subscribed to a wiki page "%(page_name)s" for change notification. '
1d60f9aa07d1 Email notification about new attachments. Some i18n issues left to be fixed.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2354
diff changeset
172 "An attachment has been added to that page by %(editor)s. "
1d60f9aa07d1 Email notification about new attachments. Some i18n issues left to be fixed.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2354
diff changeset
173 "Following detailed information is available:\n\n"
1d60f9aa07d1 Email notification about new attachments. Some i18n issues left to be fixed.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2354
diff changeset
174 "Attachment name: %(attach_name)s\n"
2638
6e84127a1860 Finally all known bugs fixed, OOB is used to send links with jabber. More...
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2633
diff changeset
175 "Attachment size: %(attach_size)s\n") % {
2356
1d60f9aa07d1 Email notification about new attachments. Some i18n issues left to be fixed.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2354
diff changeset
176 'editor': user.getUserIdentification(request),
1d60f9aa07d1 Email notification about new attachments. Some i18n issues left to be fixed.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2354
diff changeset
177 'page_name': page_name,
1d60f9aa07d1 Email notification about new attachments. Some i18n issues left to be fixed.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2354
diff changeset
178 'attach_name': attach_name,
1d60f9aa07d1 Email notification about new attachments. Some i18n issues left to be fixed.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2354
diff changeset
179 'attach_size': attach_size,
1d60f9aa07d1 Email notification about new attachments. Some i18n issues left to be fixed.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2354
diff changeset
180 }
1d60f9aa07d1 Email notification about new attachments. Some i18n issues left to be fixed.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2354
diff changeset
181
2688
da94375a625c Towards full data forms support. Not finished, probably broken. Don't merge.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2638
diff changeset
182 data['editor'] = user.getUserIdentification(request)
da94375a625c Towards full data forms support. Not finished, probably broken. Don't merge.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2638
diff changeset
183 data['page_name'] = page_name
da94375a625c Towards full data forms support. Not finished, probably broken. Don't merge.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2638
diff changeset
184 data['attach_size'] = attach_size
da94375a625c Towards full data forms support. Not finished, probably broken. Don't merge.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2638
diff changeset
185 data['attach_name'] = attach_name
da94375a625c Towards full data forms support. Not finished, probably broken. Don't merge.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2638
diff changeset
186
da94375a625c Towards full data forms support. Not finished, probably broken. Don't merge.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2638
diff changeset
187 return data
2356
1d60f9aa07d1 Email notification about new attachments. Some i18n issues left to be fixed.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2354
diff changeset
188
1d60f9aa07d1 Email notification about new attachments. Some i18n issues left to be fixed.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2354
diff changeset
189
2426
5d1c31b0c6b5 make jabber/email notification types configurable orthogonally
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2356
diff changeset
190 # XXX: clean up this method to take a notification type instead of bool for_jabber
2356
1d60f9aa07d1 Email notification about new attachments. Some i18n issues left to be fixed.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2354
diff changeset
191 def filter_subscriber_list(event, subscribers, for_jabber):
1d60f9aa07d1 Email notification about new attachments. Some i18n issues left to be fixed.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2354
diff changeset
192 """Filter a list of page subscribers to honor event subscriptions
1d60f9aa07d1 Email notification about new attachments. Some i18n issues left to be fixed.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2354
diff changeset
193
1d60f9aa07d1 Email notification about new attachments. Some i18n issues left to be fixed.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2354
diff changeset
194 @param subscribers: list of subscribers (dict of lists, language is the key)
2426
5d1c31b0c6b5 make jabber/email notification types configurable orthogonally
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2356
diff changeset
195 @param for_jabber: require jid
2356
1d60f9aa07d1 Email notification about new attachments. Some i18n issues left to be fixed.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2354
diff changeset
196 @type subscribers: dict
1d60f9aa07d1 Email notification about new attachments. Some i18n issues left to be fixed.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2354
diff changeset
197
1d60f9aa07d1 Email notification about new attachments. Some i18n issues left to be fixed.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2354
diff changeset
198 """
2633
f42fb1ae0a38 Fixes to the Event.name commit.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2505
diff changeset
199 event_name = event.name
2356
1d60f9aa07d1 Email notification about new attachments. Some i18n issues left to be fixed.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2354
diff changeset
200
1d60f9aa07d1 Email notification about new attachments. Some i18n issues left to be fixed.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2354
diff changeset
201 # Filter the list by removing users who don't want to receive
1d60f9aa07d1 Email notification about new attachments. Some i18n issues left to be fixed.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2354
diff changeset
202 # notifications about this type of event
1d60f9aa07d1 Email notification about new attachments. Some i18n issues left to be fixed.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2354
diff changeset
203 for lang in subscribers.keys():
1d60f9aa07d1 Email notification about new attachments. Some i18n issues left to be fixed.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2354
diff changeset
204 userlist = []
1d60f9aa07d1 Email notification about new attachments. Some i18n issues left to be fixed.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2354
diff changeset
205
1d60f9aa07d1 Email notification about new attachments. Some i18n issues left to be fixed.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2354
diff changeset
206 if for_jabber:
1d60f9aa07d1 Email notification about new attachments. Some i18n issues left to be fixed.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2354
diff changeset
207 for usr in subscribers[lang]:
2426
5d1c31b0c6b5 make jabber/email notification types configurable orthogonally
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2356
diff changeset
208 if usr.jid and event_name in usr.jabber_subscribed_events:
2356
1d60f9aa07d1 Email notification about new attachments. Some i18n issues left to be fixed.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2354
diff changeset
209 userlist.append(usr)
1d60f9aa07d1 Email notification about new attachments. Some i18n issues left to be fixed.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2354
diff changeset
210 else:
1d60f9aa07d1 Email notification about new attachments. Some i18n issues left to be fixed.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2354
diff changeset
211 for usr in subscribers[lang]:
2426
5d1c31b0c6b5 make jabber/email notification types configurable orthogonally
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2356
diff changeset
212 if usr.email and event_name in usr.email_subscribed_events:
2356
1d60f9aa07d1 Email notification about new attachments. Some i18n issues left to be fixed.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2354
diff changeset
213 userlist.append(usr)
1d60f9aa07d1 Email notification about new attachments. Some i18n issues left to be fixed.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2354
diff changeset
214
1d60f9aa07d1 Email notification about new attachments. Some i18n issues left to be fixed.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2354
diff changeset
215 subscribers[lang] = userlist