Back to index

moin  1.9.0~rc2
Functions | Variables
MoinMoin.action.SubscribeUser Namespace Reference

Functions

def show_form
def parse_re
def parse_userlist
def show_result
def subscribe_users
def execute

Variables

 args = sys.argv
list pagename = args[1]
list usernames = args[2]
list request_url = args[3]
tuple request = ScriptContext(url=request_url)
tuple formatter = Formatter(request)

Detailed Description

   MoinMoin - Subscribeuser - Action
   Subscribe (or unsubscribe) a user to a page.

   @copyright: 2003 Daniela Nicklas <nicklas@informatik.uni-stuttgart.de>,
           2005 MoinMoin:AlexanderSchremmer,
           2009 MoinMoin:ThomasWaldmann
   @license: GNU GPL, see COPYING for details.

Function Documentation

def MoinMoin.action.SubscribeUser.execute (   pagename,
  request 
)

Definition at line 125 of file SubscribeUser.py.

00125 
00126 def execute(pagename, request):
00127     _ = request.getText
00128     if not request.user.may.admin(pagename):
00129         thispage = Page(request, pagename)
00130         request.theme.add_msg(_("You are not allowed to perform this action."), "error")
00131         return thispage.send_page()
00132     elif 'users' not in request.form:
00133         show_form(pagename, request)
00134     else:
00135         show_result(pagename, request)
00136 

Here is the call graph for this function:

Definition at line 34 of file SubscribeUser.py.

00034 
00035 def parse_re(usernames):
00036     username_regexes = []
00037     for name in usernames:
00038         if name.startswith("re:"):
00039             name = name[3:]
00040         else:
00041             name = re.escape(name)
00042         username_regexes.append(name)
00043     return username_regexes
00044 

Here is the caller graph for this function:

Definition at line 45 of file SubscribeUser.py.

00045 
00046 def parse_userlist(usernames):
00047     subscribe = []
00048     unsubscribe = []
00049     for name in usernames:
00050         if name.startswith("-"):
00051             unsubscribe.append(name[1:])
00052         elif name.startswith("+"):
00053             subscribe.append(name[1:])
00054         else:
00055             subscribe.append(name)
00056     return parse_re(subscribe), parse_re(unsubscribe)
00057 

Here is the call graph for this function:

Here is the caller graph for this function:

def MoinMoin.action.SubscribeUser.show_form (   pagename,
  request 
)

Definition at line 18 of file SubscribeUser.py.

00018 
00019 def show_form(pagename, request):
00020     _ = request.getText
00021     request.theme.send_title(_("Subscribe users to the page %s") % pagename, pagename=pagename)
00022 
00023     request.write("""
00024 <form action="%s" method="POST" enctype="multipart/form-data">
00025 <input type="hidden" name="action" value="SubscribeUser">
00026 %s <input type="text" name="users" size="50">
00027 <input type="submit" value="Subscribe">
00028 </form>
00029 """ % (request.href(pagename),
00030       _("Enter user names (comma separated):")))
00031     request.theme.send_footer(pagename)
00032     request.theme.send_closing_html()
00033 

Here is the caller graph for this function:

def MoinMoin.action.SubscribeUser.show_result (   pagename,
  request 
)

Definition at line 58 of file SubscribeUser.py.

00058 
00059 def show_result(pagename, request):
00060     _ = request.getText
00061 
00062     request.theme.send_title(_("Subscribed for %s:") % pagename, pagename=pagename)
00063 
00064     from MoinMoin.formatter.text_html import Formatter
00065     formatter = Formatter(request)
00066 
00067     usernames = request.form['users'].split(",")
00068     subscribe, unsubscribe = parse_userlist(usernames)
00069 
00070     result = subscribe_users(request, subscribe, unsubscribe, pagename, formatter)
00071     request.write(result)
00072 
00073     request.theme.send_footer(pagename)
00074     request.theme.send_closing_html()
00075 

Here is the call graph for this function:

Here is the caller graph for this function:

def MoinMoin.action.SubscribeUser.subscribe_users (   request,
  subscribe,
  unsubscribe,
  pagename,
  formatter 
)

Definition at line 76 of file SubscribeUser.py.

00076 
00077 def subscribe_users(request, subscribe, unsubscribe, pagename, formatter):
00078     _ = request.getText
00079 
00080     if not Page(request, pagename).exists():
00081         return u"Page does not exist."
00082 
00083     result = []
00084     did_match = {}
00085 
00086     # get user object - only with IDs!
00087     for userid in user.getUserList(request):
00088         userobj = user.User(request, userid)
00089         name = userobj.name
00090 
00091         matched = subscribed = False
00092 
00093         for name_re in unsubscribe:
00094             if re.match(name_re, name, re.U):
00095                 matched = did_match[name_re] = True
00096                 if (not userobj.isSubscribedTo([pagename]) or
00097                     userobj.unsubscribe(pagename)):
00098                     subscribed = False
00099                 break
00100 
00101         for name_re in subscribe:
00102             if re.match(name_re, name, re.U):
00103                 matched = did_match[name_re] = True
00104                 if (userobj.isSubscribedTo([pagename]) or
00105                     (userobj.email or userobj.jid) and userobj.subscribe(pagename)):
00106                     subscribed = True
00107                 break
00108 
00109         if matched:
00110             result.extend([formatter.smiley(subscribed and '{*}' or '{o}'),
00111                            formatter.text(" "),
00112                            formatter.url(1, Page(request, name).url(request)),
00113                            formatter.text(name),
00114                            formatter.url(0),
00115                            formatter.linebreak(preformatted=0),
00116                           ])
00117 
00118     result.extend([''.join([formatter.smiley('{X}'),
00119                             formatter.text(" " + _("Not a user:") + " " + name_re),
00120                             formatter.linebreak(preformatted=0)])
00121                    for name_re in subscribe + unsubscribe if name_re not in did_match])
00122 
00123     return ''.join(result)
00124 

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

Definition at line 138 of file SubscribeUser.py.

Definition at line 170 of file SubscribeUser.py.

Definition at line 157 of file SubscribeUser.py.

Definition at line 167 of file SubscribeUser.py.

Definition at line 161 of file SubscribeUser.py.

Definition at line 158 of file SubscribeUser.py.