【问题标题】:How to run own python script in Trac如何在 Trac 中运行自己的 python 脚本
【发布时间】:2010-05-11 09:06:28
【问题描述】:

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

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

我担心默认模板引擎无法给我那里的信息。至少我从它的文档中没有发现任何有价值的东西。

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

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

谁能帮帮我?

【问题讨论】:

    标签: python interface trac customization


    【解决方案1】:

    我通过在所有 trac 项目页面的顶部添加 iframe 以更简单的方式自定义了 trac。您可以通过转到 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】:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2017-07-28
        • 1970-01-01
        • 2022-10-26
        • 2012-11-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多