annotate data/plugin/macro/CycleContent.py @ 653:127da830be6c

updated copyright
author Reimar Bauer <rb.proj AT googlemail DOT com>
date Tue, 19 Apr 2016 16:29:54 +0200
parents 6e5f50c5855f
children
rev   line source
462
b421f10f67b9 macro CycleContent: Cycles by the refresh rate given on the page where it is called through a page list.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
1 # -*- coding: iso-8859-1 -*-
b421f10f67b9 macro CycleContent: Cycles by the refresh rate given on the page where it is called through a page list.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
2 """
b421f10f67b9 macro CycleContent: Cycles by the refresh rate given on the page where it is called through a page list.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
3 MoinMoin - Cylce Content Macro
b421f10f67b9 macro CycleContent: Cycles by the refresh rate given on the page where it is called through a page list.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
4
467
6e5f50c5855f PEP8 whitespace cleanup
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 463
diff changeset
5 Selects a pagename from CycleContent or a given page and cycles
462
b421f10f67b9 macro CycleContent: Cycles by the refresh rate given on the page where it is called through a page list.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
6 it by the refresh rate given on the page e.g. #refresh 5 ExamplePage
467
6e5f50c5855f PEP8 whitespace cleanup
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 463
diff changeset
7 For an attachment from a cycled page of name MyPage use an absolute
462
b421f10f67b9 macro CycleContent: Cycles by the refresh rate given on the page where it is called through a page list.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
8 name for the attachment e.g. {{attachment:MyPage/image.png}}
b421f10f67b9 macro CycleContent: Cycles by the refresh rate given on the page where it is called through a page list.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
9
b421f10f67b9 macro CycleContent: Cycles by the refresh rate given on the page where it is called through a page list.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
10 Usage:
b421f10f67b9 macro CycleContent: Cycles by the refresh rate given on the page where it is called through a page list.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
11 <<CycleContent()>>
b421f10f67b9 macro CycleContent: Cycles by the refresh rate given on the page where it is called through a page list.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
12 <<CycleContent(CycleContent)>>
b421f10f67b9 macro CycleContent: Cycles by the refresh rate given on the page where it is called through a page list.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
13
b421f10f67b9 macro CycleContent: Cycles by the refresh rate given on the page where it is called through a page list.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
14 Comments:
b421f10f67b9 macro CycleContent: Cycles by the refresh rate given on the page where it is called through a page list.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
15 It will look for list delimiters on the page in question.
b421f10f67b9 macro CycleContent: Cycles by the refresh rate given on the page where it is called through a page list.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
16 It will ignore anything that is not in an "*" list.
b421f10f67b9 macro CycleContent: Cycles by the refresh rate given on the page where it is called through a page list.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
17
b421f10f67b9 macro CycleContent: Cycles by the refresh rate given on the page where it is called through a page list.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
18 @copyright: 2002-2004 Juergen Hermann <jh@web.de>
653
127da830be6c updated copyright
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 467
diff changeset
19 2009-2016 MoinMoin:ReimarBauer
462
b421f10f67b9 macro CycleContent: Cycles by the refresh rate given on the page where it is called through a page list.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
20 @license: GNU GPL, see COPYING for details.
b421f10f67b9 macro CycleContent: Cycles by the refresh rate given on the page where it is called through a page list.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
21
b421f10f67b9 macro CycleContent: Cycles by the refresh rate given on the page where it is called through a page list.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
22 Based on RandomQuote
b421f10f67b9 macro CycleContent: Cycles by the refresh rate given on the page where it is called through a page list.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
23 Originally written by Thomas Waldmann.
b421f10f67b9 macro CycleContent: Cycles by the refresh rate given on the page where it is called through a page list.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
24 Gustavo Niemeyer added wiki markup parsing of the quotes.
467
6e5f50c5855f PEP8 whitespace cleanup
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 463
diff changeset
25
462
b421f10f67b9 macro CycleContent: Cycles by the refresh rate given on the page where it is called through a page list.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
26 """
b421f10f67b9 macro CycleContent: Cycles by the refresh rate given on the page where it is called through a page list.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
27 from MoinMoin.action import cache
b421f10f67b9 macro CycleContent: Cycles by the refresh rate given on the page where it is called through a page list.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
28 from MoinMoin.Page import Page
b421f10f67b9 macro CycleContent: Cycles by the refresh rate given on the page where it is called through a page list.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
29
b421f10f67b9 macro CycleContent: Cycles by the refresh rate given on the page where it is called through a page list.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
30 Dependencies = ["time"]
b421f10f67b9 macro CycleContent: Cycles by the refresh rate given on the page where it is called through a page list.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
31
b421f10f67b9 macro CycleContent: Cycles by the refresh rate given on the page where it is called through a page list.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
32 def macro_CycleContent(macro, pagename=u'CycleContent'):
b421f10f67b9 macro CycleContent: Cycles by the refresh rate given on the page where it is called through a page list.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
33 """
463
959817d46551 macro CycleContent: update of doc string
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 462
diff changeset
34 Macro for cycling content of other pages on the page where it is called from.
959817d46551 macro CycleContent: update of doc string
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 462
diff changeset
35 That also can be used for slide shows and also without a refresh rate
959817d46551 macro CycleContent: update of doc string
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 462
diff changeset
36 because each request cycles.
959817d46551 macro CycleContent: update of doc string
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 462
diff changeset
37
959817d46551 macro CycleContent: update of doc string
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 462
diff changeset
38 @param pagename: the pagename for the list to cycle through.
462
b421f10f67b9 macro CycleContent: Cycles by the refresh rate given on the page where it is called through a page list.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
39 """
b421f10f67b9 macro CycleContent: Cycles by the refresh rate given on the page where it is called through a page list.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
40 request = macro.request
b421f10f67b9 macro CycleContent: Cycles by the refresh rate given on the page where it is called through a page list.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
41 _ = request.getText
b421f10f67b9 macro CycleContent: Cycles by the refresh rate given on the page where it is called through a page list.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
42
b421f10f67b9 macro CycleContent: Cycles by the refresh rate given on the page where it is called through a page list.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
43 if request.user.may.read(pagename):
b421f10f67b9 macro CycleContent: Cycles by the refresh rate given on the page where it is called through a page list.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
44 page = Page(request, pagename)
b421f10f67b9 macro CycleContent: Cycles by the refresh rate given on the page where it is called through a page list.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
45 raw = page.get_raw_body()
b421f10f67b9 macro CycleContent: Cycles by the refresh rate given on the page where it is called through a page list.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
46 else:
b421f10f67b9 macro CycleContent: Cycles by the refresh rate given on the page where it is called through a page list.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
47 raw = ""
b421f10f67b9 macro CycleContent: Cycles by the refresh rate given on the page where it is called through a page list.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
48
b421f10f67b9 macro CycleContent: Cycles by the refresh rate given on the page where it is called through a page list.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
49 username = request.user.name or 'Anonymous'
b421f10f67b9 macro CycleContent: Cycles by the refresh rate given on the page where it is called through a page list.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
50 # this selects lines looking like a list item
b421f10f67b9 macro CycleContent: Cycles by the refresh rate given on the page where it is called through a page list.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
51 quotes = raw.splitlines()
b421f10f67b9 macro CycleContent: Cycles by the refresh rate given on the page where it is called through a page list.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
52 quotes = [quote.strip() for quote in quotes]
b421f10f67b9 macro CycleContent: Cycles by the refresh rate given on the page where it is called through a page list.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
53 quotes = [quote[2:] for quote in quotes if quote.startswith('* ')]
b421f10f67b9 macro CycleContent: Cycles by the refresh rate given on the page where it is called through a page list.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
54 if not quotes:
b421f10f67b9 macro CycleContent: Cycles by the refresh rate given on the page where it is called through a page list.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
55 return (macro.formatter.highlight(1) +
b421f10f67b9 macro CycleContent: Cycles by the refresh rate given on the page where it is called through a page list.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
56 _('No quotes on %(pagename)s.') % {'pagename': pagename} +
b421f10f67b9 macro CycleContent: Cycles by the refresh rate given on the page where it is called through a page list.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
57 macro.formatter.highlight(0))
b421f10f67b9 macro CycleContent: Cycles by the refresh rate given on the page where it is called through a page list.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
58
b421f10f67b9 macro CycleContent: Cycles by the refresh rate given on the page where it is called through a page list.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
59 content_type = 'text/plain'
b421f10f67b9 macro CycleContent: Cycles by the refresh rate given on the page where it is called through a page list.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
60 key = '%s_%s_%s_CycleContent' % (content_type.replace('/', '_'),
b421f10f67b9 macro CycleContent: Cycles by the refresh rate given on the page where it is called through a page list.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
61 pagename, username)
b421f10f67b9 macro CycleContent: Cycles by the refresh rate given on the page where it is called through a page list.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
62 if not cache.exists(request, key):
b421f10f67b9 macro CycleContent: Cycles by the refresh rate given on the page where it is called through a page list.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
63 index = 0
b421f10f67b9 macro CycleContent: Cycles by the refresh rate given on the page where it is called through a page list.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
64 cache.put(request, key, str(index + 1), content_type=content_type)
b421f10f67b9 macro CycleContent: Cycles by the refresh rate given on the page where it is called through a page list.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
65 else:
b421f10f67b9 macro CycleContent: Cycles by the refresh rate given on the page where it is called through a page list.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
66 # may be I want a cache.get method
b421f10f67b9 macro CycleContent: Cycles by the refresh rate given on the page where it is called through a page list.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
67 index = int(cache._get_datafile(request, key).read()) + 1
b421f10f67b9 macro CycleContent: Cycles by the refresh rate given on the page where it is called through a page list.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
68 if index + 1 > len(quotes):
b421f10f67b9 macro CycleContent: Cycles by the refresh rate given on the page where it is called through a page list.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
69 cache.put(request, key, '0', content_type=content_type)
b421f10f67b9 macro CycleContent: Cycles by the refresh rate given on the page where it is called through a page list.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
70 index = 0
b421f10f67b9 macro CycleContent: Cycles by the refresh rate given on the page where it is called through a page list.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
71 else:
b421f10f67b9 macro CycleContent: Cycles by the refresh rate given on the page where it is called through a page list.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
72 cache.put(request, key, str(index), content_type=content_type)
b421f10f67b9 macro CycleContent: Cycles by the refresh rate given on the page where it is called through a page list.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
73
b421f10f67b9 macro CycleContent: Cycles by the refresh rate given on the page where it is called through a page list.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
74 quote = quotes[index]
b421f10f67b9 macro CycleContent: Cycles by the refresh rate given on the page where it is called through a page list.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
75 if quote.startswith('[[') and quote.endswith(']]'):
b421f10f67b9 macro CycleContent: Cycles by the refresh rate given on the page where it is called through a page list.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
76 quote = quote[2:-2]
b421f10f67b9 macro CycleContent: Cycles by the refresh rate given on the page where it is called through a page list.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
77 page.set_raw_body(Page(request, quote).get_raw_body(), 1)
b421f10f67b9 macro CycleContent: Cycles by the refresh rate given on the page where it is called through a page list.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
78 quote = request.redirectedOutput(page.send_page,
b421f10f67b9 macro CycleContent: Cycles by the refresh rate given on the page where it is called through a page list.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
79 content_only=1, content_id="CycleContent")
b421f10f67b9 macro CycleContent: Cycles by the refresh rate given on the page where it is called through a page list.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
80
b421f10f67b9 macro CycleContent: Cycles by the refresh rate given on the page where it is called through a page list.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
81 return quote
467
6e5f50c5855f PEP8 whitespace cleanup
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 463
diff changeset
82