Back to index

moin  1.9.0~rc2
Classes | Functions
MoinMoin.events.notification Namespace Reference

Classes

class  Result
class  Failure
class  Success
class  UnknownChangeType

Functions

def page_link
def page_change_message
def user_created_message
def attachment_added
def attachment_removed
def filter_subscriber_list

Class Documentation

class MoinMoin::events::notification::UnknownChangeType
Used to signal an invalid page change event 

Definition at line 46 of file notification.py.


Function Documentation

def MoinMoin.events.notification.attachment_added (   request,
  _,
  page_name,
  attach_name,
  attach_size 
)
Formats a message used to notify about new attachments

@param _: a gettext function
@return: a dict with notification data

Definition at line 148 of file notification.py.

00148 
00149 def attachment_added(request, _, page_name, attach_name, attach_size):
00150     """Formats a message used to notify about new attachments
00151 
00152     @param _: a gettext function
00153     @return: a dict with notification data
00154 
00155     """
00156     data = {}
00157 
00158     data['subject'] = _("New attachment added to page %(pagename)s on %(sitename)s") % {
00159                 'pagename': page_name,
00160                 'sitename': request.cfg.sitename or request.url_root,
00161                 }
00162 
00163     data['text'] = _("Dear Wiki user,\n\n"
00164     'You have subscribed to a wiki page "%(page_name)s" for change notification. '
00165     "An attachment has been added to that page by %(editor)s. "
00166     "Following detailed information is available:\n\n"
00167     "Attachment name: %(attach_name)s\n"
00168     "Attachment size: %(attach_size)s\n") % {
00169         'editor': user.getUserIdentification(request),
00170         'page_name': page_name,
00171         'attach_name': attach_name,
00172         'attach_size': attach_size,
00173     }
00174 
00175     data['editor'] = user.getUserIdentification(request)
00176     data['page_name'] = page_name
00177     data['attach_size'] = attach_size
00178     data['attach_name'] = attach_name
00179 
00180     return data
00181 

def MoinMoin.events.notification.attachment_removed (   request,
  _,
  page_name,
  attach_name,
  attach_size 
)
Formats a message used to notify about removed attachments

@param _: a gettext function
@return: a dict with notification data

Definition at line 182 of file notification.py.

00182 
00183 def attachment_removed(request, _, page_name, attach_name, attach_size):
00184     """Formats a message used to notify about removed attachments
00185 
00186     @param _: a gettext function
00187     @return: a dict with notification data
00188 
00189     """
00190     data = {}
00191 
00192     data['subject'] = _("Removed attachment from page %(pagename)s on %(sitename)s") % {
00193                 'pagename': page_name,
00194                 'sitename': request.cfg.sitename or request.url_root,
00195                 }
00196 
00197     data['text'] = _("Dear Wiki user,\n\n"
00198     'You have subscribed to a wiki page "%(page_name)s" for change notification. '
00199     "An attachment has been removed from that page by %(editor)s. "
00200     "Following detailed information is available:\n\n"
00201     "Attachment name: %(attach_name)s\n"
00202     "Attachment size: %(attach_size)s\n") % {
00203         'editor': user.getUserIdentification(request),
00204         'page_name': page_name,
00205         'attach_name': attach_name,
00206         'attach_size': attach_size,
00207     }
00208 
00209     data['editor'] = user.getUserIdentification(request)
00210     data['page_name'] = page_name
00211     data['attach_size'] = attach_size
00212     data['attach_name'] = attach_name
00213 
00214     return data
00215 
00216 
# XXX: clean up this method to take a notification type instead of bool for_jabber
def MoinMoin.events.notification.filter_subscriber_list (   event,
  subscribers,
  for_jabber 
)
Filter a list of page subscribers to honor event subscriptions

@param subscribers: list of subscribers (dict of lists, language is the key)
@param for_jabber: require jid
@type subscribers: dict

Definition at line 217 of file notification.py.

00217 
00218 def filter_subscriber_list(event, subscribers, for_jabber):
00219     """Filter a list of page subscribers to honor event subscriptions
00220 
00221     @param subscribers: list of subscribers (dict of lists, language is the key)
00222     @param for_jabber: require jid
00223     @type subscribers: dict
00224 
00225     """
00226     event_name = event.name
00227 
00228     # Filter the list by removing users who don't want to receive
00229     # notifications about this type of event
00230     for lang in subscribers.keys():
00231         userlist = []
00232 
00233         if for_jabber:
00234             for usr in subscribers[lang]:
00235                 if usr.jid and event_name in usr.jabber_subscribed_events:
00236                     userlist.append(usr)
00237         else:
00238             for usr in subscribers[lang]:
00239                 if usr.email and event_name in usr.email_subscribed_events:
00240                     userlist.append(usr)
00241 
00242         subscribers[lang] = userlist
00243 
def MoinMoin.events.notification.page_change_message (   msgtype,
  request,
  page,
  lang,
  kwargs 
)
Prepare a notification text for a page change of given type

