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