Edgewall Software

source: tags/trac-1.0.2/sample-plugins/Timestamp.py

Last change on this file was 12743, checked in by Ryan J Ollos, 9 years ago

1.0.2dev: Replaced b tags with strong tags. Refs #11598.

  • Property svn:eol-style set to native
  • Property svn:keywords set to LastChangedRevision HeadURL
File size: 1.7 KB
Line 
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
17revision = "$Rev: 12743 $"
18url = "$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# --
28import time # Trac before version 0.11 was using `time` module
29
30def 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# --
42from datetime import datetime
43# Note: since Trac 0.11, datetime objects are used internally
44
45from genshi.builder import tag
46
47from trac.util.datefmt import format_datetime, utc
48from trac.wiki.macros import WikiMacroBase
49
50class 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) ----
Note: See TracBrowser for help on using the repository browser.