Software Freedom Law Center

root/trunk/trac/sample-plugins/Timestamp.py

Revision 46, 1.1 kB (checked in by bkuhn, 11 months ago)

I am keeping a temporary fork of trac as I work on various changes to
it. I'll be coordinating with their mailing list soon.

Line 
1 """Inserts the current time (in seconds) into the wiki page."""
2
3 revision = "$Rev: 2 $"
4 url = "$URL: /mirror/sample-plugins/Timestamp.py $"
5
6 #
7 # The following shows the code for macro, old-style.
8 #
9 # The `execute` function serves no purpose other than to illustrate
10 # the example, it will not be used anymore.
11 #
12 # ---- (ignore in your own macro) ----
13 # --
14 import time # Trac before version 0.11 was using `time` module
15
16 def execute(hdf, txt, env):
17     t = time.localtime()
18     return "<b>%s</b>" % time.strftime('%c', t)
19 # --
20 # ---- (ignore in your own macro) ----
21
22
23 #
24 # The following is the converted new-style macro
25 #
26 # ---- (reuse for your own macro) ----
27 # --
28 from datetime import datetime
29 # Note: since Trac 0.11, datetime objects are used internally
30
31 from genshi.builder import tag
32
33 from trac.util.datefmt import format_datetime, utc
34 from trac.wiki.macros import WikiMacroBase
35
36 class TimestampMacro(WikiMacroBase):
37     """Inserts the current time (in seconds) into the wiki page."""
38
39     def expand_macro(self, formatter, name, args):
40         t = datetime.now(utc)
41         return tag.b(format_datetime(t, '%c'))
42 # --
43 # ---- (reuse for your own macro) ----
Note: See TracBrowser for help on using the browser.

SFLC Main Page

[frdm] Support SFLC