Back to index

moin  1.9.0~rc2
subscribe.py
Go to the documentation of this file.
00001 # -*- coding: iso-8859-1 -*-
00002 """
00003     MoinMoin - subscribe to a page to get notified when it changes
00004 
00005     @copyright: 2000-2004 Juergen Hermann <jh@web.de>,
00006                 2006 MoinMoin:ThomasWaldmann
00007     @license: GNU GPL, see COPYING for details.
00008 """
00009 from MoinMoin.Page import Page
00010 
00011 def execute(pagename, request):
00012     """ Subscribe the user to pagename """
00013     _ = request.getText
00014     if not request.user.valid:
00015         actname = __name__.split('.')[-1]
00016         request.theme.add_msg(_("You must login to use this action: %(action)s.") % {"action": actname}, "error")
00017         return Page(request, pagename).send_page()
00018 
00019     cfg = request.cfg
00020 
00021     if not request.user.may.read(pagename):
00022         request.theme.add_msg(_("You are not allowed to subscribe to a page you can't read."), "error")
00023 
00024     # Check if mail is enabled
00025     elif not cfg.mail_enabled and not cfg.jabber_enabled:
00026         request.theme.add_msg(_("This wiki is not enabled for mail/Jabber processing."), "error")
00027 
00028     # Suggest visitors to login
00029     elif not request.user.valid:
00030         request.theme.add_msg(_("You must log in to use subscriptions."), "error")
00031 
00032     # Suggest users without email to add their email address
00033     elif not request.user.email and not request.user.jid:
00034         request.theme.add_msg(_("Add your email address or Jabber ID in your user settings to use subscriptions."),
00035                               "error")
00036 
00037     elif request.user.isSubscribedTo([pagename]):
00038         request.theme.add_msg(_('You are already subscribed to this page.'))
00039     else:
00040         # Try to subscribe
00041         if request.user.subscribe(pagename):
00042             request.theme.add_msg(_('You have been subscribed to this page.'), "info")
00043         else: # should not happen
00044             request.theme.add_msg(_('You could not get subscribed to this page.'), "error")
00045 
00046     Page(request, pagename).send_page()