Search code examples
trac

Organise Trac's 'Available Projects' page


Does anyone know how to split the list of projects on the 'Available Projects' page into a list of active and archived projects? At the moment they are all listed together and I have a large number of projects so it is difficult to identify just the active projects.

I'm not a web developer or python expert so I would appreciate simple, easy-to-follow answers.

Thanks in advance.


Solution

  • The project index can be customized. You'll need a criteria for grouping the projects into active and archived. Here you can see the variables that are listed for each project. You could add a value in the config/trac.ini file for each project, such as [project] archived = true, and read that value when rendering the project index in order to determine which group to list the project in - active vs. archived. The value can be read using env.config.get('project', 'archived').

    Here is a proof-of-concept.

    Create 4 projects and set 2 of them as archived:

    $ mkdir projects && cd projects
    $ virtualenv pve
    $ source pve/bin/activate
    $ pip install trac
    $ mkdir environments && cd environments
    $ for i in `seq 1 4`; do
        trac-admin env$i initenv "Project $i" sqlite:db/trac.db
      done
    $ trac-admin env3 config set project archived true
    $ trac-admin env4 config set project archived true
    

    Add the following in projects/index.html:

    <!DOCTYPE html
        PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml"
          xmlns:py="http://genshi.edgewall.org/"
          xmlns:xi="http://www.w3.org/2001/XInclude">
      <head>
        <title>Available Projects</title>
      </head>
      <body>
        <h1>Active Projects</h1>
        <ul>
          <li py:for="project in projects"
              py:if="not project.env.config.get('project', 'archived')"
              py:choose="">
            <a py:when="project.href" href="$project.href"
               title="$project.description">$project.name</a>
            <py:otherwise>
              <small>$project.name: <em>Error</em> <br /> ($project.description)</small>
            </py:otherwise>
          </li>
        </ul>
        <h1>Archived Projects</h1>
        <ul>
          <li py:for="project in projects"
              py:if="project.env.config.get('project', 'archived')"
              py:choose="">
            <a py:when="project.href" href="$project.href"
               title="$project.description">$project.name</a>
            <py:otherwise>
              <small>$project.name: <em>Error</em> <br /> ($project.description)</small>
            </py:otherwise>
          </li>
        </ul>
      </body>
    </html>
    

    Run TracStandalone:

    $ cd projects
    $ TRAC_ENV_INDEX_TEMPLATE=`pwd`/index.html tracd -r -p 8001 --env-parent-dir=environments
    

    The result is:

    Project Index