Attachment 'UserList.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 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 _parse_arguments -method from ImageLink.py by jkk
13 ***********
14 This code has not been tested exhaustively. Use at your own risk.
15 This code opens the userdict.pickle, and if it gets corrupted, you have a
16 problem. You have been warned.
17 The multiple column support has not been tested, but is assumed to be
18 working.
19 ***********
20
21 This macro displays a list of currently known users.
22
23 Usage:
24 [[UserList]]
25 [[UserList(column1, column2, ...)]]
26
27 Demo. Try pasting the above examples into a MoinMoin sandbox page.
28
29
30 """
31
32
33 import string, pickle, time
34 from math import ceil
35 from MoinMoin import wikiutil, config
36
37 def sorted_users(users):
38 usernames=users.keys()
39 usernames.sort()
40 for username in usernames:
41 usertime = time.localtime(float(users[username].split(".")[0]))
42 yield username, usertime
43
44 def execute(macro, args):
45 '''handle the UserList Macro. return the generated display HTML
46 ark 06/13/04'''
47 # parse the arguments
48 if args==None:
49 args = ''
50 parseargs = _parse_arguments(args, ',', '"')
51 columnlist=[]
52 if len(parseargs)>0:
53 columnlist=filter(None, [name.strip() for name in parseargs])
54
55 result = [macro.formatter.paragraph(0)]
56 userdict = pickle.load(file(config.data_dir+"/user/userdict.pickle"))
57
58 if not userdict:
59 return
60
61 userlist = sorted_users(userdict)
62
63 if columnlist:
64 columnsize=int(ceil(len(userdict)/float(len(columnlist))))
65
66 initials = []
67 initial=''
68 currentcount=0
69 for name, creationtime in userlist:
70 if initial != name[0]:
71 initial=name[0]
72 initials.append(initial)
73 if currentcount:
74 result.append(macro.formatter.bullet_list(0))
75 if columnlist and (currentcount > columnsize or currentcount == 0):
76 newcolumn=columnlist.pop(0)
77 if currentcount:
78 result.append(macro.formatter.rawHTML('</div>'))
79 result.append(macro.formatter.rawHTML('<div id="%s">'%newcolumn))
80 result.append(macro.formatter.anchordef(initial))
81 result.append(macro.formatter.heading(2, name[0]))
82 result.append(macro.formatter.bullet_list(1))
83 result.append(macro.formatter.listitem(1))
84 name = macro.formatter.pagelink(name, name)
85 result.append("%s -- %s"%(name, time.strftime(config.date_fmt, creationtime)))
86 result.append(macro.formatter.listitem(0))
87 currentcount+=1
88
89 result.append(macro.formatter.bullet_list(0))
90 if parseargs:
91 result.append(macro.formatter.rawHTML('</div>'))
92 while columnlist:
93 result.append(macro.formatter.rawHTML('<div id="%s"> </div>'%columnlist.pop(0)))
94 anchorlinks = "".join([macro.formatter.anchorlink(a, a) for a in initials])
95 result.append(macro.formatter.paragraph(1))
96 result.append(macro.formatter.rawHTML('<br clear="both">'))
97 result.insert(0, anchorlinks)
98 result.append(anchorlinks)
99 return "\n".join(result)
100
101
102 def _parse_arguments(argstring, delimchar=',', quotechar='"'):
103 '''parse argstring into separate arguments originally separated by delimchar.
104 occurrences of delimchar found within quotechars are ignored.
105 This parser is not particularly elegant. Improvements are welcome.
106 jjk 03/28/01'''
107 # replace delimiters not in quotes with a special delimiter
108 delim2 = chr(0)
109 inquote = 0
110 for i1 in range(len(argstring)):
111 cchar = argstring[i1]
112 if cchar==quotechar:
113 inquote = not inquote
114 elif (not inquote) and cchar==delimchar:
115 argstring = argstring[:i1] + delim2 + argstring[i1+1:]
116 # split the argument string on the special delimiter, and remove external quotes
117 args = string.split(argstring, delim2)
118 for i1 in range(len(args)):
119 arg = args[i1]
120 if arg[:1]==quotechar and arg[-1:]==quotechar:
121 args[i1] = arg[1:-1]
122 return args
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.