@param msgtype: a type of message to send (page_changed, page_renamed, ...)
@type msgtype: str or unicode
@param **kwargs: a dictionary of additional parameters, which depend on msgtype

@return: dictionary containing data about the changed page
@rtype: dict

Definition at line 62 of file notification.py.

00062 
00063 def page_change_message(msgtype, request, page, lang, **kwargs):
00064     """Prepare a notification text for a page change of given type
00065 
00066     @param msgtype: a type of message to send (page_changed, page_renamed, ...)
00067     @type msgtype: str or unicode
00068     @param **kwargs: a dictionary of additional parameters, which depend on msgtype
00069 
00070     @return: dictionary containing data about the changed page
00071     @rtype: dict
00072 
00073     """
00074     _ = lambda text: request.getText(text, lang=lang)
00075     changes = {'page_name': page.page_name, 'revision': str(page.getRevList()[0])}
00076 
00077     if msgtype == "page_changed":
00078         revisions = kwargs['revisions']
00079 
00080     if msgtype == "page_changed":
00081         changes['text'] = _("Dear Wiki user,\n\n"
00082         'You have subscribed to a wiki page or wiki category on "%(sitename)s" for change notification.\n\n'
00083         'The "%(pagename)s" page has been changed by %(editor)s:\n') % {
00084             'pagename': page.page_name,
00085             'editor': page.uid_override or user.getUserIdentification(request),
00086             'sitename': page.cfg.sitename or request.url_root,
00087         }
00088 
00089         # append a diff (or append full page text if there is no diff)
00090         if len(revisions) < 2:
00091             changes['diff'] = _("New page:\n") + page.get_raw_body()
00092         else:
00093             lines = wikiutil.pagediff(request, page.page_name, revisions[1],
00094                                       page.page_name, revisions[0])
00095             if lines:
00096                 changes['diff'] = '\n'.join(lines)
00097             else:
00098                 changes['diff'] = _("No differences found!\n")
00099 
00100     elif msgtype == "page_deleted":
00101         changes['text'] = _("Dear wiki user,\n\n"
00102             'You have subscribed to a wiki page "%(sitename)s" for change notification.\n\n'
00103             'The page "%(pagename)s" has been deleted by %(editor)s:\n\n') % {
00104                 'pagename': page.page_name,
00105                 'editor': page.uid_override or user.getUserIdentification(request),
00106                 'sitename': page.cfg.sitename or request.url_root,
00107         }
00108 
00109     elif msgtype == "page_renamed":
00110         changes['text'] = _("Dear wiki user,\n\n"
00111             'You have subscribed to a wiki page "%(sitename)s" for change notification.\n\n'
00112             'The page "%(pagename)s" has been renamed from "%(oldname)s" by %(editor)s:\n') % {
00113                 'editor': page.uid_override or user.getUserIdentification(request),
00114                 'pagename': page.page_name,
00115                 'sitename': page.cfg.sitename or request.url_root,
00116                 'oldname': kwargs['old_name']
00117         }
00118 
00119         changes['old_name'] = kwargs['old_name']
00120 
00121     else:
00122         raise UnknownChangeType()
00123 
00124     changes['editor'] = page.uid_override or user.getUserIdentification(request)
00125     if 'comment' in kwargs and kwargs['comment']:
00126         changes['comment'] = kwargs['comment']
00127 
00128     return changes
00129 

def MoinMoin.events.notification.page_link (   request,
  page,
  querystr 
)
Create an absolute url to a given page with optional action

@param page: a page to link to
@type page: MoinMoin.Page.Page
@param querystr: a dict passed to wikiutil.makeQueryString

Definition at line 51 of file notification.py.

00051 
00052 def page_link(request, page, querystr):
00053     """Create an absolute url to a given page with optional action
00054 
00055     @param page: a page to link to
00056     @type page: MoinMoin.Page.Page
00057     @param querystr: a dict passed to wikiutil.makeQueryString
00058 
00059     """
00060     return request.getQualifiedURL(page.url(request, querystr))
00061 

def MoinMoin.events.notification.user_created_message (   request,
  _,
  sitename,
  username,
  email 
)
Formats a message used to notify about accounts being created

@return: a dict containing message body and subject

Definition at line 130 of file notification.py.

00130 
00131 def user_created_message(request, _, sitename, username, email):
00132     """Formats a message used to notify about accounts being created
00133 
00134     @return: a dict containing message body and subject
00135     """
00136     subject = _("New user account created on %(sitename)s") % {'sitename': sitename or "Wiki"}
00137     text = _("""Dear Superuser, a new user has just been created on %(sitename)s". Details follow:
00138 
00139     User name: %(username)s
00140     Email address: %(useremail)s""") % {
00141          'username': username,
00142          'useremail': email,
00143          'sitename': sitename or "Wiki",
00144          }
00145 
00146     return {'subject': subject, 'text': text}
00147