Attachment 'MakeInvitation1-6-dev.py'
Download 1 # -*- coding: iso-8859-1 -*-
2 """
3 MoinMoin - MakeInvitation macro
4
5 Syntax:
6 [[MakeInvitation]]
7
8 Lot of code take from userform.py
9 MoinMoin - userform.py
10 @copyright: 2001-2004 by Jürgen Hermann <jh@web.de>
11 @license: GNU GPL, see COPYING for details.
12
13 MoinMoin - MakeInvitation Macro
14 @copyright: 2006 by Oliver Siemoneit
15 @license: GNU GPL, see COPYING for details.
16 """
17
18 from MoinMoin.widget import html
19
20
21 def make_row(table, label, cell, **kw):
22 """ Create a row in the form table.
23 """
24 table.append(html.TR().extend([
25 html.TD(**kw).extend([html.B().append(label), ' ']),
26 html.TD().extend(cell),
27 ]))
28 return table
29
30 def execute(macro, args):
31 request = macro.request
32 _ = request.getText
33 formatter = macro.formatter
34
35 # Check if user is superuser. If not: return with error msg
36 if not request.user.isSuperUser():
37 err = _('You are not allowed to perform this action.')
38 return err
39
40 sn = request.getScriptname()
41 pi = request.getPathinfo()
42 action = u"%s%s" % (sn, pi)
43 form = html.FORM(action=action)
44 table = html.TABLE(border="0")
45
46 # Create 6 digits dummy password
47 from random import choice
48 letters = "abcdefghijklmnopqrstuvwxyz"
49 letters += "0123456789"
50 pwd = ''
51 for i in range(6):
52 pwd += choice(letters)
53
54 # Add form fields
55 for key, label, type, length, textafter in request.cfg.user_form_fields:
56 if key in ('name', 'password', 'password2', 'email'):
57
58 if key == 'password' or key == 'password2':
59 table = make_row(table, _(label),
60 [ html.INPUT(type=type, size=length, name=key,
61 value='%s' % pwd),
62 ' ',])
63 else:
64 table = make_row(table, _(label),
65 [ html.INPUT(type=type, size=length, name=key,
66 value=''),
67 ' ', _(textafter), ])
68
69 # Add buttons
70 buttons = []
71 if request.cfg.mail_enabled:
72 buttons.append(("create_and_mail", "%s + %s" %
73 (_('Create Profile'), _('Email'))))
74
75 buttons.append(('cancel', _('Cancel')))
76
77 button_cell = []
78 for name, label in buttons:
79 if not name in request.cfg.user_form_remove:
80 button_cell.extend([
81 html.INPUT(type="submit", name=name, value=label),
82 ' ',
83 ])
84 make_row(table,'', button_cell)
85
86
87 # Use the user interface language and direction
88 lang_attr = request.theme.ui_lang_attr()
89 form.append(html.Raw('<div class="userprefs"%s>' % lang_attr))
90 form.append(html.INPUT(type="hidden", name="action", value="userform"))
91 form.append(table)
92 form.append(html.Raw("</div>"))
93
94 return unicode(form)
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.