annotate MoinMoin/macro/NewPage.py @ 6133:a6283e189869 tip

fixup: remove nonexisting passlib.utils._blowfish this was removed by the passlib 1.7.1 upgrade.
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Thu, 01 Jun 2017 18:10:19 +0200
parents a6c315ff8d66
children
rev   line source
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1 # -*- coding: iso-8859-1 -*-
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
2 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
3 MoinMoin - New Page macro
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
4
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
5 Thanks to Jos Yule's "blogpost" action and his modified Form for
3115
cd6cfc715261 replace wikiwikiweb.de by moinmo.in, replace contact Juergen Hermann by Thomas Waldmann, cleanup wikiconfig (ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3040
diff changeset
6 giving me the pieces I needed to figure all this stuff out: MoinMoin:JosYule
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
7
1918
bb2e053067fb fixing copyright headers: remove umlauts (encoding troubles), make epydoc compatible, reformat
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1841
diff changeset
8 @copyright: 2004 Vito Miliano (vito_moinnewpagewithtemplate@perilith.com),
bb2e053067fb fixing copyright headers: remove umlauts (encoding troubles), make epydoc compatible, reformat
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1841
diff changeset
9 2004 by Nir Soffer <nirs@freeshell.org>,
bb2e053067fb fixing copyright headers: remove umlauts (encoding troubles), make epydoc compatible, reformat
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1841
diff changeset
10 2004 Alexander Schremmer <alex AT alexanderweb DOT de>,
3433
21d9d7529304 fixed docstring
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3432
diff changeset
11 2006-2008 MoinMoin:ReimarBauer
21d9d7529304 fixed docstring
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3432
diff changeset
12 2008 MoinMoin:RadomirDopieralski
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
13 @license: GNU GPL, see COPYING for details.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
14 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
15
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
16 from MoinMoin import wikiutil
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
17
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
18 Dependencies = ["language"]
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
19
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
20 class NewPage:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
21 """ NewPage - create new pages
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
22
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
23 Let you create new page using optional template, button text
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
24 and parent page (for automatic subpages).
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
25
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
26 Usage:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
27
2725
388204baf00f change [[macro]] to <<macro>> in all built-in markup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2286
diff changeset
28 <<NewPage(template, buttonLabel, parentPage)>>
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
29
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
30 Examples:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
31
2725
388204baf00f change [[macro]] to <<macro>> in all built-in markup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2286
diff changeset
32 <<NewPage>>
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
33
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
34 Create an input field with 'Create New Page' button. The new
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
35 page will not use a template.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
36
2725
388204baf00f change [[macro]] to <<macro>> in all built-in markup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2286
diff changeset
37 <<NewPage(BugTemplate, Create New Bug, MoinMoinBugs)>>
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
38
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
39 Create an input field with button labeled 'Create New
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
40 Bug'. The new page will use the BugTemplate template,
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
41 and create the page as a subpage of MoinMoinBugs.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
42 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
43
3377
4aeb96183e04 macro NewPage converted to the new arg parser
Radomir Dopieralski <moindev@sheep.art.pl>
parents: 3143
diff changeset
44 def __init__(self, macro, template=u'', button_label=u'',
4aeb96183e04 macro NewPage converted to the new arg parser
Radomir Dopieralski <moindev@sheep.art.pl>
parents: 3143
diff changeset
45 parent_page=u'', name_template=u'%s'):
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
46 self.macro = macro
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
47 self.request = macro.request
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
48 self.formatter = macro.formatter
3377
4aeb96183e04 macro NewPage converted to the new arg parser
Radomir Dopieralski <moindev@sheep.art.pl>
parents: 3143
diff changeset
49 self.template = template
4aeb96183e04 macro NewPage converted to the new arg parser
Radomir Dopieralski <moindev@sheep.art.pl>
parents: 3143
diff changeset
50 _ = self.request.getText
4aeb96183e04 macro NewPage converted to the new arg parser
Radomir Dopieralski <moindev@sheep.art.pl>
parents: 3143
diff changeset
51 if button_label:
4aeb96183e04 macro NewPage converted to the new arg parser
Radomir Dopieralski <moindev@sheep.art.pl>
parents: 3143
diff changeset
52 # Try to get a translation, this will probably not work in
4aeb96183e04 macro NewPage converted to the new arg parser
Radomir Dopieralski <moindev@sheep.art.pl>
parents: 3143
diff changeset
53 # most cases, but better than nothing.
4aeb96183e04 macro NewPage converted to the new arg parser
Radomir Dopieralski <moindev@sheep.art.pl>
parents: 3143
diff changeset
54 self.label = self.request.getText(button_label)
4aeb96183e04 macro NewPage converted to the new arg parser
Radomir Dopieralski <moindev@sheep.art.pl>
parents: 3143
diff changeset
55 else:
4aeb96183e04 macro NewPage converted to the new arg parser
Radomir Dopieralski <moindev@sheep.art.pl>
parents: 3143
diff changeset
56 self.label = _("Create New Page")
4aeb96183e04 macro NewPage converted to the new arg parser
Radomir Dopieralski <moindev@sheep.art.pl>
parents: 3143
diff changeset
57 if parent_page == '@ME' and self.request.user.valid:
4aeb96183e04 macro NewPage converted to the new arg parser
Radomir Dopieralski <moindev@sheep.art.pl>
parents: 3143
diff changeset
58 self.parent = self.request.user.name
4aeb96183e04 macro NewPage converted to the new arg parser
Radomir Dopieralski <moindev@sheep.art.pl>
parents: 3143
diff changeset
59 elif parent_page == '@SELF':
4aeb96183e04 macro NewPage converted to the new arg parser
Radomir Dopieralski <moindev@sheep.art.pl>
parents: 3143
diff changeset
60 self.parent = self.formatter.page.page_name
4aeb96183e04 macro NewPage converted to the new arg parser
Radomir Dopieralski <moindev@sheep.art.pl>
parents: 3143
diff changeset
61 else:
4aeb96183e04 macro NewPage converted to the new arg parser
Radomir Dopieralski <moindev@sheep.art.pl>
parents: 3143
diff changeset
62 self.parent = parent_page
4aeb96183e04 macro NewPage converted to the new arg parser
Radomir Dopieralski <moindev@sheep.art.pl>
parents: 3143
diff changeset
63 self.nametemplate = name_template
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
64
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
65 def renderInPage(self):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
66 """ Render macro in page context
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
67
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
68 The parser should decide what to do if this macro is placed in a
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
69 paragraph context.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
70 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
71 f = self.formatter
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
72 _ = self.request.getText
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
73
3377
4aeb96183e04 macro NewPage converted to the new arg parser
Radomir Dopieralski <moindev@sheep.art.pl>
parents: 3143
diff changeset
74 requires_input = '%s' in self.nametemplate
950
4eb66637ccd0 whitespace-only cleanup, small style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 882
diff changeset
75
4eb66637ccd0 whitespace-only cleanup, small style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 882
diff changeset
76
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
77 # TODO: better abstract this using the formatter
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
78 html = [
4235
a6c315ff8d66 Make more use of werkzeugs Href object for URL-generation in MoinMoin
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4168
diff changeset
79 u'<form class="macro" method="POST" action="%s"><div>' % self.request.href(self.formatter.page.page_name),
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
80 u'<input type="hidden" name="action" value="newpage">',
3377
4aeb96183e04 macro NewPage converted to the new arg parser
Radomir Dopieralski <moindev@sheep.art.pl>
parents: 3143
diff changeset
81 u'<input type="hidden" name="parent" value="%s">' % wikiutil.escape(self.parent, 1),
4aeb96183e04 macro NewPage converted to the new arg parser
Radomir Dopieralski <moindev@sheep.art.pl>
parents: 3143
diff changeset
82 u'<input type="hidden" name="template" value="%s">' % wikiutil.escape(self.template, 1),
4aeb96183e04 macro NewPage converted to the new arg parser
Radomir Dopieralski <moindev@sheep.art.pl>
parents: 3143
diff changeset
83 u'<input type="hidden" name="nametemplate" value="%s">' % wikiutil.escape(self.nametemplate, 1),
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
84 ]
950
4eb66637ccd0 whitespace-only cleanup, small style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 882
diff changeset
85
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
86 if requires_input:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
87 html += [
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
88 u'<input type="text" name="pagename" size="30">',
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
89 ]
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
90 html += [
3377
4aeb96183e04 macro NewPage converted to the new arg parser
Radomir Dopieralski <moindev@sheep.art.pl>
parents: 3143
diff changeset
91 u'<input type="submit" value="%s">' % wikiutil.escape(self.label, 1),
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
92 u'</div></form>',
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
93 ]
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
94 return self.formatter.rawHTML('\n'.join(html))
950
4eb66637ccd0 whitespace-only cleanup, small style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 882
diff changeset
95
3377
4aeb96183e04 macro NewPage converted to the new arg parser
Radomir Dopieralski <moindev@sheep.art.pl>
parents: 3143
diff changeset
96 def macro_NewPage(macro, template=u'', button_label=u'',
4aeb96183e04 macro NewPage converted to the new arg parser
Radomir Dopieralski <moindev@sheep.art.pl>
parents: 3143
diff changeset
97 parent_page=u'', name_template=u'%s'):
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
98 """ Temporary glue code to use with moin current macro system """
3377
4aeb96183e04 macro NewPage converted to the new arg parser
Radomir Dopieralski <moindev@sheep.art.pl>
parents: 3143
diff changeset
99 return NewPage(macro, template, button_label, parent_page, name_template).renderInPage()
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
100