1 | # -*- coding: utf-8 -*-
|
---|
2 | #
|
---|
3 | # Copyright (C) 2007-2013 Edgewall Software
|
---|
4 | # Copyright (C) 2007 Christian Boos <cboos@edgewall.org>
|
---|
5 | # All rights reserved.
|
---|
6 | #
|
---|
7 | # This software is licensed as described in the file COPYING, which
|
---|
8 | # you should have received as part of this distribution. The terms
|
---|
9 | # are also available at http://trac.edgewall.com/license.html.
|
---|
10 | #
|
---|
11 | # This software consists of voluntary contributions made by many
|
---|
12 | # individuals. For the exact contribution history, see the revision
|
---|
13 | # history and logs, available at http://trac.edgewall.org/.
|
---|
14 |
|
---|
15 | """Inserts the current time (in seconds) into the wiki page."""
|
---|
16 |
|
---|
17 | revision = "$Rev: 12743 $"
|
---|
18 | url = "$URL: //svn.edgewall.org/repos/trac/tags/trac-1.0.2/sample-plugins/Timestamp.py $"
|
---|
19 |
|
---|
20 | #
|
---|
21 | # The following shows the code for macro, old-style.
|
---|
22 | #
|
---|
23 | # The `execute` function serves no purpose other than to illustrate
|
---|
24 | # the example, it will not be used anymore.
|
---|
25 | #
|
---|
26 | # ---- (ignore in your own macro) ----
|
---|
27 | # --
|
---|
28 | import time # Trac before version 0.11 was using `time` module
|
---|
29 |
|
---|
30 | def execute(hdf, txt, env):
|
---|
31 | t = time.localtime()
|
---|
32 | return "<b>%s</b>" % time.strftime('%c', t)
|
---|
33 | # --
|
---|
34 | # ---- (ignore in your own macro) ----
|
---|
35 |
|
---|
36 |
|
---|
37 | #
|
---|
38 | # The following is the converted new-style macro
|
---|
39 | #
|
---|
40 | # ---- (reuse for your own macro) ----
|
---|
41 | # --
|
---|
42 | from datetime import datetime
|
---|
43 | # Note: since Trac 0.11, datetime objects are used internally
|
---|
44 |
|
---|
45 | from genshi.builder import tag
|
---|
46 |
|
---|
47 | from trac.util.datefmt import format_datetime, utc
|
---|
48 | from trac.wiki.macros import WikiMacroBase
|
---|
49 |
|
---|
50 | class TimestampMacro(WikiMacroBase):
|
---|
51 | _description = "Inserts the current time (in seconds) into the wiki page."
|
---|
52 |
|
---|
53 | def expand_macro(self, formatter, name, content, args=None):
|
---|
54 | t = datetime.now(utc)
|
---|
55 | return tag.strong(format_datetime(t, '%c'))
|
---|
56 | # --
|
---|
57 | # ---- (reuse for your own macro) ----
|
---|