annotate MoinMoin/macro/NewPage.py @ 3377:4aeb96183e04

macro NewPage converted to the new arg parser
author Radomir Dopieralski <moindev@sheep.art.pl>
date Thu, 20 Mar 2008 22:50:41 +0100
parents 16ae95df840a
children 0b56ed4808a6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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>,
bb2e053067fb fixing copyright headers: remove umlauts (encoding troubles), make epydoc compatible, reformat
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1841
diff changeset
11 2006 MoinMoin:ReimarBauer
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
12 @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
13 """
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 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
16
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
17 Dependencies = ["language"]
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
18
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
19 class NewPage:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
20 """ 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
21
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
22 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
23 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
24
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
25 Usage:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
26
2725
388204baf00f change [[macro]] to <<macro>> in all built-in markup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2286
diff changeset
27 <<NewPage(template, buttonLabel, parentPage)>>
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
28
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
29 Examples:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
30
2725
388204baf00f change [[macro]] to <<macro>> in all built-in markup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2286
diff changeset
31 <<NewPage>>
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
32
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
33 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
34 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
35
2725
388204baf00f change [[macro]] to <<macro>> in all built-in markup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2286
diff changeset
36 <<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
37
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
38 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
39 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
40 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
41 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
42
3377
4aeb96183e04 macro NewPage converted to the new arg parser
Radomir Dopieralski <moindev@sheep.art.pl>
parents: 3143
diff changeset
43 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
44 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
45 self.macro = macro
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
46 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
47 self.formatter = macro.formatter
3377
4aeb96183e04 macro NewPage converted to the new arg parser
Radomir Dopieralski <moindev@sheep.art.pl>
parents: 3143
diff changeset
48 self.template = template
4aeb96183e04 macro NewPage converted to the new arg parser
Radomir Dopieralski <moindev@sheep.art.pl>
parents: 3143
diff changeset
49 _ = self.request.getText
4aeb96183e04 macro NewPage converted to the new arg parser
Radomir Dopieralski <moindev@sheep.art.pl>
parents: 3143
diff changeset
50 if button_label:
4aeb96183e04 macro NewPage converted to the new arg parser
Radomir Dopieralski <moindev@sheep.art.pl>
parents: 3143
diff changeset
51 # 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
52 # 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
53 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
54 else:
4aeb96183e04 macro NewPage converted to the new arg parser
Radomir Dopieralski <moindev@sheep.art.pl>
parents: 3143
diff changeset
55 self.label = _("Create New Page")
4aeb96183e04 macro NewPage converted to the new arg parser
Radomir Dopieralski <moindev@sheep.art.pl>
parents: 3143
diff changeset
56 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
57 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
58 elif parent_page == '@SELF':
4aeb96183e04 macro NewPage converted to the new arg parser
Radomir Dopieralski <moindev@sheep.art.pl>
parents: 3143
diff changeset
59 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
60 else:
4aeb96183e04 macro NewPage converted to the new arg parser
Radomir Dopieralski <moindev@sheep.art.pl>
parents: 3143
diff changeset
61 self.parent = parent_page
4aeb96183e04 macro NewPage converted to the new arg parser
Radomir Dopieralski <moindev@sheep.art.pl>
parents: 3143
diff changeset
62 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
63
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
64 def renderInPage(self):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
65 """ 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
66
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
67 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
68 paragraph context.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
69 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
70 f = self.formatter
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
71 _ = self.request.getText
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
72
3377
4aeb96183e04 macro NewPage converted to the new arg parser
Radomir Dopieralski <moindev@sheep.art.pl>
parents: 3143
diff changeset
73 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
74
4eb66637ccd0 whitespace-only cleanup, small style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 882
diff changeset
75
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
76 # 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
77 html = [
3040
8608b258f8e6 bug fix of MoinMoinBugs/MoveAttachmentNotWorkingWithModPython (thanks to Boleslaw Kulbabinski) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2725
diff changeset
78 u'<form class="macro" method="get" action="%s/%s"><div>' % (self.request.getScriptname(), wikiutil.quoteWikinameURL(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
79 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
80 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
81 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
82 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
83 ]
950
4eb66637ccd0 whitespace-only cleanup, small style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 882
diff changeset
84
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
85 if requires_input:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
86 html += [
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
87 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
88 ]
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
89 html += [
3377
4aeb96183e04 macro NewPage converted to the new arg parser
Radomir Dopieralski <moindev@sheep.art.pl>
parents: 3143
diff changeset
90 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
91 u'</div></form>',
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
92 ]
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
93 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
94
3377
4aeb96183e04 macro NewPage converted to the new arg parser
Radomir Dopieralski <moindev@sheep.art.pl>
parents: 3143
diff changeset
95 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
96 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
97 """ 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
98 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
99