~ubuntu-branches/ubuntu/natty/moin/natty-updates

« back to all changes in this revision

Viewing changes to MoinMoin/events/notification.py

  • Committer: Bazaar Package Importer
  • Author(s): Jonas Smedegaard
  • Date: 2008-06-22 21:17:13 UTC
  • mto: This revision was merged to the branch mainline in revision 18.
  • Revision ID: james.westby@ubuntu.com-20080622211713-inlv5k4eifxckelr
ImportĀ upstreamĀ versionĀ 1.7.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
from MoinMoin import user, wikiutil
13
13
from MoinMoin.events import EventResult
14
14
 
15
 
 
16
15
class Result(EventResult):
17
16
    """ A base class for results of notification handlers"""
18
17
    pass
19
18
 
20
 
 
21
19
class Failure(Result):
22
20
    """ Used to report a failure in sending notifications """
23
21
    def __init__(self, reason, recipients = None):
42
40
        """
43
41
        self.recipients = recipients
44
42
 
45
 
 
46
43
class UnknownChangeType(Exception):
47
44
    """ Used to signal an invalid page change event """
48
45
    pass
49
46
 
50
 
 
51
47
def page_link(request, page, querystr):
52
48
    """Create an absolute url to a given page with optional action
53
49
 
56
52
    @param querystr: a dict passed to wikiutil.makeQueryString
57
53
 
58
54
    """
59
 
    return request.getQualifiedURL(page.url(request, querystr))
60
 
 
 
55
    query = wikiutil.makeQueryString(querystr, True)
 
56
    return request.getQualifiedURL(page.url(request, query))
61
57
 
62
58
def page_change_message(msgtype, request, page, lang, **kwargs):
63
59
    """Prepare a notification text for a page change of given type
82
78
        'The "%(pagename)s" page has been changed by %(editor)s:\n') % {
83
79
            'pagename': page.page_name,
84
80
            'editor': page.uid_override or user.getUserIdentification(request),
85
 
            'sitename': page.cfg.sitename or request.url_root,
 
81
            'sitename': page.cfg.sitename or request.getBaseURL(),
86
82
        }
87
83
 
88
84
        # append a diff (or append full page text if there is no diff)
102
98
            'The page "%(pagename)s" has been deleted by %(editor)s:\n\n') % {
103
99
                'pagename': page.page_name,
104
100
                'editor': page.uid_override or user.getUserIdentification(request),
105
 
                'sitename': page.cfg.sitename or request.url_root,
 
101
                'sitename': page.cfg.sitename or request.getBaseURL(),
106
102
        }
107
103
 
108
104
    elif msgtype == "page_renamed":
111
107
            'The page "%(pagename)s" has been renamed from "%(oldname)s" by %(editor)s:\n') % {
112
108
                'editor': page.uid_override or user.getUserIdentification(request),
113
109
                'pagename': page.page_name,
114
 
                'sitename': page.cfg.sitename or request.url_root,
 
110
                'sitename': page.cfg.sitename or request.getBaseURL(),
115
111
                'oldname': kwargs['old_name']
116
112
        }
117
113
 
126
122
 
127
123
    return changes
128
124
 
129
 
 
130
125
def user_created_message(request, _, sitename, username, email):
131
126
    """Formats a message used to notify about accounts being created
132
127
 
133
128
    @return: a dict containing message body and subject
134
129
    """
135
 
    subject = _("[%(sitename)s] New user account created") % {'sitename': sitename or "Wiki"}
136
 
    text = _("""Dear Superuser, a new user has just been created on "%(sitename)s". Details follow:
 
130
    subject = _("New user account created on %(sitename)s") % {'sitename': sitename or "Wiki"}
 
131
    text = _("""Dear Superuser, a new user has just been created. Details follow:
137
132
 
138
133
    User name: %(username)s
139
134
    Email address: %(useremail)s""") % {
140
135
         'username': username,
141
136
         'useremail': email,
142
 
         'sitename': sitename or "Wiki",
143
137
         }
144
138
 
145
139
    return {'subject': subject, 'text': text}
146
140
 
147
 
 
148
141
def attachment_added(request, _, page_name, attach_name, attach_size):
149
142
    """Formats a message used to notify about new attachments
150
143
 
154
147
    """
155
148
    data = {}
156
149
 
157
 
    data['subject'] = _("[%(sitename)s] New attachment added to page %(pagename)s") % {
 
150
    data['subject'] = _("New attachment added to page %(pagename)s on %(sitename)s") % {
158
151
                'pagename': page_name,
159
 
                'sitename': request.cfg.sitename or request.url_root,
 
152
                'sitename': request.cfg.sitename or request.getBaseURL(),
160
153
                }
161
154
 
162
155
    data['text'] = _("Dear Wiki user,\n\n"
179
172
    return data
180
173
 
181
174
 
182
 
def attachment_removed(request, _, page_name, attach_name, attach_size):
183
 
    """Formats a message used to notify about removed attachments
184
 
 
185
 
    @param _: a gettext function
186
 
    @return: a dict with notification data
187
 
 
188
 
    """
189
 
    data = {}
190
 
 
191
 
    data['subject'] = _("[%(sitename)s] Removed attachment from page %(pagename)s") % {
192
 
                'pagename': page_name,
193
 
                'sitename': request.cfg.sitename or request.url_root,
194
 
                }
195
 
 
196
 
    data['text'] = _("Dear Wiki user,\n\n"
197
 
    'You have subscribed to a wiki page "%(page_name)s" for change notification. '
198
 
    "An attachment has been removed from that page by %(editor)s. "
199
 
    "Following detailed information is available:\n\n"
200
 
    "Attachment name: %(attach_name)s\n"
201
 
    "Attachment size: %(attach_size)s\n") % {
202
 
        'editor': user.getUserIdentification(request),
203
 
        'page_name': page_name,
204
 
        'attach_name': attach_name,
205
 
        'attach_size': attach_size,
206
 
    }
207
 
 
208
 
    data['editor'] = user.getUserIdentification(request)
209
 
    data['page_name'] = page_name
210
 
    data['attach_size'] = attach_size
211
 
    data['attach_name'] = attach_name
212
 
 
213
 
    return data
214
 
 
215
 
 
216
175
# XXX: clean up this method to take a notification type instead of bool for_jabber
217
176
def filter_subscriber_list(event, subscribers, for_jabber):
218
177
    """Filter a list of page subscribers to honor event subscriptions
239
198
                    userlist.append(usr)
240
199
 
241
200
        subscribers[lang] = userlist
242