Attachment 'UserList2_1.7.py'
Download 1 #format python
2 """
3 MoinMoin macro to create a list of current users
4 UserList.py
5 ark 06/13/04 0.1
6
7 ***********
8 originally by Antti Kuntsi <antti@kuntsi.com>
9 As far as the author is concerned, this code is released to the public
10 domain, but some restrictions in the MoinMoin COPYING file may apply. Ask a
11 lawyer.
12 ***********
13 This code has not been tested exhaustively. Use at your own risk.
14 The multiple column support has been tested a little
15 ***********
16
17 This macro displays a list of currently known users.
18
19 Usage:
20 <<UserList2(....)>>
21 parameters:
22 columncount=INT
23 width=PERCENTUAL WIDTH OF BOX
24 grouplabel - whether render linkbar with initials
25
26
27 Changes to suit to API changes of 1.3.x releases done by CyA, (c) 2005-02-28
28 Multicolumn layout redesigned by CyA
29
30 """
31
32
33 import string, time, os, getopt
34 from math import ceil
35 from MoinMoin import wikiutil, user
36 from MoinMoin.config import multiconfig
37
38 def create_realname(username):
39 realname=""
40
41 start=1
42 for i in username:
43 if start == 0 and i.isupper():
44 realname+=" %s" % i
45 else:
46 realname+=i
47 if start == 1:
48 start = 0
49 return realname
50
51 def execute(macro, args):
52 '''handle the UserList Macro. return the generated display HTML
53 ark 06/13/04'''
54 result = []
55 columnlist=[]
56
57 # get user from Wiki cache
58 users = user.getUserList(macro.request)
59 if not users:
60 return
61 else:
62 #get identifications of users
63 userlist=[]
64 for uid in users:
65 name = user.User(macro.request, id=uid).name
66 userlist.append(name)
67 # create a dictionary with initials as keys and lists of usernames as values
68 initials={}
69 for u in userlist:
70 initial=u[0]
71 if not initial in initials.keys():
72 initials[initial]=[]
73 initials[initial].append(u)
74
75 # define standard values
76 rowsize=1
77 grouplabel=0
78 tablewidth=100
79
80 # parse the arguments
81 args = _parse_arguments(args, ',')
82
83 # use passed in options
84 if args:
85 for o,a in args:
86 # how many columns to use in output table
87 if o in ("--columncount"):
88 rowsize=int(a)
89
90 # label each group of users which is started by new initial by special row
91 if o in ("--grouplabel"):
92 grouplabel=1
93
94 # use defined table width
95 if o in ("--width"):
96 # is it not relative?
97 if a.find("%") < 0:
98 if a<0:
99 a=100
100 if a>100:
101 a=100
102 a=a+"%"
103 tablewidth=a
104
105 result.append(macro.formatter.rawHTML('<table style="width: %s;">') % tablewidth)
106 ik=initials.keys()
107 ik.sort()
108 for initial in ik:
109 users=initials[initial]
110 count=len(users)
111
112 rows=ceil(count/float(rowsize)) # how much rows will take group of users with the same initials
113 row=0
114 col=0
115 userindex=0
116
117 if grouplabel == 1:
118 result.append(macro.formatter.rawHTML('<tr><td width="100%%" colspan="%s"><a id="%s"><span style="text-transform: uppercase; font-weight: bold;">%s</span></a></td></tr>' %(rowsize,initial,initial)))
119 while row < rows:
120 result.append(macro.formatter.table_row(1))
121 while col < rowsize:
122 result.append(macro.formatter.table_cell(1))
123 if userindex < count:
124 name=users[userindex]
125 pagename = macro.formatter.pagelink(1, name)
126 realname = create_realname(name)
127 content=pagename+realname+"</a>"
128 else:
129 content=" "
130 result.append(macro.formatter.rawHTML("%s") % content)
131 result.append(macro.formatter.table_cell(0))
132 userindex+=1
133 col+=1
134 col=0
135 result.append(macro.formatter.table_row(0))
136 row+=1
137
138 result.append(macro.formatter.table(0))
139
140 if grouplabel==1:
141 anchorlinks=""
142 for a in ik:
143 anchor=macro.formatter.anchorlink(1,a)+a+"</a> "
144 anchorlinks+=anchor
145 anchorlinks=anchorlinks[:-1]
146 result.insert(0, anchorlinks)
147
148 result.append(macro.formatter.rawHTML('<br clear="both">'))
149 return "\n".join(result)
150
151
152 def _parse_arguments(argstring, delimchar=',', quotechar='"',macro=None,result=None):
153 '''
154 transform argument string into form suitable for getopt and parse it.
155 I'm lazy to finding out original ways when the standard one does exist. cya.
156 '''
157
158 if argstring:
159 arguments=argstring.split(delimchar)
160 args=[]
161 for a in arguments:
162 a='--'+a
163 args.append(a)
164
165 try:
166 opts, oargs = getopt.getopt(args, "", ["columncount=","width=","grouplabel"])
167 except getopt.GetoptError:
168 opts=None
169 else:
170 opts=None
171
172 return opts
Attached Files
To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.You are not allowed to attach a file to this page.