代码之家  ›  专栏  ›  技术社区  ›  stanleyxu2005

如何在trac中运行自己的python脚本

  •  0
  • stanleyxu2005  · 技术社区  · 15 年前

    我想自定义项目页面(trac/templates/index.html)。

    我想使用一个表来显示更多特定于项目的信息。例如,每个项目的管理列表,每个项目的构建状态。这些信息存储在TRAC的数据库中。

    恐怕默认的模板引擎无法向我提供这些信息。至少我没有从它的文档中发现任何有价值的东西。

    所以我决定编写一个python脚本(在服务器端),将这些信息生成为JSON字符串。我还注入了一个块JavaScript,通过使用Ajax从这个python脚本中获取JSON。

    但是我不知道如何让我的python脚本由trac解释。

    有人能帮我吗?

    2 回复  |  直到 15 年前
        1
  •  1
  •   rlotun    15 年前

    我通过添加一个 iframe 到所有TRAC项目页面的顶部。你可以通过 templates 目录,并添加一个 site.html 文件。

    我有点像:

     <html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:py="http://genshi.edgewall.org/" py:strip="">
      <!--! Custom match templates go here -->
      <head py:match="head" py:attrs="select('@*')">
          ${select('*|comment()|text()[local-name()!="script"]')}
          <link rel="stylesheet" type="text/css" href="http://mysite.com/nav.css" />
      </head>
    
    <body py:match="body" py:attrs="select('@*')">
         <iframe src ="http://mysite.com/nav.html"
                     width="100%"
                     id="navbar-iframe"
                     height="30px"
                     frameborder="0"
                     marginheight="0"
                     scrolling="no"
                     marginwidth="0">
                 </iframe>
        <div id="tdtracbody">
            ${select('*|text()')}
        </div>
        </body>
    </html>
    
        2
  •  1
  •   CuriousCurmudgeon    15 年前

    trac扩展API允许您截取任意页面并插入新数据。例如,batchModifyPlugin会截获请求并向自定义查询页面添加内容。请参阅中的itemplatestreamfilter方法 http://trac-hacks.org/browser/batchmodifyplugin/0.11/trunk/batchmod/web_ui.py 查看trac hacks网站了解更多示例。