<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Customising Roundup &mdash; Roundup v1.4 documentation</title> <link rel="stylesheet" href="_static/style.css" type="text/css" /> <link rel="stylesheet" href="_static/pygments.css" type="text/css" /> <script type="text/javascript"> var DOCUMENTATION_OPTIONS = { URL_ROOT: '#', VERSION: '1.4', COLLAPSE_MODINDEX: false, FILE_SUFFIX: '.html' }; </script> <script type="text/javascript" src="_static/jquery.js"></script> <script type="text/javascript" src="_static/doctools.js"></script> <link rel="index" title="Index" href="genindex.html" /> <link rel="search" title="Search" href="search.html" /> <link rel="top" title="Roundup v1.4 documentation" href="index.html" /> <link rel="next" title="Administration Guide" href="admin_guide.html" /> <link rel="prev" title="User Guide" href="user_guide.html" /> </head> <body> <div class="header"><h1>Roundup</h1> <div id="searchbox" style="display: none"> <form class="search" action="search.html" method="get"> <input type="text" name="q" size="18" /> <input type="submit" value="Search" /> <input type="hidden" name="check_keywords" value="yes" /> <input type="hidden" name="area" value="default" /> </form> </div> <script type="text/javascript">$('#searchbox').show(0);</script> </div> <div class="navigation"> <div class="menu"> <h3><a href="index.html">Table Of Contents</a></h3> <ul> <li><a class="reference external" href="#">Customising Roundup</a><ul> <li><a class="reference external" href="#what-you-can-do">What You Can Do</a></li> <li><a class="reference external" href="#trackers-in-a-nutshell">Trackers in a Nutshell</a></li> <li><a class="reference external" href="#tracker-configuration">Tracker Configuration</a></li> <li><a class="reference external" href="#tracker-schema">Tracker Schema</a></li> <li><a class="reference external" href="#detectors-adding-behaviour-to-your-tracker">Detectors - adding behaviour to your tracker</a></li> <li><a class="reference external" href="#database-content">Database Content</a></li> <li><a class="reference external" href="#security-access-controls">Security / Access Controls</a></li> <li><a class="reference external" href="#web-interface">Web Interface</a></li> <li><a class="reference external" href="#examples">Examples</a></li> <li><a class="reference external" href="#debugging-trackers">Debugging Trackers</a></li> </ul> </li> </ul> <h4>Previous topic</h4> <p class="topless"><a href="user_guide.html" title="previous chapter">User Guide</a></p> <h4>Next topic</h4> <p class="topless"><a href="admin_guide.html" title="next chapter">Administration Guide</a></p> <h3>This Page</h3> <ul class="this-page-menu"> <li><a href="_sources/customizing.txt" rel="nofollow">Show Source</a></li> </ul> <div id="searchbox" style="display: none"> <h3>Quick search</h3> <form class="search" action="search.html" method="get"> <input type="text" name="q" size="18" /> <input type="submit" value="Go" /> <input type="hidden" name="check_keywords" value="yes" /> <input type="hidden" name="area" value="default" /> </form> <p style="font-size: 90%">Enter search terms or a module, class or function name.</p> </div> <script type="text/javascript">$('#searchbox').show(0);</script> </div> </div> <div class="content"> <div class="related related-top"> <ul> <li class="right" style="margin-right: 10px"> <a href="genindex.html" title="General Index" accesskey="I">index</a></li> <li class="right" > <a href="admin_guide.html" title="Administration Guide" accesskey="N">next</a></li> <li class="right" > <a href="user_guide.html" title="User Guide" accesskey="P">previous</a></li> <li><a href="index.html">Roundup v1.4 documentation</a></li> </ul> </div> <div class="section" id="customising-roundup"> <h1><a class="toc-backref" href="#id6">Customising Roundup</a></h1> <div class="contents topic" id="contents"> <p class="topic-title first">Contents</p> <ul class="simple"> <li><a class="reference internal" href="#customising-roundup" id="id6">Customising Roundup</a></li> </ul> </div> <div class="section" id="what-you-can-do"> <h2>What You Can Do</h2> <p>Before you get too far, it’s probably worth having a quick read of the Roundup <a class="reference external" href="design.html">design documentation</a>.</p> <p>Customisation of Roundup can take one of six forms:</p> <ol class="arabic simple"> <li><a class="reference internal" href="#tracker-configuration">tracker configuration</a> changes</li> <li>database, or <a class="reference internal" href="#tracker-schema">tracker schema</a> changes</li> <li>“definition” class <a class="reference internal" href="#database-content">database content</a> changes</li> <li>behavioural changes, through <a class="reference internal" href="#detectors">detectors</a></li> <li><a class="reference internal" href="#security-access-controls">security / access controls</a></li> <li>change the <a class="reference internal" href="#web-interface">web interface</a></li> </ol> <p>The third case is special because it takes two distinctly different forms depending upon whether the tracker has been initialised or not. The other two may be done at any time, before or after tracker initialisation. Yes, this includes adding or removing properties from classes.</p> </div> <div class="section" id="trackers-in-a-nutshell"> <h2>Trackers in a Nutshell</h2> <p>Trackers have the following structure:</p> <table border="1" class="docutils"> <colgroup> <col width="25%" /> <col width="75%" /> </colgroup> <thead valign="bottom"> <tr><th class="head">Tracker File</th> <th class="head">Description</th> </tr> </thead> <tbody valign="top"> <tr><td>config.ini</td> <td>Holds the basic <a class="reference internal" href="#tracker-configuration">tracker configuration</a></td> </tr> <tr><td>schema.py</td> <td>Holds the <a class="reference internal" href="#tracker-schema">tracker schema</a></td> </tr> <tr><td>initial_data.py</td> <td>Holds any data to be entered into the database when the tracker is initialised.</td> </tr> <tr><td>db/</td> <td>Holds the tracker’s database</td> </tr> <tr><td>db/files/</td> <td>Holds the tracker’s upload files and messages</td> </tr> <tr><td>db/backend_name</td> <td>Names the database back-end for the tracker</td> </tr> <tr><td>detectors/</td> <td>Auditors and reactors for this tracker</td> </tr> <tr><td>extensions/</td> <td>Additional web actions and templating utilities.</td> </tr> <tr><td>html/</td> <td>Web interface templates, images and style sheets</td> </tr> <tr><td>lib/</td> <td>optional common imports for detectors and extensions</td> </tr> </tbody> </table> </div> <div class="section" id="tracker-configuration"> <h2>Tracker Configuration</h2> <p>The <tt class="docutils literal"><span class="pre">config.ini</span></tt> located in your tracker home contains the basic configuration for the web and e-mail components of roundup’s interfaces.</p> <p>Changes to the data captured by your tracker is controlled by the <a class="reference internal" href="#tracker-schema">tracker schema</a>. Some configuration is also performed using permissions - see the <a class="reference internal" href="#security-access-controls">security / access controls</a> section. For example, to allow users to automatically register through the email interface, you must grant the “Anonymous” Role the “Email Access” Permission.</p> <p>The following is taken from the <a class="reference external" href="http://docs.python.org/lib/module-ConfigParser.html">Python Library Reference</a> (May 20, 2004) section “ConfigParser – Configuration file parser”:</p> <blockquote> <p>The configuration file consists of sections, led by a “[section]” header and followed by “name = value” entries, with line continuations on a newline with leading whitespace. Note that leading whitespace is removed from values. The optional values can contain format strings which refer to other values in the same section. Lines beginning with “#” or “;” are ignored and may be used to provide comments.</p> <p>For example:</p> <div class="highlight-python"><pre>[My Section] foodir = %(dir)s/whatever dir = frob</pre> </div> <p>would resolve the “%(dir)s” to the value of “dir” (“frob” in this case) resulting in “foodir” being “frob/whatever”.</p> </blockquote> <dl class="docutils"> <dt>Section <strong>main</strong></dt> <dd><dl class="first last docutils"> <dt>database – <tt class="docutils literal"><span class="pre">db</span></tt></dt> <dd>Database directory path. The path may be either absolute or relative to the directory containig this config file.</dd> <dt>templates – <tt class="docutils literal"><span class="pre">html</span></tt></dt> <dd>Path to the HTML templates directory. The path may be either absolute or relative to the directory containig this config file.</dd> <dt>static_files – default <em>blank</em></dt> <dd>Path to directory holding additional static files available via Web UI. This directory may contain sitewide images, CSS stylesheets etc. and is searched for these files prior to the TEMPLATES directory specified above. If this option is not set, all static files are taken from the TEMPLATES directory The path may be either absolute or relative to the directory containig this config file.</dd> <dt>admin_email – <tt class="docutils literal"><span class="pre">roundup-admin</span></tt></dt> <dd>Email address that roundup will complain to if it runs into trouble. If the email address doesn’t contain an <tt class="docutils literal"><span class="pre">@</span></tt> part, the MAIL_DOMAIN defined below is used.</dd> <dt>dispatcher_email – <tt class="docutils literal"><span class="pre">roundup-admin</span></tt></dt> <dd>The ‘dispatcher’ is a role that can get notified of new items to the database. It is used by the ERROR_MESSAGES_TO config setting. If the email address doesn’t contain an <tt class="docutils literal"><span class="pre">@</span></tt> part, the MAIL_DOMAIN defined below is used.</dd> <dt>email_from_tag – default <em>blank</em></dt> <dd>Additional text to include in the “name” part of the From: address used in nosy messages. If the sending user is “Foo Bar”, the From: line is usually: <tt class="docutils literal"><span class="pre">"Foo</span> <span class="pre">Bar"</span> <span class="pre"><issue_tracker@tracker.example></span></tt> the EMAIL_FROM_TAG goes inside the “Foo Bar” quotes like so: <tt class="docutils literal"><span class="pre">"Foo</span> <span class="pre">Bar</span> <span class="pre">EMAIL_FROM_TAG"</span> <span class="pre"><issue_tracker@tracker.example></span></tt></dd> <dt>new_web_user_roles – <tt class="docutils literal"><span class="pre">User</span></tt></dt> <dd>Roles that a user gets when they register with Web User Interface. This is a comma-separated list of role names (e.g. <tt class="docutils literal"><span class="pre">Admin,User</span></tt>).</dd> <dt>new_email_user_roles – <tt class="docutils literal"><span class="pre">User</span></tt></dt> <dd>Roles that a user gets when they register with Email Gateway. This is a comma-separated string of role names (e.g. <tt class="docutils literal"><span class="pre">Admin,User</span></tt>).</dd> <dt>error_messages_to – <tt class="docutils literal"><span class="pre">user</span></tt></dt> <dd>Send error message emails to the <tt class="docutils literal"><span class="pre">dispatcher</span></tt>, <tt class="docutils literal"><span class="pre">user</span></tt>, or <tt class="docutils literal"><span class="pre">both</span></tt>? The dispatcher is configured using the DISPATCHER_EMAIL setting. Allowed values: <tt class="docutils literal"><span class="pre">dispatcher</span></tt>, <tt class="docutils literal"><span class="pre">user</span></tt>, or <tt class="docutils literal"><span class="pre">both</span></tt></dd> <dt>html_version – <tt class="docutils literal"><span class="pre">html4</span></tt></dt> <dd>HTML version to generate. The templates are <tt class="docutils literal"><span class="pre">html4</span></tt> by default. If you wish to make them xhtml, then you’ll need to change this var to <tt class="docutils literal"><span class="pre">xhtml</span></tt> too so all auto-generated HTML is compliant. Allowed values: <tt class="docutils literal"><span class="pre">html4</span></tt>, <tt class="docutils literal"><span class="pre">xhtml</span></tt></dd> <dt>timezone – <tt class="docutils literal"><span class="pre">0</span></tt></dt> <dd>Numeric timezone offset used when users do not choose their own in their settings.</dd> <dt>instant_registration – <tt class="docutils literal"><span class="pre">yes</span></tt></dt> <dd>Register new users instantly, or require confirmation via email? Allowed values: <tt class="docutils literal"><span class="pre">yes</span></tt>, <tt class="docutils literal"><span class="pre">no</span></tt></dd> <dt>email_registration_confirmation – <tt class="docutils literal"><span class="pre">yes</span></tt></dt> <dd>Offer registration confirmation by email or only through the web? Allowed values: <tt class="docutils literal"><span class="pre">yes</span></tt>, <tt class="docutils literal"><span class="pre">no</span></tt></dd> <dt>indexer_stopwords – default <em>blank</em></dt> <dd>Additional stop-words for the full-text indexer specific to your tracker. See the indexer source for the default list of stop-words (e.g. <tt class="docutils literal"><span class="pre">A,AND,ARE,AS,AT,BE,BUT,BY,</span> <span class="pre">...</span></tt>).</dd> <dt>umask – <tt class="docutils literal"><span class="pre">02</span></tt></dt> <dd>Defines the file creation mode mask.</dd> </dl> </dd> <dt>Section <strong>tracker</strong></dt> <dd><dl class="first last docutils"> <dt>name – <tt class="docutils literal"><span class="pre">Roundup</span> <span class="pre">issue</span> <span class="pre">tracker</span></tt></dt> <dd>A descriptive name for your roundup instance.</dd> <dt>web – <tt class="docutils literal"><span class="pre">http://host.example/demo/</span></tt></dt> <dd>The web address that the tracker is viewable at. This will be included in information sent to users of the tracker. The URL MUST include the cgi-bin part or anything else that is required to get to the home page of the tracker. You MUST include a trailing ‘/’ in the URL.</dd> <dt>email – <tt class="docutils literal"><span class="pre">issue_tracker</span></tt></dt> <dd>Email address that mail to roundup should go to.</dd> <dt>language – default <em>blank</em></dt> <dd>Default locale name for this tracker. If this option is not set, the language is determined by the environment variable LANGUAGE, LC_ALL, LC_MESSAGES, or LANG, in that order of preference.</dd> </dl> </dd> <dt>Section <strong>web</strong></dt> <dd><dl class="first last docutils"> <dt>allow_html_file – <tt class="docutils literal"><span class="pre">no</span></tt></dt> <dd>Setting this option enables Roundup to serve uploaded HTML file content <em>as HTML</em>. This is a potential security risk and is therefore disabled by default. Set to ‘yes’ if you trust <em>all</em> users uploading content to your tracker.</dd> <dt>http_auth – <tt class="docutils literal"><span class="pre">yes</span></tt></dt> <dd>Whether to use HTTP Basic Authentication, if present. Roundup will use either the REMOTE_USER or HTTP_AUTHORIZATION variables supplied by your web server (in that order). Set this option to ‘no’ if you do not wish to use HTTP Basic Authentication in your web interface.</dd> <dt>use_browser_language – <tt class="docutils literal"><span class="pre">yes</span></tt></dt> <dd>Whether to use HTTP Accept-Language, if present. Browsers send a language-region preference list. It’s usually set in the client’s browser or in their Operating System. Set this option to ‘no’ if you want to ignore it.</dd> <dt>debug – <tt class="docutils literal"><span class="pre">no</span></tt></dt> <dd>Setting this option makes Roundup display error tracebacks in the user’s browser rather than emailing them to the tracker admin.”),</dd> </dl> </dd> <dt>Section <strong>rdbms</strong></dt> <dd><p class="first">Settings in this section are used by Postgresql and MySQL backends only</p> <dl class="last docutils"> <dt>name – <tt class="docutils literal"><span class="pre">roundup</span></tt></dt> <dd>Name of the database to use.</dd> <dt>host – <tt class="docutils literal"><span class="pre">localhost</span></tt></dt> <dd>Database server host.</dd> <dt>port – default <em>blank</em></dt> <dd>TCP port number of the database server. Postgresql usually resides on port 5432 (if any), for MySQL default port number is 3306. Leave this option empty to use backend default.</dd> <dt>user – <tt class="docutils literal"><span class="pre">roundup</span></tt></dt> <dd>Database user name that Roundup should use.</dd> <dt>password – <tt class="docutils literal"><span class="pre">roundup</span></tt></dt> <dd>Database user password.</dd> <dt>read_default_file – <tt class="docutils literal"><span class="pre">~/.my.cnf</span></tt></dt> <dd>Name of the MySQL defaults file. Only used in MySQL connections.</dd> <dt>read_default_group – <tt class="docutils literal"><span class="pre">roundup</span></tt></dt> <dd>Name of the group to use in the MySQL defaults file. Only used in MySQL connections.</dd> </dl> </dd> <dt>Section <strong>logging</strong></dt> <dd><dl class="first last docutils"> <dt>config – default <em>blank</em></dt> <dd>Path to configuration file for standard Python logging module. If this option is set, logging configuration is loaded from specified file; options ‘filename’ and ‘level’ in this section are ignored. The path may be either absolute or relative to the directory containig this config file.</dd> <dt>filename – default <em>blank</em></dt> <dd>Log file name for minimal logging facility built into Roundup. If no file name specified, log messages are written on stderr. If above ‘config’ option is set, this option has no effect. The path may be either absolute or relative to the directory containig this config file.</dd> <dt>level – <tt class="docutils literal"><span class="pre">ERROR</span></tt></dt> <dd>Minimal severity level of messages written to log file. If above ‘config’ option is set, this option has no effect. Allowed values: <tt class="docutils literal"><span class="pre">DEBUG</span></tt>, <tt class="docutils literal"><span class="pre">INFO</span></tt>, <tt class="docutils literal"><span class="pre">WARNING</span></tt>, <tt class="docutils literal"><span class="pre">ERROR</span></tt></dd> </dl> </dd> <dt>Section <strong>mail</strong></dt> <dd><p class="first">Outgoing email options. Used for nosy messages, password reset and registration approval requests.</p> <dl class="last docutils"> <dt>domain – <tt class="docutils literal"><span class="pre">localhost</span></tt></dt> <dd>Domain name used for email addresses.</dd> <dt>host – default <em>blank</em></dt> <dd>SMTP mail host that roundup will use to send mail</dd> <dt>username – default <em>blank</em></dt> <dd>SMTP login name. Set this if your mail host requires authenticated access. If username is not empty, password (below) MUST be set!</dd> <dt>password – default <em>blank</em></dt> <dd>SMTP login password. Set this if your mail host requires authenticated access.</dd> <dt>port – default <em>25</em></dt> <dd>SMTP port on mail host. Set this if your mail host runs on a different port.</dd> <dt>local_hostname – default <em>blank</em></dt> <dd>The fully qualified domain name (FQDN) to use during SMTP sessions. If left blank, the underlying SMTP library will attempt to detect your FQDN. If your mail host requires something specific, specify the FQDN to use.</dd> <dt>tls – <tt class="docutils literal"><span class="pre">no</span></tt></dt> <dd>If your SMTP mail host provides or requires TLS (Transport Layer Security) then you may set this option to ‘yes’. Allowed values: <tt class="docutils literal"><span class="pre">yes</span></tt>, <tt class="docutils literal"><span class="pre">no</span></tt></dd> <dt>tls_keyfile – default <em>blank</em></dt> <dd>If TLS is used, you may set this option to the name of a PEM formatted file that contains your private key. The path may be either absolute or relative to the directory containig this config file.</dd> <dt>tls_certfile – default <em>blank</em></dt> <dd>If TLS is used, you may set this option to the name of a PEM formatted certificate chain file. The path may be either absolute or relative to the directory containig this config file.</dd> <dt>charset – utf-8</dt> <dd>Character set to encode email headers with. We use utf-8 by default, as it’s the most flexible. Some mail readers (eg. Eudora) can’t cope with that, so you might need to specify a more limited character set (eg. iso-8859-1).</dd> <dt>debug – default <em>blank</em></dt> <dd>Setting this option makes Roundup to write all outgoing email messages to this file <em>instead</em> of sending them. This option has the same effect as environment variable SENDMAILDEBUG. Environment variable takes precedence. The path may be either absolute or relative to the directory containig this config file.</dd> <dt>add_authorinfo – <tt class="docutils literal"><span class="pre">yes</span></tt></dt> <dd>Add a line with author information at top of all messages send by roundup.</dd> <dt>add_authoremail – <tt class="docutils literal"><span class="pre">yes</span></tt></dt> <dd>Add the mail address of the author to the author information at the top of all messages. If this is false but add_authorinfo is true, only the name of the actor is added which protects the mail address of the actor from being exposed at mail archives, etc.</dd> </dl> </dd> <dt>Section <strong>mailgw</strong></dt> <dd><p class="first">Roundup Mail Gateway options</p> <dl class="last docutils"> <dt>keep_quoted_text – <tt class="docutils literal"><span class="pre">yes</span></tt></dt> <dd>Keep email citations when accepting messages. Setting this to <tt class="docutils literal"><span class="pre">no</span></tt> strips out “quoted” text from the message. Signatures are also stripped. Allowed values: <tt class="docutils literal"><span class="pre">yes</span></tt>, <tt class="docutils literal"><span class="pre">no</span></tt></dd> <dt>leave_body_unchanged – <tt class="docutils literal"><span class="pre">no</span></tt></dt> <dd>Preserve the email body as is - that is, keep the citations <em>and</em> signatures. Allowed values: <tt class="docutils literal"><span class="pre">yes</span></tt>, <tt class="docutils literal"><span class="pre">no</span></tt></dd> <dt>default_class – <tt class="docutils literal"><span class="pre">issue</span></tt></dt> <dd>Default class to use in the mailgw if one isn’t supplied in email subjects. To disable, leave the value blank.</dd> <dt>language – default <em>blank</em></dt> <dd>Default locale name for the tracker mail gateway. If this option is not set, mail gateway will use the language of the tracker instance.</dd> <dt>subject_prefix_parsing – <tt class="docutils literal"><span class="pre">strict</span></tt></dt> <dd>Controls the parsing of the [prefix] on subject lines in incoming emails. <tt class="docutils literal"><span class="pre">strict</span></tt> will return an error to the sender if the [prefix] is not recognised. <tt class="docutils literal"><span class="pre">loose</span></tt> will attempt to parse the [prefix] but just pass it through as part of the issue title if not recognised. <tt class="docutils literal"><span class="pre">none</span></tt> will always pass any [prefix] through as part of the issue title.</dd> <dt>subject_suffix_parsing – <tt class="docutils literal"><span class="pre">strict</span></tt></dt> <dd>Controls the parsing of the [suffix] on subject lines in incoming emails. <tt class="docutils literal"><span class="pre">strict</span></tt> will return an error to the sender if the [suffix] is not recognised. <tt class="docutils literal"><span class="pre">loose</span></tt> will attempt to parse the [suffix] but just pass it through as part of the issue title if not recognised. <tt class="docutils literal"><span class="pre">none</span></tt> will always pass any [suffix] through as part of the issue title.</dd> <dt>subject_suffix_delimiters – <tt class="docutils literal"><span class="pre">[]</span></tt></dt> <dd>Defines the brackets used for delimiting the commands suffix in a subject line.</dd> <dt>subject_content_match – <tt class="docutils literal"><span class="pre">always</span></tt></dt> <dd>Controls matching of the incoming email subject line against issue titles in the case where there is no designator [prefix]. <tt class="docutils literal"><span class="pre">never</span></tt> turns off matching. <tt class="docutils literal"><span class="pre">creation</span> <span class="pre">+</span> <span class="pre">interval</span></tt> or <tt class="docutils literal"><span class="pre">activity</span> <span class="pre">+</span> <span class="pre">interval</span></tt> will match an issue for the interval after the issue’s creation or last activity. The interval is a standard Roundup interval.</dd> <dt>subject_updates_title – <tt class="docutils literal"><span class="pre">yes</span></tt></dt> <dd>Update issue title if incoming subject of email is different. Setting this to <tt class="docutils literal"><span class="pre">no</span></tt> will ignore the title part of the subject of incoming email messages.</dd> <dt>refwd_re – <tt class="docutils literal"><span class="pre">(\s*\W?\s*(fw|fwd|re|aw|sv|ang)\W)+</span></tt></dt> <dd>Regular expression matching a single reply or forward prefix prepended by the mailer. This is explicitly stripped from the subject during parsing. Value is Python Regular Expression (UTF8-encoded).</dd> <dt>origmsg_re – `` ^[>|s]*—–s?Original Messages?—–$``</dt> <dd>Regular expression matching start of an original message if quoted the in body. Value is Python Regular Expression (UTF8-encoded).</dd> <dt>sign_re – <tt class="docutils literal"><span class="pre">^[>|\s]*--</span> <span class="pre">?$</span></tt></dt> <dd>Regular expression matching the start of a signature in the message body. Value is Python Regular Expression (UTF8-encoded).</dd> <dt>eol_re – <tt class="docutils literal"><span class="pre">[\r\n]+</span></tt></dt> <dd>Regular expression matching end of line. Value is Python Regular Expression (UTF8-encoded).</dd> <dt>blankline_re – <tt class="docutils literal"><span class="pre">[\r\n]+\s*[\r\n]+</span></tt></dt> <dd>Regular expression matching a blank line. Value is Python Regular Expression (UTF8-encoded).</dd> <dt>ignore_alternatives – <tt class="docutils literal"><span class="pre">no</span></tt></dt> <dd>When parsing incoming mails, roundup uses the first text/plain part it finds. If this part is inside a multipart/alternative, and this option is set, all other parts of the multipart/alternative are ignored. The default is to keep all parts and attach them to the issue.</dd> </dl> </dd> <dt>Section <strong>pgp</strong></dt> <dd><p class="first">OpenPGP mail processing options</p> <dl class="last docutils"> <dt>enable – <tt class="docutils literal"><span class="pre">no</span></tt></dt> <dd>Enable PGP processing. Requires pyme.</dd> <dt>roles – default <em>blank</em></dt> <dd>If specified, a comma-separated list of roles to perform PGP processing on. If not specified, it happens for all users.</dd> <dt>homedir – default <em>blank</em></dt> <dd>Location of PGP directory. Defaults to $HOME/.gnupg if not specified.</dd> </dl> </dd> <dt>Section <strong>nosy</strong></dt> <dd><p class="first">Nosy messages sending</p> <dl class="last docutils"> <dt>messages_to_author – <tt class="docutils literal"><span class="pre">no</span></tt></dt> <dd>Send nosy messages to the author of the message. Allowed values: <tt class="docutils literal"><span class="pre">yes</span></tt>, <tt class="docutils literal"><span class="pre">no</span></tt>, <tt class="docutils literal"><span class="pre">new</span></tt></dd> <dt>signature_position – <tt class="docutils literal"><span class="pre">bottom</span></tt></dt> <dd>Where to place the email signature. Allowed values: <tt class="docutils literal"><span class="pre">top</span></tt>, <tt class="docutils literal"><span class="pre">bottom</span></tt>, <tt class="docutils literal"><span class="pre">none</span></tt></dd> <dt>add_author – <tt class="docutils literal"><span class="pre">new</span></tt></dt> <dd>Does the author of a message get placed on the nosy list automatically? If <tt class="docutils literal"><span class="pre">new</span></tt> is used, then the author will only be added when a message creates a new issue. If <tt class="docutils literal"><span class="pre">yes</span></tt>, then the author will be added on followups too. If <tt class="docutils literal"><span class="pre">no</span></tt>, they’re never added to the nosy. Allowed values: <tt class="docutils literal"><span class="pre">yes</span></tt>, <tt class="docutils literal"><span class="pre">no</span></tt>, <tt class="docutils literal"><span class="pre">new</span></tt></dd> <dt>add_recipients – <tt class="docutils literal"><span class="pre">new</span></tt></dt> <dd>Do the recipients (<tt class="docutils literal"><span class="pre">To:</span></tt>, <tt class="docutils literal"><span class="pre">Cc:</span></tt>) of a message get placed on the nosy list? If <tt class="docutils literal"><span class="pre">new</span></tt> is used, then the recipients will only be added when a message creates a new issue. If <tt class="docutils literal"><span class="pre">yes</span></tt>, then the recipients will be added on followups too. If <tt class="docutils literal"><span class="pre">no</span></tt>, they’re never added to the nosy. Allowed values: <tt class="docutils literal"><span class="pre">yes</span></tt>, <tt class="docutils literal"><span class="pre">no</span></tt>, <tt class="docutils literal"><span class="pre">new</span></tt></dd> <dt>email_sending – <tt class="docutils literal"><span class="pre">single</span></tt></dt> <dd>Controls the email sending from the nosy reactor. If <tt class="docutils literal"><span class="pre">multiple</span></tt> then a separate email is sent to each recipient. If <tt class="docutils literal"><span class="pre">single</span></tt> then a single email is sent with each recipient as a CC address.</dd> <dt>max_attachment_size – <tt class="docutils literal"><span class="pre">2147483647</span></tt></dt> <dd>Attachments larger than the given number of bytes won’t be attached to nosy mails. They will be replaced by a link to the tracker’s download page for the file.</dd> </dl> </dd> </dl> <p>You may generate a new default config file using the <tt class="docutils literal"><span class="pre">roundup-admin</span> <span class="pre">genconfig</span></tt> command.</p> <p>Configuration variables may be referred to in lower or upper case. In code, variables not in the “main” section are referred to using their section and name, so “domain” in the section “mail” becomes MAIL_DOMAIN. The configuration variables available are:</p> <div class="section" id="extending-the-configuration-file"> <h3>Extending the configuration file</h3> <p>You can’t add new variables to the config.ini file in the tracker home but you can add two new config.ini files:</p> <ul class="simple"> <li>a config.ini in the <tt class="docutils literal"><span class="pre">extensions</span></tt> directory will be loaded and attached to the config variable as “ext”.</li> <li>a config.ini in the <tt class="docutils literal"><span class="pre">detectors</span></tt> directory will be loaded and attached to the config variable as “detectors”.</li> </ul> <p>For example, the following in <tt class="docutils literal"><span class="pre">detectors/config.ini</span></tt>:</p> <div class="highlight-python"><pre>[main] qa_recipients = email@example.com</pre> </div> <p>is accessible as:</p> <div class="highlight-python"><div class="highlight"><pre><span class="n">db</span><span class="o">.</span><span class="n">config</span><span class="o">.</span><span class="n">detectors</span><span class="p">[</span><span class="s">'QA_RECIPIENTS'</span><span class="p">]</span> </pre></div> </div> <p>Note that the name grouping applied to the main configuration file is applied to the extension config files, so if you instead have:</p> <div class="highlight-python"><pre>[qa] recipients = email@example.com</pre> </div> <p>then the above <tt class="docutils literal"><span class="pre">db.config.detectors['QA_RECIPIENTS']</span></tt> will still work.</p> </div> </div> <div class="section" id="tracker-schema"> <h2>Tracker Schema</h2> <div class="admonition note"> <p class="first admonition-title">Note</p> <p class="last">if you modify the schema, you’ll most likely need to edit the <a class="reference internal" href="#web-interface">web interface</a> HTML template files and <a class="reference internal" href="#detectors">detectors</a> to reflect your changes.</p> </div> <p>A tracker schema defines what data is stored in the tracker’s database. Schemas are defined using Python code in the <tt class="docutils literal"><span class="pre">schema.py</span></tt> module of your tracker.</p> <div class="section" id="the-schema-py-module"> <h3>The <tt class="docutils literal"><span class="pre">schema.py</span></tt> module</h3> <p>The <tt class="docutils literal"><span class="pre">schema.py</span></tt> module contains two functions:</p> <dl class="docutils"> <dt><strong>open</strong></dt> <dd>This function defines what your tracker looks like on the inside, the <strong>schema</strong> of the tracker. It defines the <strong>Classes</strong> and <strong>properties</strong> on each class. It also defines the <strong>security</strong> for those Classes. The next few sections describe how schemas work and what you can do with them.</dd> <dt><strong>init</strong></dt> <dd>This function is responsible for setting up the initial state of your tracker. It’s called exactly once - by the <tt class="docutils literal"><span class="pre">roundup-admin</span> <span class="pre">initialise</span></tt> command. See the start of the section on <a class="reference internal" href="#database-content">database content</a> for more info about how this works.</dd> </dl> </div> <div class="section" id="the-classic-schema"> <h3>The “classic” schema</h3> <p>The “classic” schema looks like this (see section <a class="reference internal" href="#setkey-property">setkey(property)</a> below for the meaning of <tt class="docutils literal"><span class="pre">'setkey'</span></tt> – you may also want to look into the sections <a class="reference internal" href="#setlabelprop-property">setlabelprop(property)</a> and <a class="reference internal" href="#setorderprop-property">setorderprop(property)</a> for specifying (default) labelling and ordering of classes.):</p> <div class="highlight-python"><div class="highlight"><pre><span class="n">pri</span> <span class="o">=</span> <span class="n">Class</span><span class="p">(</span><span class="n">db</span><span class="p">,</span> <span class="s">"priority"</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="n">String</span><span class="p">(),</span> <span class="n">order</span><span class="o">=</span><span class="n">String</span><span class="p">())</span> <span class="n">pri</span><span class="o">.</span><span class="n">setkey</span><span class="p">(</span><span class="s">"name"</span><span class="p">)</span> <span class="n">stat</span> <span class="o">=</span> <span class="n">Class</span><span class="p">(</span><span class="n">db</span><span class="p">,</span> <span class="s">"status"</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="n">String</span><span class="p">(),</span> <span class="n">order</span><span class="o">=</span><span class="n">String</span><span class="p">())</span> <span class="n">stat</span><span class="o">.</span><span class="n">setkey</span><span class="p">(</span><span class="s">"name"</span><span class="p">)</span> <span class="n">keyword</span> <span class="o">=</span> <span class="n">Class</span><span class="p">(</span><span class="n">db</span><span class="p">,</span> <span class="s">"keyword"</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="n">String</span><span class="p">())</span> <span class="n">keyword</span><span class="o">.</span><span class="n">setkey</span><span class="p">(</span><span class="s">"name"</span><span class="p">)</span> <span class="n">user</span> <span class="o">=</span> <span class="n">Class</span><span class="p">(</span><span class="n">db</span><span class="p">,</span> <span class="s">"user"</span><span class="p">,</span> <span class="n">username</span><span class="o">=</span><span class="n">String</span><span class="p">(),</span> <span class="n">organisation</span><span class="o">=</span><span class="n">String</span><span class="p">(),</span> <span class="n">password</span><span class="o">=</span><span class="n">String</span><span class="p">(),</span> <span class="n">address</span><span class="o">=</span><span class="n">String</span><span class="p">(),</span> <span class="n">realname</span><span class="o">=</span><span class="n">String</span><span class="p">(),</span> <span class="n">phone</span><span class="o">=</span><span class="n">String</span><span class="p">(),</span> <span class="n">alternate_addresses</span><span class="o">=</span><span class="n">String</span><span class="p">(),</span> <span class="n">queries</span><span class="o">=</span><span class="n">Multilink</span><span class="p">(</span><span class="s">'query'</span><span class="p">),</span> <span class="n">roles</span><span class="o">=</span><span class="n">String</span><span class="p">(),</span> <span class="n">timezone</span><span class="o">=</span><span class="n">String</span><span class="p">())</span> <span class="n">user</span><span class="o">.</span><span class="n">setkey</span><span class="p">(</span><span class="s">"username"</span><span class="p">)</span> <span class="n">msg</span> <span class="o">=</span> <span class="n">FileClass</span><span class="p">(</span><span class="n">db</span><span class="p">,</span> <span class="s">"msg"</span><span class="p">,</span> <span class="n">author</span><span class="o">=</span><span class="n">Link</span><span class="p">(</span><span class="s">"user"</span><span class="p">),</span> <span class="n">summary</span><span class="o">=</span><span class="n">String</span><span class="p">(),</span> <span class="n">date</span><span class="o">=</span><span class="n">Date</span><span class="p">(),</span> <span class="n">recipients</span><span class="o">=</span><span class="n">Multilink</span><span class="p">(</span><span class="s">"user"</span><span class="p">),</span> <span class="n">files</span><span class="o">=</span><span class="n">Multilink</span><span class="p">(</span><span class="s">"file"</span><span class="p">),</span> <span class="n">messageid</span><span class="o">=</span><span class="n">String</span><span class="p">(),</span> <span class="n">inreplyto</span><span class="o">=</span><span class="n">String</span><span class="p">())</span> <span class="nb">file</span> <span class="o">=</span> <span class="n">FileClass</span><span class="p">(</span><span class="n">db</span><span class="p">,</span> <span class="s">"file"</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="n">String</span><span class="p">())</span> <span class="n">issue</span> <span class="o">=</span> <span class="n">IssueClass</span><span class="p">(</span><span class="n">db</span><span class="p">,</span> <span class="s">"issue"</span><span class="p">,</span> <span class="n">keyword</span><span class="o">=</span><span class="n">Multilink</span><span class="p">(</span><span class="s">"keyword"</span><span class="p">),</span> <span class="n">status</span><span class="o">=</span><span class="n">Link</span><span class="p">(</span><span class="s">"status"</span><span class="p">),</span> <span class="n">assignedto</span><span class="o">=</span><span class="n">Link</span><span class="p">(</span><span class="s">"user"</span><span class="p">),</span> <span class="n">priority</span><span class="o">=</span><span class="n">Link</span><span class="p">(</span><span class="s">"priority"</span><span class="p">))</span> <span class="n">issue</span><span class="o">.</span><span class="n">setkey</span><span class="p">(</span><span class="s">'title'</span><span class="p">)</span> </pre></div> </div> </div> <div class="section" id="what-you-can-t-do-to-the-schema"> <h3>What you can’t do to the schema</h3> <p>You must never:</p> <dl class="docutils"> <dt><strong>Remove the users class</strong></dt> <dd>This class is the only <em>required</em> class in Roundup.</dd> <dt><strong>Remove the “username”, “address”, “password” or “realname” user properties</strong></dt> <dd>Various parts of Roundup require these properties. Don’t remove them.</dd> <dt><strong>Change the type of a property</strong></dt> <dd>Property types must <em>never</em> be changed - the database simply doesn’t take this kind of action into account. Note that you can’t just remove a property and re-add it as a new type either. If you wanted to make the assignedto property a Multilink, you’d need to create a new property assignedto_list and remove the old assignedto property.</dd> </dl> </div> <div class="section" id="what-you-can-do-to-the-schema"> <h3>What you can do to the schema</h3> <p>Your schema may be changed at any time before or after the tracker has been initialised (or used). You may:</p> <dl class="docutils"> <dt><strong>Add new properties to classes, or add whole new classes</strong></dt> <dd>This is painless and easy to do - there are generally no repurcussions from adding new information to a tracker’s schema.</dd> <dt><strong>Remove properties</strong></dt> <dd>Removing properties is a little more tricky - you need to make sure that the property is no longer used in the <a class="reference internal" href="#web-interface">web interface</a> <em>or</em> by the <a class="reference internal" href="#detectors">detectors</a>.</dd> </dl> </div> <div class="section" id="classes-and-properties-creating-a-new-information-store"> <h3>Classes and Properties - creating a new information store</h3> <p>In the tracker above, we’ve defined 7 classes of information:</p> <blockquote> <dl class="docutils"> <dt>priority</dt> <dd>Defines the possible levels of urgency for issues.</dd> <dt>status</dt> <dd>Defines the possible states of processing the issue may be in.</dd> <dt>keyword</dt> <dd>Initially empty, will hold keywords useful for searching issues.</dd> <dt>user</dt> <dd>Initially holding the “admin” user, will eventually have an entry for all users using roundup.</dd> <dt>msg</dt> <dd>Initially empty, will hold all e-mail messages sent to or generated by roundup.</dd> <dt>file</dt> <dd>Initially empty, will hold all files attached to issues.</dd> <dt>issue</dt> <dd>Initially empty, this is where the issue information is stored.</dd> </dl> </blockquote> <p>We define the “priority” and “status” classes to allow two things: reduction in the amount of information stored on the issue and more powerful, accurate searching of issues by priority and status. By only requiring a link on the issue (which is stored as a single number) we reduce the chance that someone mis-types a priority or status - or simply makes a new one up.</p> <div class="section" id="class-and-items"> <h4>Class and Items</h4> <p>A Class defines a particular class (or type) of data that will be stored in the database. A class comprises one or more properties, which gives the information about the class items.</p> <p>The actual data entered into the database, using <tt class="docutils literal"><span class="pre">class.create()</span></tt>, are called items. They have a special immutable property called <tt class="docutils literal"><span class="pre">'id'</span></tt>. We sometimes refer to this as the <em>itemid</em>.</p> </div> <div class="section" id="properties"> <h4>Properties</h4> <p>A Class is comprised of one or more properties of the following types:</p> <ul class="simple"> <li>String properties are for storing arbitrary-length strings.</li> <li>Password properties are for storing encoded arbitrary-length strings. The default encoding is defined on the <tt class="docutils literal"><span class="pre">roundup.password.Password</span></tt> class.</li> <li>Date properties store date-and-time stamps. Their values are Timestamp objects.</li> <li>Number properties store numeric values.</li> <li>Boolean properties store on/off, yes/no, true/false values.</li> <li>A Link property refers to a single other item selected from a specified class. The class is part of the property; the value is an integer, the id of the chosen item.</li> <li>A Multilink property refers to possibly many items in a specified class. The value is a list of integers.</li> </ul> <p>All Classes automatically have a number of properties by default:</p> <dl class="docutils"> <dt><em>creator</em></dt> <dd>Link to the user that created the item.</dd> <dt><em>creation</em></dt> <dd>Date the item was created.</dd> <dt><em>actor</em></dt> <dd>Link to the user that last modified the item.</dd> <dt><em>activity</em></dt> <dd>Date the item was last modified.</dd> </dl> </div> <div class="section" id="fileclass"> <h4>FileClass</h4> <p>FileClasses save their “content” attribute off in a separate file from the rest of the database. This reduces the number of large entries in the database, which generally makes databases more efficient, and also allows us to use command-line tools to operate on the files. They are stored in the files sub-directory of the <tt class="docutils literal"><span class="pre">'db'</span></tt> directory in your tracker. FileClasses also have a “type” attribute to store the MIME type of the file.</p> </div> <div class="section" id="issueclass"> <h4>IssueClass</h4> <p>IssueClasses automatically include the “messages”, “files”, “nosy”, and “superseder” properties.</p> <p>The messages and files properties list the links to the messages and files related to the issue. The nosy property is a list of links to users who wish to be informed of changes to the issue - they get “CC’ed” e-mails when messages are sent to or generated by the issue. The nosy reactor (in the <tt class="docutils literal"><span class="pre">'detectors'</span></tt> directory) handles this action. The superseder link indicates an issue which has superseded this one.</p> <p>They also have the dynamically generated “creation”, “activity” and “creator” properties.</p> <p>The value of the “creation” property is the date when an item was created, and the value of the “activity” property is the date when any property on the item was last edited (equivalently, these are the dates on the first and last records in the item’s journal). The “creator” property holds a link to the user that created the issue.</p> </div> <div class="section" id="setkey-property"> <h4>setkey(property)</h4> <p>Select a String property of the class to be the key property. The key property must be unique, and allows references to the items in the class by the content of the key property. That is, we can refer to users by their username: for example, let’s say that there’s an issue in roundup, issue 23. There’s also a user, richard, who happens to be user 2. To assign an issue to him, we could do either of:</p> <div class="highlight-python"><pre>roundup-admin set issue23 assignedto=2</pre> </div> <p>or:</p> <div class="highlight-python"><pre>roundup-admin set issue23 assignedto=richard</pre> </div> <p>Note, the same thing can be done in the web and e-mail interfaces.</p> </div> <div class="section" id="setlabelprop-property"> <h4>setlabelprop(property)</h4> <p>Select a property of the class to be the label property. The label property is used whereever an item should be uniquely identified, e.g., when displaying a link to an item. If setlabelprop is not specified for a class, the following values are tried for the label:</p> <blockquote> <ul class="simple"> <li>the key of the class (see the <a class="reference internal" href="#setkey-property">setkey(property)</a> section above)</li> <li>the “name” property</li> <li>the “title” property</li> <li>the first property from the sorted property name list</li> </ul> </blockquote> <p>So in most cases you can get away without specifying setlabelprop explicitly.</p> </div> <div class="section" id="setorderprop-property"> <h4>setorderprop(property)</h4> <p>Select a property of the class to be the order property. The order property is used whenever using a default sort order for the class, e.g., when grouping or sorting class A by a link to class B in the user interface, the order property of class B is used for sorting. If setorderprop is not specified for a class, the following values are tried for the order property:</p> <blockquote> <ul class="simple"> <li>the property named “order”</li> <li>the label property (see <a class="reference internal" href="#setlabelprop-property">setlabelprop(property)</a> above)</li> </ul> </blockquote> <p>So in most cases you can get away without specifying setorderprop explicitly.</p> </div> <div class="section" id="create-information"> <h4>create(information)</h4> <p>Create an item in the database. This is generally used to create items in the “definitional” classes like “priority” and “status”.</p> </div> <div class="section" id="a-note-about-ordering"> <h4>A note about ordering</h4> <p>When we sort items in the hyperdb, we use one of a number of methods, depending on the properties being sorted on:</p> <ol class="arabic simple"> <li>If it’s a String, Number, Date or Interval property, we just sort the scalar value of the property. Strings are sorted case-sensitively.</li> <li>If it’s a Link property, we sort by either the linked item’s “order” property (if it has one) or the linked item’s “id”.</li> <li>Mulitlinks sort similar to #2, but we start with the first Multilink list item, and if they’re the same, we sort by the second item, and so on.</li> </ol> <p>Note that if an “order” property is defined on a Class that is used for sorting, all items of that Class <em>must</em> have a value against the “order” property, or sorting will result in random ordering.</p> </div> </div> <div class="section" id="examples-of-adding-to-your-schema"> <h3>Examples of adding to your schema</h3> <p>The Roundup wiki has examples of how schemas can be customised to add new functionality.</p> </div> </div> <div class="section" id="detectors-adding-behaviour-to-your-tracker"> <h2>Detectors - adding behaviour to your tracker</h2> <p id="detectors">Detectors are initialised every time you open your tracker database, so you’re free to add and remove them any time, even after the database is initialised via the <tt class="docutils literal"><span class="pre">roundup-admin</span> <span class="pre">initialise</span></tt> command.</p> <p>The detectors in your tracker fire <em>before</em> (<strong>auditors</strong>) and <em>after</em> (<strong>reactors</strong>) changes to the contents of your database. They are Python modules that sit in your tracker’s <tt class="docutils literal"><span class="pre">detectors</span></tt> directory. You will have some installed by default - have a look. You can write new detectors or modify the existing ones. The existing detectors installed for you are:</p> <dl class="docutils"> <dt><strong>nosyreaction.py</strong></dt> <dd>This provides the automatic nosy list maintenance and email sending. The nosy reactor (<tt class="docutils literal"><span class="pre">nosyreaction</span></tt>) fires when new messages are added to issues. The nosy auditor (<tt class="docutils literal"><span class="pre">updatenosy</span></tt>) fires when issues are changed, and figures out what changes need to be made to the nosy list (such as adding new authors, etc.)</dd> <dt><strong>statusauditor.py</strong></dt> <dd>This provides the <tt class="docutils literal"><span class="pre">chatty</span></tt> auditor which changes the issue status from <tt class="docutils literal"><span class="pre">unread</span></tt> or <tt class="docutils literal"><span class="pre">closed</span></tt> to <tt class="docutils literal"><span class="pre">chatting</span></tt> if new messages appear. It also provides the <tt class="docutils literal"><span class="pre">presetunread</span></tt> auditor which pre-sets the status to <tt class="docutils literal"><span class="pre">unread</span></tt> on new items if the status isn’t explicitly defined.</dd> <dt><strong>messagesummary.py</strong></dt> <dd>Generates the <tt class="docutils literal"><span class="pre">summary</span></tt> property for new messages based on the message content.</dd> <dt><strong>userauditor.py</strong></dt> <dd>Verifies the content of some of the user fields (email addresses and roles lists).</dd> </dl> <p>If you don’t want this default behaviour, you’re completely free to change or remove these detectors.</p> <p>See the detectors section in the <a class="reference external" href="design.html">design document</a> for details of the interface for detectors.</p> <div class="section" id="detector-api"> <h3>Detector API</h3> <p>Auditors are called with the arguments:</p> <div class="highlight-python"><div class="highlight"><pre><span class="n">audit</span><span class="p">(</span><span class="n">db</span><span class="p">,</span> <span class="n">cl</span><span class="p">,</span> <span class="n">itemid</span><span class="p">,</span> <span class="n">newdata</span><span class="p">)</span> </pre></div> </div> <p>where <tt class="docutils literal"><span class="pre">db</span></tt> is the database, <tt class="docutils literal"><span class="pre">cl</span></tt> is an instance of Class or IssueClass within the database, and <tt class="docutils literal"><span class="pre">newdata</span></tt> is a dictionary mapping property names to values.</p> <p>For a <tt class="docutils literal"><span class="pre">create()</span></tt> operation, the <tt class="docutils literal"><span class="pre">itemid</span></tt> argument is None and newdata contains all of the initial property values with which the item is about to be created.</p> <p>For a <tt class="docutils literal"><span class="pre">set()</span></tt> operation, newdata contains only the names and values of properties that are about to be changed.</p> <p>For a <tt class="docutils literal"><span class="pre">retire()</span></tt> or <tt class="docutils literal"><span class="pre">restore()</span></tt> operation, newdata is None.</p> <p>Reactors are called with the arguments:</p> <div class="highlight-python"><div class="highlight"><pre><span class="n">react</span><span class="p">(</span><span class="n">db</span><span class="p">,</span> <span class="n">cl</span><span class="p">,</span> <span class="n">itemid</span><span class="p">,</span> <span class="n">olddata</span><span class="p">)</span> </pre></div> </div> <p>where <tt class="docutils literal"><span class="pre">db</span></tt> is the database, <tt class="docutils literal"><span class="pre">cl</span></tt> is an instance of Class or IssueClass within the database, and <tt class="docutils literal"><span class="pre">olddata</span></tt> is a dictionary mapping property names to values.</p> <p>For a <tt class="docutils literal"><span class="pre">create()</span></tt> operation, the <tt class="docutils literal"><span class="pre">itemid</span></tt> argument is the id of the newly-created item and <tt class="docutils literal"><span class="pre">olddata</span></tt> is None.</p> <p>For a <tt class="docutils literal"><span class="pre">set()</span></tt> operation, <tt class="docutils literal"><span class="pre">olddata</span></tt> contains the names and previous values of properties that were changed.</p> <p>For a <tt class="docutils literal"><span class="pre">retire()</span></tt> or <tt class="docutils literal"><span class="pre">restore()</span></tt> operation, <tt class="docutils literal"><span class="pre">itemid</span></tt> is the id of the retired or restored item and <tt class="docutils literal"><span class="pre">olddata</span></tt> is None.</p> </div> <div class="section" id="additional-detectors-ready-for-use"> <h3>Additional Detectors Ready For Use</h3> <p>Sample additional detectors that have been found useful will appear in the <tt class="docutils literal"><span class="pre">'detectors'</span></tt> directory of the Roundup distribution. If you want to use one, copy it to the <tt class="docutils literal"><span class="pre">'detectors'</span></tt> of your tracker instance:</p> <dl class="docutils"> <dt><strong>newissuecopy.py</strong></dt> <dd>This detector sends an email to a team address whenever a new issue is created. The address is hard-coded into the detector, so edit it before you use it (look for the text <a class="reference external" href="mailto:'team%40team.host">'team<span>@</span>team<span>.</span>host</a>‘) or you’ll get email errors!</dd> <dt><strong>creator_resolution.py</strong></dt> <dd>Catch attempts to set the status to “resolved” - if the assignedto user isn’t the creator, then set the status to “confirm-done”. Note that “classic” Roundup doesn’t have that status, so you’ll have to add it. If you don’t want to though, it’ll just use “in-progress” instead.</dd> <dt><strong>email_auditor.py</strong></dt> <dd>If a file added to an issue is of type message/rfc822, we tack on the extension .eml. The reason for this is that Microsoft Internet Explorer will not open things with a .eml attachment, as they deem it ‘unsafe’. Worse yet, they’ll just give you an incomprehensible error message. For more information, see the detector code - it has a length explanation.</dd> </dl> </div> <div class="section" id="auditor-or-reactor"> <h3>Auditor or Reactor?</h3> <p>Generally speaking, the following rules should be observed:</p> <dl class="docutils"> <dt><strong>Auditors</strong></dt> <dd>Are used for <a class="reference internal" href="#vetoing-creation-of-or-changes-to-items">vetoing creation of or changes to items</a>. They might also make automatic changes to item properties.</dd> <dt><strong>Reactors</strong></dt> <dd>Detect changes in the database and react accordingly. They should avoid making changes to the database where possible, as this could create detector loops.</dd> </dl> </div> <div class="section" id="vetoing-creation-of-or-changes-to-items"> <h3>Vetoing creation of or changes to items</h3> <p>Auditors may raise the <tt class="docutils literal"><span class="pre">Reject</span></tt> exception to prevent the creation of or changes to items in the database. The mail gateway, for example, will not attach files or messages to issues when the creation of those files or messages are prevented through the <tt class="docutils literal"><span class="pre">Reject</span></tt> exception. It’ll also not create users if that creation is <tt class="docutils literal"><span class="pre">Reject</span></tt>‘ed too.</p> <p>To use, simply add at the top of your auditor:</p> <div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">roundup.exceptions</span> <span class="kn">import</span> <span class="n">Reject</span> </pre></div> </div> <p>And then when your rejection criteria have been detected, simply:</p> <div class="highlight-python"><div class="highlight"><pre><span class="k">raise</span> <span class="n">Reject</span> </pre></div> </div> </div> <div class="section" id="generating-email-from-roundup"> <h3>Generating email from Roundup</h3> <p>The module <tt class="docutils literal"><span class="pre">roundup.mailer</span></tt> contains most of the nuts-n-bolts required to generate email messages from Roundup.</p> <p>In addition, the <tt class="docutils literal"><span class="pre">IssueClass</span></tt> methods <tt class="docutils literal"><span class="pre">nosymessage()</span></tt> and <tt class="docutils literal"><span class="pre">send_message()</span></tt> are used to generate nosy messages, and may generate messages which only consist of a change note (ie. the message id parameter is not required - this is referred to as a “System Message” because it comes from “the system” and not a user).</p> </div> </div> <div class="section" id="database-content"> <h2>Database Content</h2> <div class="admonition note"> <p class="first admonition-title">Note</p> <p class="last">If you modify the content of definitional classes, you’ll most likely need to edit the tracker <a class="reference internal" href="#detectors">detectors</a> to reflect your changes.</p> </div> <p>Customisation of the special “definitional” classes (eg. status, priority, resolution, ...) may be done either before or after the tracker is initialised. The actual method of doing so is completely different in each case though, so be careful to use the right one.</p> <dl class="docutils"> <dt><strong>Changing content before tracker initialisation</strong></dt> <dd>Edit the initial_data.py module in your tracker to alter the items created using the <tt class="docutils literal"><span class="pre">create(</span> <span class="pre">...</span> <span class="pre">)</span></tt> methods.</dd> <dt><strong>Changing content after tracker initialisation</strong></dt> <dd><p class="first">As the “admin” user, click on the “class list” link in the web interface to bring up a list of all database classes. Click on the name of the class you wish to change the content of.</p> <p class="last">You may also use the <tt class="docutils literal"><span class="pre">roundup-admin</span></tt> interface’s create, set and retire methods to add, alter or remove items from the classes in question.</p> </dd> </dl> <p>See “<a class="reference internal" href="#adding-a-new-field-to-the-classic-schema">adding a new field to the classic schema</a>” for an example that requires database content changes.</p> </div> <div class="section" id="security-access-controls"> <h2>Security / Access Controls</h2> <p>A set of Permissions is built into the security module by default:</p> <ul class="simple"> <li>Create (everything)</li> <li>Edit (everything)</li> <li>View (everything)</li> <li>Register (User class only)</li> </ul> <p>These are assigned to the “Admin” Role by default, and allow a user to do anything. Every Class you define in your <a class="reference internal" href="#tracker-schema">tracker schema</a> also gets an Create, Edit and View Permission of its own. The web and email interfaces also define:</p> <dl class="docutils"> <dt><em>Email Access</em></dt> <dd>If defined, the user may use the email interface. Used by default to deny Anonymous users access to the email interface. When granted to the Anonymous user, they will be automatically registered by the email interface (see also the <tt class="docutils literal"><span class="pre">new_email_user_roles</span></tt> configuration option).</dd> <dt><em>Web Access</em></dt> <dd>If defined, the user may use the web interface. All users are able to see the login form, regardless of this setting (thus enabling logging in).</dd> <dt><em>Web Roles</em></dt> <dd>Controls user access to editing the “roles” property of the “user” class. TODO: deprecate in favour of a property-based control.</dd> </dl> <p>These are hooked into the default Roles:</p> <ul class="simple"> <li>Admin (Create, Edit, View and everything; Web Roles)</li> <li>User (Web Access; Email Access)</li> <li>Anonymous (Web Access)</li> </ul> <p>And finally, the “admin” user gets the “Admin” Role, and the “anonymous” user gets “Anonymous” assigned when the tracker is installed.</p> <p>For the “User” Role, the “classic” tracker defines:</p> <ul class="simple"> <li>Create, Edit and View issue, file, msg, query, keyword</li> <li>View priority, status</li> <li>View user</li> <li>Edit their own user record</li> </ul> <p>And the “Anonymous” Role is defined as:</p> <ul class="simple"> <li>Web interface access</li> <li>Register user (for registration)</li> <li>View issue, file, msg, query, keyword, priority, status</li> </ul> <p>Put together, these settings appear in the tracker’s <tt class="docutils literal"><span class="pre">schema.py</span></tt> file:</p> <div class="highlight-python"><div class="highlight"><pre><span class="c">#</span> <span class="c"># TRACKER SECURITY SETTINGS</span> <span class="c">#</span> <span class="c"># See the configuration and customisation document for information</span> <span class="c"># about security setup.</span> <span class="c">#</span> <span class="c"># REGULAR USERS</span> <span class="c">#</span> <span class="c"># Give the regular users access to the web and email interface</span> <span class="n">db</span><span class="o">.</span><span class="n">security</span><span class="o">.</span><span class="n">addPermissionToRole</span><span class="p">(</span><span class="s">'User'</span><span class="p">,</span> <span class="s">'Web Access'</span><span class="p">)</span> <span class="n">db</span><span class="o">.</span><span class="n">security</span><span class="o">.</span><span class="n">addPermissionToRole</span><span class="p">(</span><span class="s">'User'</span><span class="p">,</span> <span class="s">'Email Access'</span><span class="p">)</span> <span class="c"># Assign the access and edit Permissions for issue, file and message</span> <span class="c"># to regular users now</span> <span class="k">for</span> <span class="n">cl</span> <span class="ow">in</span> <span class="s">'issue'</span><span class="p">,</span> <span class="s">'file'</span><span class="p">,</span> <span class="s">'msg'</span><span class="p">,</span> <span class="s">'query'</span><span class="p">,</span> <span class="s">'keyword'</span><span class="p">:</span> <span class="n">db</span><span class="o">.</span><span class="n">security</span><span class="o">.</span><span class="n">addPermissionToRole</span><span class="p">(</span><span class="s">'User'</span><span class="p">,</span> <span class="s">'View'</span><span class="p">,</span> <span class="n">cl</span><span class="p">)</span> <span class="n">db</span><span class="o">.</span><span class="n">security</span><span class="o">.</span><span class="n">addPermissionToRole</span><span class="p">(</span><span class="s">'User'</span><span class="p">,</span> <span class="s">'Edit'</span><span class="p">,</span> <span class="n">cl</span><span class="p">)</span> <span class="n">db</span><span class="o">.</span><span class="n">security</span><span class="o">.</span><span class="n">addPermissionToRole</span><span class="p">(</span><span class="s">'User'</span><span class="p">,</span> <span class="s">'Create'</span><span class="p">,</span> <span class="n">cl</span><span class="p">)</span> <span class="k">for</span> <span class="n">cl</span> <span class="ow">in</span> <span class="s">'priority'</span><span class="p">,</span> <span class="s">'status'</span><span class="p">:</span> <span class="n">db</span><span class="o">.</span><span class="n">security</span><span class="o">.</span><span class="n">addPermissionToRole</span><span class="p">(</span><span class="s">'User'</span><span class="p">,</span> <span class="s">'View'</span><span class="p">,</span> <span class="n">cl</span><span class="p">)</span> <span class="c"># May users view other user information? Comment these lines out</span> <span class="c"># if you don't want them to</span> <span class="n">db</span><span class="o">.</span><span class="n">security</span><span class="o">.</span><span class="n">addPermissionToRole</span><span class="p">(</span><span class="s">'User'</span><span class="p">,</span> <span class="s">'View'</span><span class="p">,</span> <span class="s">'user'</span><span class="p">)</span> <span class="c"># Users should be able to edit their own details -- this permission</span> <span class="c"># is limited to only the situation where the Viewed or Edited item</span> <span class="c"># is their own.</span> <span class="k">def</span> <span class="nf">own_record</span><span class="p">(</span><span class="n">db</span><span class="p">,</span> <span class="n">userid</span><span class="p">,</span> <span class="n">itemid</span><span class="p">):</span> <span class="sd">'''Determine whether the userid matches the item being accessed.'''</span> <span class="k">return</span> <span class="n">userid</span> <span class="o">==</span> <span class="n">itemid</span> <span class="n">p</span> <span class="o">=</span> <span class="n">db</span><span class="o">.</span><span class="n">security</span><span class="o">.</span><span class="n">addPermission</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s">'View'</span><span class="p">,</span> <span class="n">klass</span><span class="o">=</span><span class="s">'user'</span><span class="p">,</span> <span class="n">check</span><span class="o">=</span><span class="n">own_record</span><span class="p">,</span> <span class="n">description</span><span class="o">=</span><span class="s">"User is allowed to view their own user details"</span><span class="p">)</span> <span class="n">db</span><span class="o">.</span><span class="n">security</span><span class="o">.</span><span class="n">addPermissionToRole</span><span class="p">(</span><span class="s">'User'</span><span class="p">,</span> <span class="n">p</span><span class="p">)</span> <span class="n">p</span> <span class="o">=</span> <span class="n">db</span><span class="o">.</span><span class="n">security</span><span class="o">.</span><span class="n">addPermission</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s">'Edit'</span><span class="p">,</span> <span class="n">klass</span><span class="o">=</span><span class="s">'user'</span><span class="p">,</span> <span class="n">check</span><span class="o">=</span><span class="n">own_record</span><span class="p">,</span> <span class="n">description</span><span class="o">=</span><span class="s">"User is allowed to edit their own user details"</span><span class="p">)</span> <span class="n">db</span><span class="o">.</span><span class="n">security</span><span class="o">.</span><span class="n">addPermissionToRole</span><span class="p">(</span><span class="s">'User'</span><span class="p">,</span> <span class="n">p</span><span class="p">)</span> <span class="c">#</span> <span class="c"># ANONYMOUS USER PERMISSIONS</span> <span class="c">#</span> <span class="c"># Let anonymous users access the web interface. Note that almost all</span> <span class="c"># trackers will need this Permission. The only situation where it's not</span> <span class="c"># required is in a tracker that uses an HTTP Basic Authenticated front-end.</span> <span class="n">db</span><span class="o">.</span><span class="n">security</span><span class="o">.</span><span class="n">addPermissionToRole</span><span class="p">(</span><span class="s">'Anonymous'</span><span class="p">,</span> <span class="s">'Web Access'</span><span class="p">)</span> <span class="c"># Let anonymous users access the email interface (note that this implies</span> <span class="c"># that they will be registered automatically, hence they will need the</span> <span class="c"># "Create" user Permission below)</span> <span class="c"># This is disabled by default to stop spam from auto-registering users on</span> <span class="c"># public trackers.</span> <span class="c">#db.security.addPermissionToRole('Anonymous', 'Email Access')</span> <span class="c"># Assign the appropriate permissions to the anonymous user's Anonymous</span> <span class="c"># Role. Choices here are:</span> <span class="c"># - Allow anonymous users to register</span> <span class="n">db</span><span class="o">.</span><span class="n">security</span><span class="o">.</span><span class="n">addPermissionToRole</span><span class="p">(</span><span class="s">'Anonymous'</span><span class="p">,</span> <span class="s">'Create'</span><span class="p">,</span> <span class="s">'user'</span><span class="p">)</span> <span class="c"># Allow anonymous users access to view issues (and the related, linked</span> <span class="c"># information)</span> <span class="k">for</span> <span class="n">cl</span> <span class="ow">in</span> <span class="s">'issue'</span><span class="p">,</span> <span class="s">'file'</span><span class="p">,</span> <span class="s">'msg'</span><span class="p">,</span> <span class="s">'keyword'</span><span class="p">,</span> <span class="s">'priority'</span><span class="p">,</span> <span class="s">'status'</span><span class="p">:</span> <span class="n">db</span><span class="o">.</span><span class="n">security</span><span class="o">.</span><span class="n">addPermissionToRole</span><span class="p">(</span><span class="s">'Anonymous'</span><span class="p">,</span> <span class="s">'View'</span><span class="p">,</span> <span class="n">cl</span><span class="p">)</span> <span class="c"># [OPTIONAL]</span> <span class="c"># Allow anonymous users access to create or edit "issue" items (and the</span> <span class="c"># related file and message items)</span> <span class="c">#for cl in 'issue', 'file', 'msg':</span> <span class="c"># db.security.addPermissionToRole('Anonymous', 'Create', cl)</span> <span class="c"># db.security.addPermissionToRole('Anonymous', 'Edit', cl)</span> </pre></div> </div> <div class="section" id="automatic-permission-checks"> <h3>Automatic Permission Checks</h3> <p>Permissions are automatically checked when information is rendered through the web. This includes:</p> <ol class="arabic simple"> <li>View checks for properties when being rendered via the <tt class="docutils literal"><span class="pre">plain()</span></tt> or similar methods. If the check fails, the text “[hidden]” will be displayed.</li> <li>Edit checks for properties when the edit field is being rendered via the <tt class="docutils literal"><span class="pre">field()</span></tt> or similar methods. If the check fails, the property will be rendered via the <tt class="docutils literal"><span class="pre">plain()</span></tt> method (see point 1. for subsequent checking performed)</li> <li>View checks are performed in index pages for each item being displayed such that if the user does not have permission, the row is not rendered.</li> <li>View checks are performed at the top of item pages for the Item being displayed. If the user does not have permission, the text “You are not allowed to view this page.” will be displayed.</li> <li>View checks are performed at the top of index pages for the Class being displayed. If the user does not have permission, the text “You are not allowed to view this page.” will be displayed.</li> </ol> </div> <div class="section" id="new-user-roles"> <h3>New User Roles</h3> <p>New users are assigned the Roles defined in the config file as:</p> <ul class="simple"> <li>NEW_WEB_USER_ROLES</li> <li>NEW_EMAIL_USER_ROLES</li> </ul> <p>The <a class="reference internal" href="#users-may-only-edit-their-issues">users may only edit their issues</a> example shows customisation of these parameters.</p> </div> <div class="section" id="changing-access-controls"> <h3>Changing Access Controls</h3> <p>You may alter the configuration variables to change the Role that new web or email users get, for example to not give them access to the web interface if they register through email.</p> <p>You may use the <tt class="docutils literal"><span class="pre">roundup-admin</span></tt> “<tt class="docutils literal"><span class="pre">security</span></tt>” command to display the current Role and Permission configuration in your tracker.</p> <div class="section" id="adding-a-new-permission"> <h4>Adding a new Permission</h4> <p>When adding a new Permission, you will need to:</p> <ol class="arabic"> <li><p class="first">add it to your tracker’s <tt class="docutils literal"><span class="pre">schema.py</span></tt> so it is created, using <tt class="docutils literal"><span class="pre">security.addPermission</span></tt>, for example:</p> <div class="highlight-python"><div class="highlight"><pre><span class="bp">self</span><span class="o">.</span><span class="n">security</span><span class="o">.</span><span class="n">addPermission</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s">"View"</span><span class="p">,</span> <span class="n">klass</span><span class="o">=</span><span class="s">'frozzle'</span><span class="p">,</span> <span class="n">description</span><span class="o">=</span><span class="s">"User is allowed to access frozzles"</span><span class="p">)</span> </pre></div> </div> <p>will set up a new “View” permission on the Class “frozzle”.</p> </li> <li><p class="first">enable it for the Roles that should have it (verify with “<tt class="docutils literal"><span class="pre">roundup-admin</span> <span class="pre">security</span></tt>“)</p> </li> <li><p class="first">add it to the relevant HTML interface templates</p> </li> <li><p class="first">add it to the appropriate xxxPermission methods on in your tracker interfaces module</p> </li> </ol> <p>The <tt class="docutils literal"><span class="pre">addPermission</span></tt> method takes a couple of optional parameters:</p> <dl class="docutils"> <dt><strong>properties</strong></dt> <dd>A sequence of property names that are the only properties to apply the new Permission to (eg. <tt class="docutils literal"><span class="pre">...</span> <span class="pre">klass='user',</span> <span class="pre">properties=('name',</span> <span class="pre">'email')</span> <span class="pre">...</span></tt>)</dd> <dt><strong>check</strong></dt> <dd>A function to be execute which returns boolean determining whether the Permission is allowed. The function has the signature <tt class="docutils literal"><span class="pre">check(db,</span> <span class="pre">userid,</span> <span class="pre">itemid)</span></tt> where <tt class="docutils literal"><span class="pre">db</span></tt> is a handle on the open database, <tt class="docutils literal"><span class="pre">userid</span></tt> is the user attempting access and <tt class="docutils literal"><span class="pre">itemid</span></tt> is the specific item being accessed.</dd> </dl> </div> <div class="section" id="example-scenarios"> <h4>Example Scenarios</h4> <p>See the <a class="reference internal" href="#examples">examples</a> section for longer examples of customisation.</p> <dl class="docutils"> <dt><strong>anonymous access through the e-mail gateway</strong></dt> <dd>Give the “anonymous” user the “Email Access”, (“Edit”, “issue”) and (“Create”, “msg”) Permissions but do not not give them the (“Create”, “user”) Permission. This means that when an unknown user sends email into the tracker, they’re automatically logged in as “anonymous”. Since they don’t have the (“Create”, “user”) Permission, they won’t be automatically registered, but since “anonymous” has permission to use the gateway, they’ll still be able to submit issues. Note that the Sender information - their email address - will not be available - they’re <em>anonymous</em>.</dd> <dt><strong>automatic registration of users in the e-mail gateway</strong></dt> <dd>By giving the “anonymous” user the (“Register”, “user”) Permission, any unidentified user will automatically be registered with the tracker (with no password, so they won’t be able to log in through the web until an admin sets their password). By default new Roundup trackers don’t allow this as it opens them up to spam. It may be enabled by uncommenting the appropriate addPermissionToRole in your tracker’s <tt class="docutils literal"><span class="pre">schema.py</span></tt> file. The new user is given the Roles list defined in the “new_email_user_roles” config variable.</dd> <dt><strong>only developers may be assigned issues</strong></dt> <dd>Create a new Permission called “Fixer” for the “issue” class. Create a new Role “Developer” which has that Permission, and assign that to the appropriate users. Filter the list of users available in the assignedto list to include only those users. Enforce the Permission with an auditor. See the example <a class="reference internal" href="#restricting-the-list-of-users-that-are-assignable-to-a-task">restricting the list of users that are assignable to a task</a>.</dd> <dt><strong>only managers may sign off issues as complete</strong></dt> <dd><p class="first">Create a new Permission called “Closer” for the “issue” class. Create a new Role “Manager” which has that Permission, and assign that to the appropriate users. In your web interface, only display the “resolved” issue state option when the user has the “Closer” Permissions. Enforce the Permission with an auditor. This is very similar to the previous example, except that the web interface check would look like:</p> <div class="last highlight-python"><pre><option tal:condition="python:request.user.hasPermission('Closer')" value="resolved">Resolved</option></pre> </div> </dd> <dt><strong>don’t give web access to users who register through email</strong></dt> <dd>Create a new Role called “Email User” which has all the Permissions of the normal “User” Role minus the “Web Access” Permission. This will allow users to send in emails to the tracker, but not access the web interface.</dd> <dt><strong>let some users edit the details of all users</strong></dt> <dd><p class="first">Create a new Role called “User Admin” which has the Permission for editing users:</p> <div class="highlight-python"><div class="highlight"><pre><span class="n">db</span><span class="o">.</span><span class="n">security</span><span class="o">.</span><span class="n">addRole</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s">'User Admin'</span><span class="p">,</span> <span class="n">description</span><span class="o">=</span><span class="s">'Managing users'</span><span class="p">)</span> <span class="n">p</span> <span class="o">=</span> <span class="n">db</span><span class="o">.</span><span class="n">security</span><span class="o">.</span><span class="n">getPermission</span><span class="p">(</span><span class="s">'Edit'</span><span class="p">,</span> <span class="s">'user'</span><span class="p">)</span> <span class="n">db</span><span class="o">.</span><span class="n">security</span><span class="o">.</span><span class="n">addPermissionToRole</span><span class="p">(</span><span class="s">'User Admin'</span><span class="p">,</span> <span class="n">p</span><span class="p">)</span> </pre></div> </div> <p class="last">and assign the Role to the users who need the permission.</p> </dd> </dl> </div> </div> </div> <div class="section" id="web-interface"> <h2>Web Interface</h2> <div class="contents local topic" id="id3"> <ul class="simple"> <li><a class="reference internal" href="#repercussions-of-changing-the-tracker-schema" id="id7">Repercussions of changing the tracker schema</a></li> <li><a class="reference internal" href="#how-requests-are-processed" id="id8">How requests are processed</a></li> <li><a class="reference internal" href="#determining-web-context" id="id9">Determining web context</a></li> <li><a class="reference internal" href="#the-home-context" id="id10">The “home” Context</a></li> <li><a class="reference internal" href="#serving-static-content" id="id11">Serving static content</a></li> <li><a class="reference internal" href="#performing-actions-in-web-requests" id="id12">Performing actions in web requests</a></li> <li><a class="reference internal" href="#special-form-variables" id="id13">Special form variables</a></li> <li><a class="reference internal" href="#default-templates" id="id14">Default templates</a></li> <li><a class="reference internal" href="#how-the-templates-work" id="id15">How the templates work</a><ul> <li><a class="reference internal" href="#basic-templating-actions" id="id16">Basic Templating Actions</a></li> <li><a class="reference internal" href="#templating-expressions" id="id17">Templating Expressions</a></li> <li><a class="reference internal" href="#template-macros" id="id18">Template Macros</a></li> </ul> </li> <li><a class="reference internal" href="#information-available-to-templates" id="id19">Information available to templates</a><ul> <li><a class="reference internal" href="#the-context-variable" id="id20">The context variable</a><ul> <li><a class="reference internal" href="#hyperdb-class-wrapper" id="id21">Hyperdb class wrapper</a></li> <li><a class="reference internal" href="#hyperdb-item-wrapper" id="id22">Hyperdb item wrapper</a></li> <li><a class="reference internal" href="#hyperdb-property-wrapper" id="id23">Hyperdb property wrapper</a></li> </ul> </li> <li><a class="reference internal" href="#the-request-variable" id="id24">The request variable</a><ul> <li><a class="reference internal" href="#the-form-variable" id="id25">The form variable</a></li> </ul> </li> <li><a class="reference internal" href="#the-db-variable" id="id26">The db variable</a></li> <li><a class="reference internal" href="#the-templates-variable" id="id27">The templates variable</a></li> <li><a class="reference internal" href="#the-repeat-variable" id="id28">The repeat variable</a></li> <li><a class="reference internal" href="#the-utils-variable" id="id29">The utils variable</a><ul> <li><a class="reference internal" href="#batching" id="id30">Batching</a></li> </ul> </li> <li><a class="reference internal" href="#translations" id="id31">Translations</a></li> </ul> </li> <li><a class="reference internal" href="#displaying-properties" id="id32">Displaying Properties</a></li> <li><a class="reference internal" href="#index-views" id="id33">Index Views</a><ul> <li><a class="reference internal" href="#index-view-specifiers" id="id34">Index View Specifiers</a></li> </ul> </li> <li><a class="reference internal" href="#searching-views" id="id35">Searching Views</a></li> <li><a class="reference internal" href="#item-views" id="id36">Item Views</a><ul> <li><a class="reference internal" href="#editor-section" id="id37">Editor Section</a><ul> <li><a class="reference internal" href="#form-values" id="id38">Form values</a></li> </ul> </li> <li><a class="reference internal" href="#spool-section" id="id39">Spool Section</a></li> <li><a class="reference internal" href="#history-section" id="id40">History Section</a></li> </ul> </li> <li><a class="reference internal" href="#defining-new-web-actions" id="id41">Defining new web actions</a><ul> <li><a class="reference internal" href="#define-the-new-action-class" id="id42">Define the new action class</a></li> <li><a class="reference internal" href="#register-the-action-class" id="id43">Register the action class</a></li> <li><a class="reference internal" href="#use-the-new-action" id="id44">Use the new action</a></li> <li><a class="reference internal" href="#actions-may-return-content-to-the-user" id="id45">Actions may return content to the user</a></li> </ul> </li> <li><a class="reference internal" href="#bit-character-set-support-in-web-interface" id="id46">8-bit character set support in Web interface</a></li> </ul> </div> <p>The web interface is provided by the <tt class="docutils literal"><span class="pre">roundup.cgi.client</span></tt> module and is used by <tt class="docutils literal"><span class="pre">roundup.cgi</span></tt>, <tt class="docutils literal"><span class="pre">roundup-server</span></tt> and <tt class="docutils literal"><span class="pre">ZRoundup</span></tt> (<tt class="docutils literal"><span class="pre">ZRoundup</span></tt> is broken, until further notice). In all cases, we determine which tracker is being accessed (the first part of the URL path inside the scope of the CGI handler) and pass control on to the <tt class="docutils literal"><span class="pre">roundup.cgi.client.Client</span></tt> class - which handles the rest of the access through its <tt class="docutils literal"><span class="pre">main()</span></tt> method. This means that you can do pretty much anything you want as a web interface to your tracker.</p> <div class="section" id="repercussions-of-changing-the-tracker-schema"> <h3><a class="toc-backref" href="#id7">Repercussions of changing the tracker schema</a></h3> <p>If you choose to change the <a class="reference internal" href="#tracker-schema">tracker schema</a> you will need to ensure the web interface knows about it:</p> <ol class="arabic simple"> <li>Index, item and search pages for the relevant classes may need to have properties added or removed,</li> <li>The “page” template may require links to be changed, as might the “home” page’s content arguments.</li> </ol> </div> <div class="section" id="how-requests-are-processed"> <h3><a class="toc-backref" href="#id8">How requests are processed</a></h3> <p>The basic processing of a web request proceeds as follows:</p> <ol class="arabic simple"> <li>figure out who we are, defaulting to the “anonymous” user</li> <li>figure out what the request is for - we call this the “context”</li> <li>handle any requested action (item edit, search, ...)</li> <li>render the template requested by the context, resulting in HTML output</li> </ol> <p>In some situations, exceptions occur:</p> <ul> <li><p class="first">HTTP Redirect (generally raised by an action)</p> </li> <li><dl class="first docutils"> <dt>SendFile (generally raised by <tt class="docutils literal"><span class="pre">determine_context</span></tt>)</dt> <dd><p class="first last">here we serve up a FileClass “content” property</p> </dd> </dl> </li> <li><dl class="first docutils"> <dt>SendStaticFile (generally raised by <tt class="docutils literal"><span class="pre">determine_context</span></tt>)</dt> <dd><p class="first last">here we serve up a file from the tracker “html” directory</p> </dd> </dl> </li> <li><dl class="first docutils"> <dt>Unauthorised (generally raised by an action)</dt> <dd><p class="first last">here the action is cancelled, the request is rendered and an error message is displayed indicating that permission was not granted for the action to take place</p> </dd> </dl> </li> <li><dl class="first docutils"> <dt>NotFound (raised wherever it needs to be)</dt> <dd><p class="first last">this exception percolates up to the CGI interface that called the client</p> </dd> </dl> </li> </ul> </div> <div class="section" id="determining-web-context"> <h3><a class="toc-backref" href="#id9">Determining web context</a></h3> <p>To determine the “context” of a request, we look at the URL and the special request variable <tt class="docutils literal"><span class="pre">@template</span></tt>. The URL path after the tracker identifier is examined. Typical URL paths look like:</p> <ol class="arabic simple"> <li><tt class="docutils literal"><span class="pre">/tracker/issue</span></tt></li> <li><tt class="docutils literal"><span class="pre">/tracker/issue1</span></tt></li> <li><tt class="docutils literal"><span class="pre">/tracker/@@file/style.css</span></tt></li> <li><tt class="docutils literal"><span class="pre">/cgi-bin/roundup.cgi/tracker/file1</span></tt></li> <li><tt class="docutils literal"><span class="pre">/cgi-bin/roundup.cgi/tracker/file1/kitten.png</span></tt></li> </ol> <p>where the “tracker identifier” is “tracker” in the above cases. That means we’re looking at “issue”, “issue1”, “@@file/style.css”, “file1” and “file1/kitten.png” in the cases above. The path is generally only one entry long - longer paths are handled differently.</p> <ol class="loweralpha simple"> <li>if there is no path, then we are in the “home” context. See <a class="reference internal" href="#the-home-context">the “home” context</a> below for more information about how it may be used.</li> <li>if the path starts with “@@file” (as in example 3, “/tracker/@@file/style.css”), then the additional path entry, “style.css” specifies the filename of a static file we’re to serve up from the tracker TEMPLATES (or STATIC_FILES, if configured) directory. This is usually the tracker’s “html” directory. Raises a SendStaticFile exception.</li> <li>if there is something in the path (as in example 1, “issue”), it identifies the tracker class we’re to display.</li> <li>if the path is an item designator (as in examples 2 and 4, “issue1” and “file1”), then we’re to display a specific item.</li> <li>if the path starts with an item designator and is longer than one entry (as in example 5, “file1/kitten.png”), then we’re assumed to be handling an item of a <tt class="docutils literal"><span class="pre">FileClass</span></tt>, and the extra path information gives the filename that the client is going to label the download with (i.e. “file1/kitten.png” is nicer to download than “file1”). This raises a <tt class="docutils literal"><span class="pre">SendFile</span></tt> exception.</li> </ol> <p>Both b. and e. stop before we bother to determine the template we’re going to use. That’s because they don’t actually use templates.</p> <p>The template used is specified by the <tt class="docutils literal"><span class="pre">@template</span></tt> CGI variable, which defaults to:</p> <ul class="simple"> <li>only classname suplied: “index”</li> <li>full item designator supplied: “item”</li> </ul> </div> <div class="section" id="the-home-context"> <h3><a class="toc-backref" href="#id10">The “home” Context</a></h3> <p>The “home” context is special because it allows you to add templated pages to your tracker that don’t rely on a class or item (ie. an issues list or specific issue).</p> <p>Let’s say you wish to add frames to control the layout of your tracker’s interface. You’d probably have:</p> <ul> <li><p class="first">A top-level frameset page. This page probably wouldn’t be templated, so it could be served as a static file (see <a class="reference internal" href="#serving-static-content">serving static content</a>)</p> </li> <li><p class="first">A sidebar frame that is templated. Let’s call this page “home.navigation.html” in your tracker’s “html” directory. To load that page up, you use the URL:</p> <blockquote> <p><tracker url>/<a class="reference external" href="mailto:home?%40template=navigation">home?<span>@</span>template=navigation</a></p> </blockquote> </li> </ul> </div> <div class="section" id="serving-static-content"> <h3><a class="toc-backref" href="#id11">Serving static content</a></h3> <p>See the previous section <a class="reference internal" href="#determining-web-context">determining web context</a> where it describes <tt class="docutils literal"><span class="pre">@@file</span></tt> paths.</p> </div> <div class="section" id="performing-actions-in-web-requests"> <h3><a class="toc-backref" href="#id12">Performing actions in web requests</a></h3> <p>When a user requests a web page, they may optionally also request for an action to take place. As described in <a class="reference internal" href="#how-requests-are-processed">how requests are processed</a>, the action is performed before the requested page is generated. Actions are triggered by using a <tt class="docutils literal"><span class="pre">@action</span></tt> CGI variable, where the value is one of:</p> <dl class="docutils"> <dt><strong>login</strong></dt> <dd>Attempt to log a user in.</dd> <dt><strong>logout</strong></dt> <dd>Log the user out - make them “anonymous”.</dd> <dt><strong>register</strong></dt> <dd>Attempt to create a new user based on the contents of the form and then log them in.</dd> <dt><strong>edit</strong></dt> <dd>Perform an edit of an item in the database. There are some <a class="reference internal" href="#special-form-variables">special form variables</a> you may use.</dd> <dt><strong>new</strong></dt> <dd>Add a new item to the database. You may use the same <a class="reference internal" href="#special-form-variables">special form variables</a> as in the “edit” action.</dd> <dt><strong>retire</strong></dt> <dd>Retire the item in the database.</dd> <dt><strong>editCSV</strong></dt> <dd>Performs an edit of all of a class’ items in one go. See also the <em>class</em>.csv templating method which generates the CSV data to be edited, and the <tt class="docutils literal"><span class="pre">'_generic.index'</span></tt> template which uses both of these features.</dd> <dt><strong>search</strong></dt> <dd><p class="first">Mangle some of the form variables:</p> <ul class="last simple"> <li>Set the form “:filter” variable based on the values of the filter variables - if they’re set to anything other than “dontcare” then add them to :filter.</li> <li>Also handle the “:queryname” variable and save off the query to the user’s query list.</li> </ul> </dd> </dl> <p>Each of the actions is implemented by a corresponding <tt class="docutils literal"><span class="pre">*XxxAction*</span></tt> (where “Xxx” is the name of the action) class in the <tt class="docutils literal"><span class="pre">roundup.cgi.actions</span></tt> module. These classes are registered with <tt class="docutils literal"><span class="pre">roundup.cgi.client.Client</span></tt>. If you need to define new actions, you may add them there (see <a class="reference internal" href="#defining-new-web-actions">defining new web actions</a>).</p> <p>Each action class also has a <tt class="docutils literal"><span class="pre">*permission*</span></tt> method which determines whether the action is permissible given the current user. The base permission checks for each action are:</p> <dl class="docutils"> <dt><strong>login</strong></dt> <dd>Determine whether the user has the “Web Access” Permission.</dd> <dt><strong>logout</strong></dt> <dd>No permission checks are made.</dd> <dt><strong>register</strong></dt> <dd>Determine whether the user has the (“Create”, “user”) Permission.</dd> <dt><strong>edit</strong></dt> <dd>Determine whether the user has permission to edit this item. If we’re editing the “user” class, users are allowed to edit their own details - unless they try to edit the “roles” property, which requires the special Permission “Web Roles”.</dd> <dt><strong>new</strong></dt> <dd>Determine whether the user has permission to create this item. No additional property checks are made. Additionally, new user items may be created if the user has the (“Create”, “user”) Permission.</dd> <dt><strong>editCSV</strong></dt> <dd>Determine whether the user has permission to edit this class.</dd> <dt><strong>search</strong></dt> <dd>Determine whether the user has permission to view this class.</dd> </dl> </div> <div class="section" id="special-form-variables"> <h3><a class="toc-backref" href="#id13">Special form variables</a></h3> <p>Item properties and their values are edited with html FORM variables and their values. You can:</p> <ul class="simple"> <li>Change the value of some property of the current item.</li> <li>Create a new item of any class, and edit the new item’s properties,</li> <li>Attach newly created items to a multilink property of the current item.</li> <li>Remove items from a multilink property of the current item.</li> <li>Specify that some properties are required for the edit operation to be successful.</li> <li>Set up user interface locale.</li> </ul> <p>These operations will only take place if the form action (the <tt class="docutils literal"><span class="pre">@action</span></tt> variable) is “edit” or “new”.</p> <p>In the following, <bracketed> values are variable, “@” may be either “:” or “@”, and other text “required” is fixed.</p> <p>Two special form variables are used to specify user language preferences:</p> <dl class="docutils"> <dt><tt class="docutils literal"><span class="pre">@language</span></tt></dt> <dd>value may be locale name or <tt class="docutils literal"><span class="pre">none</span></tt>. If this variable is set to locale name, web interface language is changed to given value (provided that appropriate translation is available), the value is stored in the browser cookie and will be used for all following requests. If value is <tt class="docutils literal"><span class="pre">none</span></tt> the cookie is removed and the language is changed to the tracker default, set up in the tracker configuration or OS environment.</dd> <dt><tt class="docutils literal"><span class="pre">@charset</span></tt></dt> <dd>value may be character set name or <tt class="docutils literal"><span class="pre">none</span></tt>. Character set name is stored in the browser cookie and sets output encoding for all HTML pages generated by Roundup. If value is <tt class="docutils literal"><span class="pre">none</span></tt> the cookie is removed and HTML output is reset to Roundup internal encoding (UTF-8).</dd> </dl> <p>Most properties are specified as form variables:</p> <dl class="docutils"> <dt><tt class="docutils literal"><span class="pre"><propname></span></tt></dt> <dd>property on the current context item</dd> <dt><tt class="docutils literal"><span class="pre"><designator>"@"<propname></span></tt></dt> <dd>property on the indicated item (for editing related information)</dd> </dl> <p>Designators name a specific item of a class.</p> <dl class="docutils"> <dt><tt class="docutils literal"><span class="pre"><classname><N></span></tt></dt> <dd>Name an existing item of class <classname>.</dd> <dt><tt class="docutils literal"><span class="pre"><classname>"-"<N></span></tt></dt> <dd>Name the <N>th new item of class <classname>. If the form submission is successful, a new item of <classname> is created. Within the submitted form, a particular designator of this form always refers to the same new item.</dd> </dl> <p>Once we have determined the “propname”, we look at it to see if it’s special:</p> <dl class="docutils"> <dt><tt class="docutils literal"><span class="pre">@required</span></tt></dt> <dd><p class="first">The associated form value is a comma-separated list of property names that must be specified when the form is submitted for the edit operation to succeed.</p> <p>When the <designator> is missing, the properties are for the current context item. When <designator> is present, they are for the item specified by <designator>.</p> <p class="last">The “@required” specifier must come before any of the properties it refers to are assigned in the form.</p> </dd> <dt><tt class="docutils literal"><span class="pre">@remove@<propname>=id(s)</span></tt> or <tt class="docutils literal"><span class="pre">@add@<propname>=id(s)</span></tt></dt> <dd>The “@add@” and “@remove@” edit actions apply only to Multilink properties. The form value must be a comma-separate list of keys for the class specified by the simple form variable. The listed items are added to (respectively, removed from) the specified property.</dd> <dt><tt class="docutils literal"><span class="pre">@link@<propname>=<designator></span></tt></dt> <dd>If the edit action is “@link@”, the simple form variable must specify a Link or Multilink property. The form value is a comma-separated list of designators. The item corresponding to each designator is linked to the property given by simple form variable.</dd> <dt>None of the above (ie. just a simple form value)</dt> <dd><p class="first">The value of the form variable is converted appropriately, depending on the type of the property.</p> <p>For a Link(‘klass’) property, the form value is a single key for ‘klass’, where the key field is specified in schema.py.</p> <p>For a Multilink(‘klass’) property, the form value is a comma-separated list of keys for ‘klass’, where the key field is specified in schema.py.</p> <p>Note that for simple-form-variables specifiying Link and Multilink properties, the linked-to class must have a key field.</p> <p>For a String() property specifying a filename, the file named by the form value is uploaded. This means we try to set additional properties “filename” and “type” (if they are valid for the class). Otherwise, the property is set to the form value.</p> <p class="last">For Date(), Interval(), Boolean(), and Number() properties, the form value is converted to the appropriate</p> </dd> </dl> <p>Any of the form variables may be prefixed with a classname or designator.</p> <p>Two special form values are supported for backwards compatibility:</p> <dl class="docutils"> <dt>@note</dt> <dd><p class="first">This is equivalent to:</p> <div class="highlight-python"><pre>@link@messages=msg-1 msg-1@content=value</pre> </div> <p class="last">except that in addition, the “author” and “date” properties of “msg-1” are set to the userid of the submitter, and the current time, respectively.</p> </dd> <dt>@file</dt> <dd><p class="first">This is equivalent to:</p> <div class="highlight-python"><pre>@link@files=file-1 file-1@content=value</pre> </div> <p class="last">The String content value is handled as described above for file uploads.</p> </dd> </dl> <p>If both the “@note” and “@file” form variables are specified, the action:</p> <div class="highlight-python"><pre>@link@msg-1@files=file-1</pre> </div> <p>is also performed.</p> <p>We also check that FileClass items have a “content” property with actual content, otherwise we remove them from all_props before returning.</p> </div> <div class="section" id="default-templates"> <h3><a class="toc-backref" href="#id14">Default templates</a></h3> <p>The default templates are html4 compliant. If you wish to change them to be xhtml compliant, you’ll need to change the <tt class="docutils literal"><span class="pre">html_version</span></tt> configuration variable in <tt class="docutils literal"><span class="pre">config.ini</span></tt> to <tt class="docutils literal"><span class="pre">'xhtml'</span></tt> instead of <tt class="docutils literal"><span class="pre">'html4'</span></tt>.</p> <p>Most customisation of the web view can be done by modifying the templates in the tracker <tt class="docutils literal"><span class="pre">'html'</span></tt> directory. There are several types of files in there. The <em>minimal</em> template includes:</p> <dl class="docutils"> <dt><strong>page.html</strong></dt> <dd>This template usually defines the overall look of your tracker. When you view an issue, it appears inside this template. When you view an index, it also appears inside this template. This template defines a macro called “icing” which is used by almost all other templates as a coating for their content, using its “content” slot. It also defines the “head_title” and “body_title” slots to allow setting of the page title.</dd> <dt><strong>home.html</strong></dt> <dd>the default page displayed when no other page is indicated by the user</dd> <dt><strong>home.classlist.html</strong></dt> <dd>a special version of the default page that lists the classes in the tracker</dd> <dt><strong>classname.item.html</strong></dt> <dd>displays an item of the <em>classname</em> class</dd> <dt><strong>classname.index.html</strong></dt> <dd>displays a list of <em>classname</em> items</dd> <dt><strong>classname.search.html</strong></dt> <dd>displays a search page for <em>classname</em> items</dd> <dt><strong>_generic.index.html</strong></dt> <dd>used to display a list of items where there is no <tt class="docutils literal"><span class="pre">*classname*.index</span></tt> available</dd> <dt><strong>_generic.help.html</strong></dt> <dd>used to display a “class help” page where there is no <tt class="docutils literal"><span class="pre">*classname*.help</span></tt></dd> <dt><strong>user.register.html</strong></dt> <dd>a special page just for the user class, that renders the registration page</dd> <dt><strong>style.css</strong></dt> <dd>a static file that is served up as-is</dd> </dl> <p>The <em>classic</em> template has a number of additional templates.</p> <p>Remember that you can create any template extension you want to, so if you just want to play around with the templating for new issues, you can copy the current “issue.item” template to “issue.test”, and then access the test template using the “@template” URL argument:</p> <div class="highlight-python"><pre>http://your.tracker.example/tracker/issue?@template=test</pre> </div> <p>and it won’t affect your users using the “issue.item” template.</p> </div> <div class="section" id="how-the-templates-work"> <h3><a class="toc-backref" href="#id15">How the templates work</a></h3> <div class="section" id="basic-templating-actions"> <h4><a class="toc-backref" href="#id16">Basic Templating Actions</a></h4> <p>Roundup’s templates consist of special attributes on the HTML tags. These attributes form the <a class="reference external" href="http://dev.zope.org/Wikis/DevSite/Projects/ZPT/TAL%20Specification%201.4">Template Attribute Language</a>, or TAL. The basic TAL commands are:</p> <dl class="docutils"> <dt><strong>tal:define=”variable expression; variable expression; ...”</strong></dt> <dd><p class="first">Define a new variable that is local to this tag and its contents. For example:</p> <div class="highlight-python"><pre><html tal:define="title request/description"> <head><title tal:content="title"></title></head> </html></pre> </div> <p class="last">In this example, the variable “title” is defined as the result of the expression “request/description”. The “tal:content” command inside the <html> tag may then use the “title” variable.</p> </dd> <dt><strong>tal:condition=”expression”</strong></dt> <dd><p class="first">Only keep this tag and its contents if the expression is true. For example:</p> <div class="highlight-python"><pre><p tal:condition="python:request.user.hasPermission('View', 'issue')"> Display some issue information. </p></pre> </div> <p class="last">In the example, the <p> tag and its contents are only displayed if the user has the “View” permission for issues. We consider the number zero, a blank string, an empty list, and the built-in variable nothing to be false values. Nearly every other value is true, including non-zero numbers, and strings with anything in them (even spaces!).</p> </dd> <dt><strong>tal:repeat=”variable expression”</strong></dt> <dd><p class="first">Repeat this tag and its contents for each element of the sequence that the expression returns, defining a new local variable and a special “repeat” variable for each element. For example:</p> <div class="highlight-python"><pre><tr tal:repeat="u user/list"> <td tal:content="u/id"></td> <td tal:content="u/username"></td> <td tal:content="u/realname"></td> </tr></pre> </div> <p class="last">The example would iterate over the sequence of users returned by “user/list” and define the local variable “u” for each entry. Using the repeat command creates a new variable called “repeat” which you may access to gather information about the iteration. See the section below on <a class="reference internal" href="#the-repeat-variable">the repeat variable</a>.</p> </dd> <dt><strong>tal:replace=”expression”</strong></dt> <dd><p class="first">Replace this tag with the result of the expression. For example:</p> <div class="highlight-python"><pre><span tal:replace="request/user/realname" /></pre> </div> <p class="last">The example would replace the <span> tag and its contents with the user’s realname. If the user’s realname was “Bruce”, then the resultant output would be “Bruce”.</p> </dd> <dt><strong>tal:content=”expression”</strong></dt> <dd><p class="first">Replace the contents of this tag with the result of the expression. For example:</p> <div class="highlight-python"><pre><span tal:content="request/user/realname">user's name appears here </span></pre> </div> <p class="last">The example would replace the contents of the <span> tag with the user’s realname. If the user’s realname was “Bruce” then the resultant output would be “<span>Bruce</span>”.</p> </dd> <dt><strong>tal:attributes=”attribute expression; attribute expression; ...”</strong></dt> <dd><p class="first">Set attributes on this tag to the results of expressions. For example:</p> <div class="highlight-python"><pre><a tal:attributes="href string:user${request/user/id}">My Details</a></pre> </div> <p class="last">In the example, the “href” attribute of the <a> tag is set to the value of the “string:user${request/user/id}” expression, which will be something like “user123”.</p> </dd> <dt><strong>tal:omit-tag=”expression”</strong></dt> <dd><p class="first">Remove this tag (but not its contents) if the expression is true. For example:</p> <div class="highlight-python"><pre><span tal:omit-tag="python:1">Hello, world!</span></pre> </div> <p>would result in output of:</p> <div class="last highlight-python"><pre>Hello, world!</pre> </div> </dd> </dl> <p>Note that the commands on a given tag are evaulated in the order above, so <em>define</em> comes before <em>condition</em>, and so on.</p> <p>Additionally, you may include tags such as <tal:block>, which are removed from output. Its content is kept, but the tag itself is not (so don’t go using any “tal:attributes” commands on it). This is useful for making arbitrary blocks of HTML conditional or repeatable (very handy for repeating multiple table rows, which would othewise require an illegal tag placement to effect the repeat).</p> </div> <div class="section" id="templating-expressions"> <h4><a class="toc-backref" href="#id17">Templating Expressions</a></h4> <p>Templating Expressions are covered by <a class="reference external" href="http://dev.zope.org/Wikis/DevSite/Projects/ZPT/TALES%20Specification%201.3">Template Attribute Language Expression Syntax</a>, or TALES. The expressions you may use in the attribute values may be one of the following forms:</p> <dl class="docutils"> <dt><strong>Path Expressions</strong> - eg. <tt class="docutils literal"><span class="pre">item/status/checklist</span></tt></dt> <dd><p class="first">These are object attribute / item accesses. Roughly speaking, the path <tt class="docutils literal"><span class="pre">item/status/checklist</span></tt> is broken into parts <tt class="docutils literal"><span class="pre">item</span></tt>, <tt class="docutils literal"><span class="pre">status</span></tt> and <tt class="docutils literal"><span class="pre">checklist</span></tt>. The <tt class="docutils literal"><span class="pre">item</span></tt> part is the root of the expression. We then look for a <tt class="docutils literal"><span class="pre">status</span></tt> attribute on <tt class="docutils literal"><span class="pre">item</span></tt>, or failing that, a <tt class="docutils literal"><span class="pre">status</span></tt> item (as in <tt class="docutils literal"><span class="pre">item['status']</span></tt>). If that fails, the path expression fails. When we get to the end, the object we’re left with is evaluated to get a string - if it is a method, it is called; if it is an object, it is stringified. Path expressions may have an optional <tt class="docutils literal"><span class="pre">path:</span></tt> prefix, but they are the default expression type, so it’s not necessary.</p> <p>If an expression evaluates to <tt class="docutils literal"><span class="pre">default</span></tt>, then the expression is “cancelled” - whatever HTML already exists in the template will remain (tag content in the case of <tt class="docutils literal"><span class="pre">tal:content</span></tt>, attributes in the case of <tt class="docutils literal"><span class="pre">tal:attributes</span></tt>).</p> <p>If an expression evaluates to <tt class="docutils literal"><span class="pre">nothing</span></tt> then the target of the expression is removed (tag content in the case of <tt class="docutils literal"><span class="pre">tal:content</span></tt>, attributes in the case of <tt class="docutils literal"><span class="pre">tal:attributes</span></tt> and the tag itself in the case of <tt class="docutils literal"><span class="pre">tal:replace</span></tt>).</p> <p>If an element in the path may not exist, then you can use the <tt class="docutils literal"><span class="pre">|</span></tt> operator in the expression to provide an alternative. So, the expression <tt class="docutils literal"><span class="pre">request/form/foo/value</span> <span class="pre">|</span> <span class="pre">default</span></tt> would simply leave the current HTML in place if the “foo” form variable doesn’t exist.</p> <p class="last">You may use the python function <tt class="docutils literal"><span class="pre">path</span></tt>, as in <tt class="docutils literal"><span class="pre">path("item/status")</span></tt>, to embed path expressions in Python expressions.</p> </dd> <dt><strong>String Expressions</strong> - eg. <tt class="docutils literal"><span class="pre">string:hello</span> <span class="pre">${user/name}</span></tt></dt> <dd>These expressions are simple string interpolations - though they can be just plain strings with no interpolation if you want. The expression in the <tt class="docutils literal"><span class="pre">${</span> <span class="pre">...</span> <span class="pre">}</span></tt> is just a path expression as above.</dd> <dt><strong>Python Expressions</strong> - eg. <tt class="docutils literal"><span class="pre">python:</span> <span class="pre">1+1</span></tt></dt> <dd>These expressions give the full power of Python. All the “root level” variables are available, so <tt class="docutils literal"><span class="pre">python:item.status.checklist()</span></tt> would be equivalent to <tt class="docutils literal"><span class="pre">item/status/checklist</span></tt>, assuming that <tt class="docutils literal"><span class="pre">checklist</span></tt> is a method.</dd> </dl> <p>Modifiers:</p> <dl class="docutils"> <dt><strong>structure</strong> - eg. <tt class="docutils literal"><span class="pre">structure</span> <span class="pre">python:msg.content.plain(hyperlink=1)</span></tt></dt> <dd>The result of expressions are normally <em>escaped</em> to be safe for HTML display (all “<”, “>” and “&” are turned into special entities). The <tt class="docutils literal"><span class="pre">structure</span></tt> expression modifier turns off this escaping - the result of the expression is now assumed to be HTML, which is passed to the web browser for rendering.</dd> <dt><strong>not:</strong> - eg. <tt class="docutils literal"><span class="pre">not:python:1=1</span></tt></dt> <dd>This simply inverts the logical true/false value of another expression.</dd> </dl> </div> <div class="section" id="template-macros"> <h4><a class="toc-backref" href="#id18">Template Macros</a></h4> <p>Macros are used in Roundup to save us from repeating the same common page stuctures over and over. The most common (and probably only) macro you’ll use is the “icing” macro defined in the “page” template.</p> <p>Macros are generated and used inside your templates using special attributes similar to the <a class="reference internal" href="#basic-templating-actions">basic templating actions</a>. In this case, though, the attributes belong to the <a class="reference external" href="http://dev.zope.org/Wikis/DevSite/Projects/ZPT/METAL%20Specification%201.0">Macro Expansion Template Attribute Language</a>, or METAL. The macro commands are:</p> <dl class="docutils"> <dt><strong>metal:define-macro=”macro name”</strong></dt> <dd><p class="first">Define that the tag and its contents are now a macro that may be inserted into other templates using the <em>use-macro</em> command. For example:</p> <div class="highlight-python"><pre><html metal:define-macro="page"> ... </html></pre> </div> <p class="last">defines a macro called “page” using the <tt class="docutils literal"><span class="pre"><html></span></tt> tag and its contents. Once defined, macros are stored on the template they’re defined on in the <tt class="docutils literal"><span class="pre">macros</span></tt> attribute. You can access them later on through the <tt class="docutils literal"><span class="pre">templates</span></tt> variable, eg. the most common <tt class="docutils literal"><span class="pre">templates/page/macros/icing</span></tt> to access the “page” macro of the “page” template.</p> </dd> <dt><strong>metal:use-macro=”path expression”</strong></dt> <dd><p class="first">Use a macro, which is identified by the path expression (see above). This will replace the current tag with the identified macro contents. For example:</p> <div class="last highlight-python"><pre><tal:block metal:use-macro="templates/page/macros/icing"> ... </tal:block> will replace the tag and its contents with the "page" macro of the "page" template.</pre> </div> </dd> <dt><strong>metal:define-slot=”slot name”</strong> and <strong>metal:fill-slot=”slot name”</strong></dt> <dd><p class="first">To define <em>dynamic</em> parts of the macro, you define “slots” which may be filled when the macro is used with a <em>use-macro</em> command. For example, the <tt class="docutils literal"><span class="pre">templates/page/macros/icing</span></tt> macro defines a slot like so:</p> <div class="highlight-python"><pre><title metal:define-slot="head_title">title goes here</title></pre> </div> <p>In your <em>use-macro</em> command, you may now use a <em>fill-slot</em> command like this:</p> <div class="highlight-python"><pre><title metal:fill-slot="head_title">My Title</title></pre> </div> <p class="last">where the tag that fills the slot completely replaces the one defined as the slot in the macro.</p> </dd> </dl> <p>Note that you may not mix <a class="reference external" href="http://dev.zope.org/Wikis/DevSite/Projects/ZPT/METAL%20Specification%201.0">METAL</a> and <a class="reference external" href="http://dev.zope.org/Wikis/DevSite/Projects/ZPT/TAL%20Specification%201.4">TAL</a> commands on the same tag, but TAL commands may be used freely inside METAL-using tags (so your <em>fill-slots</em> tags may have all manner of TAL inside them).</p> </div> </div> <div class="section" id="information-available-to-templates"> <h3><a class="toc-backref" href="#id19">Information available to templates</a></h3> <p>This is implemented by <tt class="docutils literal"><span class="pre">roundup.cgi.templating.RoundupPageTemplate</span></tt></p> <p>The following variables are available to templates.</p> <dl class="docutils"> <dt><strong>context</strong></dt> <dd>The current context. This is either None, a <a class="reference internal" href="#hyperdb-class-wrapper">hyperdb class wrapper</a> or a <a class="reference internal" href="#hyperdb-item-wrapper">hyperdb item wrapper</a></dd> <dt><strong>request</strong></dt> <dd><dl class="first last docutils"> <dt>Includes information about the current request, including:</dt> <dd><ul class="first last simple"> <li>the current index information (<tt class="docutils literal"><span class="pre">filterspec</span></tt>, <tt class="docutils literal"><span class="pre">filter</span></tt> args, <tt class="docutils literal"><span class="pre">properties</span></tt>, etc) parsed out of the form.</li> <li>methods for easy filterspec link generation</li> <li>“form” The current CGI form information as a mapping of form argument name to value (specifically a cgi.FieldStorage)</li> <li>“env” the CGI environment variables</li> <li>“base” the base URL for this instance</li> <li>“user” a HTMLItem instance for the current user</li> <li>“language” as determined by the browser or config</li> <li>“classname” the current classname (possibly None)</li> <li>“template” the current template (suffix, also possibly None)</li> </ul> </dd> </dl> </dd> <dt><strong>config</strong></dt> <dd>This variable holds all the values defined in the tracker config.ini file (eg. TRACKER_NAME, etc.)</dd> <dt><strong>db</strong></dt> <dd>The current database, used to access arbitrary database items.</dd> <dt><strong>templates</strong></dt> <dd>Access to all the tracker templates by name. Used mainly in <em>use-macro</em> commands.</dd> <dt><strong>utils</strong></dt> <dd>This variable makes available some utility functions like batching.</dd> <dt><strong>nothing</strong></dt> <dd><p class="first">This is a special variable - if an expression evaluates to this, then the tag (in the case of a <tt class="docutils literal"><span class="pre">tal:replace</span></tt>), its contents (in the case of <tt class="docutils literal"><span class="pre">tal:content</span></tt>) or some attributes (in the case of <tt class="docutils literal"><span class="pre">tal:attributes</span></tt>) will not appear in the the output. So, for example:</p> <div class="highlight-python"><pre><span tal:attributes="class nothing">Hello, World!</span></pre> </div> <p>would result in:</p> <div class="last highlight-python"><pre><span>Hello, World!</span></pre> </div> </dd> <dt><strong>default</strong></dt> <dd><p class="first">Also a special variable - if an expression evaluates to this, then the existing HTML in the template will not be replaced or removed, it will remain. So:</p> <div class="highlight-python"><pre><span tal:replace="default">Hello, World!</span></pre> </div> <p>would result in:</p> <div class="last highlight-python"><pre><span>Hello, World!</span></pre> </div> </dd> <dt><strong>true</strong>, <strong>false</strong></dt> <dd>Boolean constants that may be used in <a class="reference internal" href="#templating-expressions">templating expressions</a> instead of <tt class="docutils literal"><span class="pre">python:1</span></tt> and <tt class="docutils literal"><span class="pre">python:0</span></tt>.</dd> <dt><strong>i18n</strong></dt> <dd><p class="first">Internationalization service, providing two string translation methods:</p> <dl class="last docutils"> <dt><strong>gettext</strong> (<em>message</em>)</dt> <dd>Return the localized translation of message</dd> <dt><strong>ngettext</strong> (<em>singular</em>, <em>plural</em>, <em>number</em>)</dt> <dd><p class="first">Like <tt class="docutils literal"><span class="pre">gettext()</span></tt>, but consider plural forms. If a translation is found, apply the plural formula to <em>number</em>, and return the resulting message (some languages have more than two plural forms). If no translation is found, return singular if <em>number</em> is 1; return plural otherwise.</p> <p class="last">This function requires python2.3; in earlier python versions may not work as expected.</p> </dd> </dl> </dd> </dl> <div class="section" id="the-context-variable"> <h4><a class="toc-backref" href="#id20">The context variable</a></h4> <p>The <em>context</em> variable is one of three things based on the current context (see <a class="reference internal" href="#determining-web-context">determining web context</a> for how we figure this out):</p> <ol class="arabic simple"> <li>if we’re looking at a “home” page, then it’s None</li> <li>if we’re looking at a specific hyperdb class, it’s a <a class="reference internal" href="#hyperdb-class-wrapper">hyperdb class wrapper</a>.</li> <li>if we’re looking at a specific hyperdb item, it’s a <a class="reference internal" href="#hyperdb-item-wrapper">hyperdb item wrapper</a>.</li> </ol> <p>If the context is not None, we can access the properties of the class or item. The only real difference between cases 2 and 3 above are:</p> <ol class="arabic simple"> <li>the properties may have a real value behind them, and this will appear if the property is displayed through <tt class="docutils literal"><span class="pre">context/property</span></tt> or <tt class="docutils literal"><span class="pre">context/property/field</span></tt>.</li> <li>the context’s “id” property will be a false value in the second case, but a real, or true value in the third. Thus we can determine whether we’re looking at a real item from the hyperdb by testing “context/id”.</li> </ol> <div class="section" id="hyperdb-class-wrapper"> <h5><a class="toc-backref" href="#id21">Hyperdb class wrapper</a></h5> <p>This is implemented by the <tt class="docutils literal"><span class="pre">roundup.cgi.templating.HTMLClass</span></tt> class.</p> <p>This wrapper object provides access to a hyperdb class. It is used primarily in both index view and new item views, but it’s also usable anywhere else that you wish to access information about a class, or the items of a class, when you don’t have a specific item of that class in mind.</p> <p>We allow access to properties. There will be no “id” property. The value accessed through the property will be the current value of the same name from the CGI form.</p> <p>There are several methods available on these wrapper objects:</p> <table border="1" class="docutils"> <colgroup> <col width="15%" /> <col width="85%" /> </colgroup> <thead valign="bottom"> <tr><th class="head">Method</th> <th class="head">Description</th> </tr> </thead> <tbody valign="top"> <tr><td>properties</td> <td>return a <a class="reference internal" href="#hyperdb-property-wrapper">hyperdb property wrapper</a> for all of this class’s properties.</td> </tr> <tr><td>list</td> <td>lists all of the active (not retired) items in the class.</td> </tr> <tr><td>csv</td> <td>return the items of this class as a chunk of CSV text.</td> </tr> <tr><td>propnames</td> <td>lists the names of the properties of this class.</td> </tr> <tr><td>filter</td> <td><p class="first">lists of items from this class, filtered and sorted. Two options are avaible for sorting:</p> <ol class="arabic"> <li><p class="first">by the current <em>request</em> filterspec/filter/sort/group args</p> </li> <li><p class="first">by the “filterspec”, “sort” and “group” keyword args. “filterspec” is <tt class="docutils literal"><span class="pre">{propname:</span> <span class="pre">value(s)}</span></tt>. “sort” and “group” are an optionally empty list <tt class="docutils literal"><span class="pre">[(dir,</span> <span class="pre">prop)]</span></tt> where dir is ‘+’, ‘-‘ or None and prop is a prop name or None.</p> <p>The propname in filterspec and prop in a sort/group spec may be transitive, i.e., it may contain properties of the form link.link.link.name.</p> </li> </ol> <p class="last">eg. All issues with a priority of “1” with messages added in the last week, sorted by activity date: <tt class="docutils literal"><span class="pre">issue.filter(filterspec={"priority":</span> <span class="pre">"1",</span> <span class="pre">'messages.creation'</span> <span class="pre">:</span> <span class="pre">'.-1w;'},</span> <span class="pre">sort=[('activity',</span> <span class="pre">'+')])</span></tt></p> </td> </tr> <tr><td>filter_sql</td> <td><p class="first"><strong>Only in SQL backends</strong></p> <p>Lists the items that match the SQL provided. The SQL is a complete “select” statement.</p> <p>The SQL select must include the item id as the first column.</p> <p class="last">This function <strong>does not</strong> filter out retired items, add on a where clause “__retired__ <> 1” if you don’t want retired nodes.</p> </td> </tr> <tr><td>classhelp</td> <td><p class="first">display a link to a javascript popup containing this class’ “help” template.</p> <p>This generates a link to a popup window which displays the properties indicated by “properties” of the class named by “classname”. The “properties” should be a comma-separated list (eg. ‘id,name,description’). Properties defaults to all the properties of a class (excluding id, creator, created and activity).</p> <p>You may optionally override the “label” displayed, the “width”, the “height”, the number of items per page (“pagesize”) and the field on which the list is sorted (“sort”).</p> <p>With the “filter” arg it is possible to specify a filter for which items are supposed to be displayed. It has to be of the format “<field>=<values>;<field>=<values>;...”.</p> <p>The popup window will be resizable and scrollable.</p> <p>If the “property” arg is given, it’s passed through to the javascript help_window function. This allows updating of a property in the calling HTML page.</p> <p class="last">If the “form” arg is given, it’s passed through to the javascript help_window function - it’s the name of the form the “property” belongs to.</p> </td> </tr> <tr><td>submit</td> <td>generate a submit button (and action hidden element)</td> </tr> <tr><td>renderWith</td> <td>render this class with the given template.</td> </tr> <tr><td>history</td> <td>returns ‘New node - no history’ :)</td> </tr> <tr><td>is_edit_ok</td> <td>is the user allowed to Edit the current class?</td> </tr> <tr><td>is_view_ok</td> <td>is the user allowed to View the current class?</td> </tr> </tbody> </table> <p>Note that if you have a property of the same name as one of the above methods, you’ll need to access it using a python “item access” expression. For example:</p> <div class="highlight-python"><pre>python:context['list']</pre> </div> <p>will access the “list” property, rather than the list method.</p> </div> <div class="section" id="hyperdb-item-wrapper"> <h5><a class="toc-backref" href="#id22">Hyperdb item wrapper</a></h5> <p>This is implemented by the <tt class="docutils literal"><span class="pre">roundup.cgi.templating.HTMLItem</span></tt> class.</p> <p>This wrapper object provides access to a hyperdb item.</p> <p>We allow access to properties. There will be no “id” property. The value accessed through the property will be the current value of the same name from the CGI form.</p> <p>There are several methods available on these wrapper objects:</p> <table border="1" class="docutils"> <colgroup> <col width="21%" /> <col width="79%" /> </colgroup> <thead valign="bottom"> <tr><th class="head">Method</th> <th class="head">Description</th> </tr> </thead> <tbody valign="top"> <tr><td>submit</td> <td>generate a submit button (and action hidden element)</td> </tr> <tr><td>journal</td> <td>return the journal of the current item (<strong>not implemented</strong>)</td> </tr> <tr><td>history</td> <td>render the journal of the current item as HTML</td> </tr> <tr><td>renderQueryForm</td> <td>specific to the “query” class - render the search form for the query</td> </tr> <tr><td>hasPermission</td> <td><p class="first">specific to the “user” class - determine whether the user has a Permission. The signature is:</p> <div class="highlight-python"><pre>hasPermission(self, permission, [classname=], [property=], [itemid=])</pre> </div> <p class="last">where the classname defaults to the current context.</p> </td> </tr> <tr><td>hasRole</td> <td><p class="first">specific to the “user” class - determine whether the user has a Role. The signature is:</p> <div class="last highlight-python"><div class="highlight"><pre><span class="n">hasRole</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">rolename</span><span class="p">)</span> </pre></div> </div> </td> </tr> <tr><td>is_edit_ok</td> <td>is the user allowed to Edit the current item?</td> </tr> <tr><td>is_view_ok</td> <td>is the user allowed to View the current item?</td> </tr> <tr><td>is_retired</td> <td>is the item retired?</td> </tr> <tr><td>download_url</td> <td>generate a url-quoted link for download of FileClass item contents (ie. file<id>/<name>)</td> </tr> <tr><td>copy_url</td> <td>generate a url-quoted link for creating a copy of this item. By default, the copy will acquire all properties of the current item except for <tt class="docutils literal"><span class="pre">messages</span></tt> and <tt class="docutils literal"><span class="pre">files</span></tt>. This can be overridden by passing <tt class="docutils literal"><span class="pre">exclude</span></tt> argument which contains a list (or any iterable) of property names that shall not be copied. Database-driven properties like <tt class="docutils literal"><span class="pre">id</span></tt> or <tt class="docutils literal"><span class="pre">activity</span></tt> cannot be copied.</td> </tr> </tbody> </table> <p>Note that if you have a property of the same name as one of the above methods, you’ll need to access it using a python “item access” expression. For example:</p> <div class="highlight-python"><pre>python:context['journal']</pre> </div> <p>will access the “journal” property, rather than the journal method.</p> </div> <div class="section" id="hyperdb-property-wrapper"> <h5><a class="toc-backref" href="#id23">Hyperdb property wrapper</a></h5> <p>This is implemented by subclasses of the <tt class="docutils literal"><span class="pre">roundup.cgi.templating.HTMLProperty</span></tt> class (<tt class="docutils literal"><span class="pre">HTMLStringProperty</span></tt>, <tt class="docutils literal"><span class="pre">HTMLNumberProperty</span></tt>, and so on).</p> <p>This wrapper object provides access to a single property of a class. Its value may be either:</p> <ol class="arabic simple"> <li>if accessed through a <a class="reference internal" href="#hyperdb-item-wrapper">hyperdb item wrapper</a>, then it’s a value from the hyperdb</li> <li>if access through a <a class="reference internal" href="#hyperdb-class-wrapper">hyperdb class wrapper</a>, then it’s a value from the CGI form</li> </ol> <p>The property wrapper has some useful attributes:</p> <table border="1" class="docutils"> <colgroup> <col width="21%" /> <col width="79%" /> </colgroup> <thead valign="bottom"> <tr><th class="head">Attribute</th> <th class="head">Description</th> </tr> </thead> <tbody valign="top"> <tr><td>_name</td> <td>the name of the property</td> </tr> <tr><td>_value</td> <td>the value of the property if any - this is the actual value retrieved from the hyperdb for this property</td> </tr> </tbody> </table> <p>There are several methods available on these wrapper objects:</p> <table border="1" class="docutils"> <colgroup> <col width="15%" /> <col width="85%" /> </colgroup> <thead valign="bottom"> <tr><th class="head">Method</th> <th class="head">Description</th> </tr> </thead> <tbody valign="top"> <tr><td>plain</td> <td><p class="first">render a “plain” representation of the property. This method may take two arguments:</p> <dl class="last docutils"> <dt>escape</dt> <dd><p class="first">If true, escape the text so it is HTML safe (default: no). The reason this defaults to off is that text is usually escaped at a later stage by the TAL commands, unless the “structure” option is used in the template. The following <tt class="docutils literal"><span class="pre">tal:content</span></tt> expressions are all equivalent:</p> <div class="highlight-python"><div class="highlight"><pre><span class="s">"structure python:msg.content.plain(escape=1)"</span> <span class="s">"python:msg.content.plain()"</span> <span class="s">"msg/content/plain"</span> <span class="s">"msg/content"</span> </pre></div> </div> <p class="last">Usually you’ll only want to use the escape option in a complex expression.</p> </dd> <dt>hyperlink</dt> <dd><p class="first">If true, turn URLs, email addresses and hyperdb item designators in the text into hyperlinks (default: no). Note that you’ll need to use the “structure” TAL option if you want to use this <tt class="docutils literal"><span class="pre">tal:content</span></tt> expression:</p> <div class="highlight-python"><div class="highlight"><pre><span class="s">"structure python:msg.content.plain(hyperlink=1)"</span> </pre></div> </div> <p class="last">The text is automatically HTML-escaped before the hyperlinking transformation done in the plain() method.</p> </dd> </dl> </td> </tr> <tr><td>hyperlinked</td> <td><p class="first">The same as msg.content.plain(hyperlink=1), but nicer:</p> <div class="last highlight-python"><div class="highlight"><pre><span class="s">"structure msg/content/hyperlinked"</span> </pre></div> </div> </td> </tr> <tr><td>field</td> <td><p class="first">render an appropriate form edit field for the property - for most types this is a text entry box, but for Booleans it’s a tri-state yes/no/neither selection. This method may take some arguments:</p> <dl class="last docutils"> <dt>size</dt> <dd>Sets the width in characters of the edit field</dd> <dt>format (Date properties only)</dt> <dd>Sets the format of the date in the field - uses the same format string argument as supplied to the <tt class="docutils literal"><span class="pre">pretty</span></tt> method below.</dd> <dt>popcal (Date properties only)</dt> <dd>Include the Javascript-based popup calendar for date selection. Defaults to on.</dd> </dl> </td> </tr> <tr><td>stext</td> <td>only on String properties - render the value of the property as StructuredText (requires the StructureText module to be installed separately)</td> </tr> <tr><td>multiline</td> <td>only on String properties - render a multiline form edit field for the property</td> </tr> <tr><td>email</td> <td>only on String properties - render the value of the property as an obscured email address</td> </tr> <tr><td>confirm</td> <td>only on Password properties - render a second form edit field for the property, used for confirmation that the user typed the password correctly. Generates a field with name “name:confirm”.</td> </tr> <tr><td>now</td> <td>only on Date properties - return the current date as a new property</td> </tr> <tr><td>reldate</td> <td>only on Date properties - render the interval between the date and now</td> </tr> <tr><td>local</td> <td><p class="first">only on Date properties - return this date as a new property with some timezone offset, for example:</p> <div class="highlight-python"><pre>python:context.creation.local(10)</pre> </div> <p class="last">will render the date with a +10 hour offset.</p> </td> </tr> <tr><td>pretty</td> <td><p class="first">Date properties - render the date as “dd Mon YYYY” (eg. “19 Mar 2004”). Takes an optional format argument, for example:</p> <div class="highlight-python"><pre>python:context.activity.pretty('%Y-%m-%d')</pre> </div> <p>Will format as “2004-03-19” instead.</p> <p class="last">Interval properties - render the interval in a pretty format (eg. “yesterday”). The format arguments are those used in the standard <tt class="docutils literal"><span class="pre">strftime</span></tt> call (see the <a class="reference external" href="http://docs.python.org/lib/module-time.html">Python Library Reference: time module</a>)</p> </td> </tr> <tr><td>popcal</td> <td><p class="first">Generate a link to a popup calendar which may be used to edit the date field, for example:</p> <div class="highlight-python"><pre><span tal:replace="structure context/due/popcal" /></pre> </div> <p>you still need to include the <tt class="docutils literal"><span class="pre">field</span></tt> for the property, so typically you’d have:</p> <div class="last highlight-python"><pre><span tal:replace="structure context/due/field" /> <span tal:replace="structure context/due/popcal" /></pre> </div> </td> </tr> <tr><td>menu</td> <td><p class="first">only on Link and Multilink properties - render a form select list for this property. Takes a number of optional arguments</p> <dl class="docutils"> <dt>size</dt> <dd>is used to limit the length of the list labels</dd> <dt>height</dt> <dd>is used to set the <select> tag’s “size” attribute</dd> <dt>showid</dt> <dd>includes the item ids in the list labels</dd> <dt>additional</dt> <dd>lists properties which should be included in the label</dd> <dt>sort_on</dt> <dd>indicates the property to sort the list on as (direction, (direction, property) where direction is ‘+’ or ‘-‘. A single string with the direction prepended may be used. For example: (‘-‘, ‘order’), ‘+name’.</dd> <dt>value</dt> <dd>gives a default value to preselect in the menu</dd> </dl> <p>The remaining keyword arguments are used as conditions for filtering the items in the list - they’re passed as the “filterspec” argument to a Class.filter() call. For example:</p> <div class="last highlight-python"><pre><span tal:replace="structure context/status/menu" /> <span tal:replace="python:context.status.menu(order='+name", value='chatting', filterspec={'status': '1,2,3,4'}" /></pre> </div> </td> </tr> <tr><td>sorted</td> <td><p class="first">only on Multilink properties - produce a list of the linked items sorted by some property, for example:</p> <div class="highlight-python"><pre>python:context.files.sorted('creation')</pre> </div> <p class="last">Will list the files by upload date.</p> </td> </tr> <tr><td>reverse</td> <td>only on Multilink properties - produce a list of the linked items in reverse order</td> </tr> <tr><td>isset</td> <td>returns True if the property has been set to a value</td> </tr> </tbody> </table> <p>All of the above functions perform checks for permissions required to display or edit the data they are manipulating. The simplest case is editing an issue title. Including the expression:</p> <div class="highlight-python"><div class="highlight"><pre><span class="n">context</span><span class="o">/</span><span class="n">title</span><span class="o">/</span><span class="n">field</span> </pre></div> </div> <p>Will present the user with an edit field, if they have edit permission. If not, then they will be presented with a static display if they have view permission. If they don’t even have view permission, then an error message is raised, preventing the display of the page, indicating that they don’t have permission to view the information.</p> </div> </div> <div class="section" id="the-request-variable"> <h4><a class="toc-backref" href="#id24">The request variable</a></h4> <p>This is implemented by the <tt class="docutils literal"><span class="pre">roundup.cgi.templating.HTMLRequest</span></tt> class.</p> <p>The request variable is packed with information about the current request.</p> <table border="1" class="docutils"> <colgroup> <col width="15%" /> <col width="85%" /> </colgroup> <thead valign="bottom"> <tr><th class="head">Variable</th> <th class="head">Holds</th> </tr> </thead> <tbody valign="top"> <tr><td>form</td> <td>the CGI form as a cgi.FieldStorage</td> </tr> <tr><td>env</td> <td>the CGI environment variables</td> </tr> <tr><td>base</td> <td>the base URL for this tracker</td> </tr> <tr><td>user</td> <td>a HTMLUser instance for this user</td> </tr> <tr><td>classname</td> <td>the current classname (possibly None)</td> </tr> <tr><td>template</td> <td>the current template (suffix, also possibly None)</td> </tr> <tr><td>form</td> <td>the current CGI form variables in a FieldStorage</td> </tr> </tbody> </table> <p><strong>Index page specific variables (indexing arguments)</strong></p> <table border="1" class="docutils"> <colgroup> <col width="15%" /> <col width="85%" /> </colgroup> <thead valign="bottom"> <tr><th class="head">Variable</th> <th class="head">Holds</th> </tr> </thead> <tbody valign="top"> <tr><td>columns</td> <td>dictionary of the columns to display in an index page</td> </tr> <tr><td>show</td> <td>a convenience access to columns - request/show/colname will be true if the columns should be displayed, false otherwise</td> </tr> <tr><td>sort</td> <td>index sort columns [(direction, column name)]</td> </tr> <tr><td>group</td> <td>index grouping properties [(direction, column name)]</td> </tr> <tr><td>filter</td> <td>properties to filter the index on</td> </tr> <tr><td>filterspec</td> <td>values to filter the index on (property=value, eg <tt class="docutils literal"><span class="pre">priority=1</span></tt> or <tt class="docutils literal"><span class="pre">messages.author=42</span></tt></td> </tr> <tr><td>search_text</td> <td>text to perform a full-text search on for an index</td> </tr> </tbody> </table> <p>There are several methods available on the request variable:</p> <table border="1" class="docutils"> <colgroup> <col width="21%" /> <col width="79%" /> </colgroup> <thead valign="bottom"> <tr><th class="head">Method</th> <th class="head">Description</th> </tr> </thead> <tbody valign="top"> <tr><td>description</td> <td>render a description of the request - handle for the page title</td> </tr> <tr><td>indexargs_form</td> <td>render the current index args as form elements</td> </tr> <tr><td>indexargs_url</td> <td>render the current index args as a URL</td> </tr> <tr><td>base_javascript</td> <td>render some javascript that is used by other components of the templating</td> </tr> <tr><td>batch</td> <td>run the current index args through a filter and return a list of items (see <a class="reference internal" href="#hyperdb-item-wrapper">hyperdb item wrapper</a>, and <a class="reference internal" href="#batching">batching</a>)</td> </tr> </tbody> </table> <div class="section" id="the-form-variable"> <h5><a class="toc-backref" href="#id25">The form variable</a></h5> <p>The form variable is a bit special because it’s actually a python FieldStorage object. That means that you have two ways to access its contents. For example, to look up the CGI form value for the variable “name”, use the path expression:</p> <div class="highlight-python"><div class="highlight"><pre><span class="n">request</span><span class="o">/</span><span class="n">form</span><span class="o">/</span><span class="n">name</span><span class="o">/</span><span class="n">value</span> </pre></div> </div> <p>or the python expression:</p> <div class="highlight-python"><pre>python:request.form['name'].value</pre> </div> <p>Note the “item” access used in the python case, and also note the explicit “value” attribute we have to access. That’s because the form variables are stored as MiniFieldStorages. If there’s more than one “name” value in the form, then the above will break since <tt class="docutils literal"><span class="pre">request/form/name</span></tt> is actually a <em>list</em> of MiniFieldStorages. So it’s best to know beforehand what you’re dealing with.</p> </div> </div> <div class="section" id="the-db-variable"> <h4><a class="toc-backref" href="#id26">The db variable</a></h4> <p>This is implemented by the <tt class="docutils literal"><span class="pre">roundup.cgi.templating.HTMLDatabase</span></tt> class.</p> <p>Allows access to all hyperdb classes as attributes of this variable. If you want access to the “user” class, for example, you would use:</p> <div class="highlight-python"><pre>db/user python:db.user</pre> </div> <p>Also, the current id of the current user is available as <tt class="docutils literal"><span class="pre">db.getuid()</span></tt>. This isn’t so useful in templates (where you have <tt class="docutils literal"><span class="pre">request/user</span></tt>), but it can be useful in detectors or interfaces.</p> <p>The access results in a <a class="reference internal" href="#hyperdb-class-wrapper">hyperdb class wrapper</a>.</p> </div> <div class="section" id="the-templates-variable"> <h4><a class="toc-backref" href="#id27">The templates variable</a></h4> <p>This is implemented by the <tt class="docutils literal"><span class="pre">roundup.cgi.templating.Templates</span></tt> class.</p> <p>This variable doesn’t have any useful methods defined. It supports being used in expressions to access the templates, and consequently the template macros. You may access the templates using the following path expression:</p> <div class="highlight-python"><div class="highlight"><pre><span class="n">templates</span><span class="o">/</span><span class="n">name</span> </pre></div> </div> <p>or the python expression:</p> <div class="highlight-python"><div class="highlight"><pre><span class="n">templates</span><span class="p">[</span><span class="n">name</span><span class="p">]</span> </pre></div> </div> <p>where “name” is the name of the template you wish to access. The template has one useful attribute, namely “macros”. To access a specific macro (called “macro_name”), use the path expression:</p> <div class="highlight-python"><div class="highlight"><pre><span class="n">templates</span><span class="o">/</span><span class="n">name</span><span class="o">/</span><span class="n">macros</span><span class="o">/</span><span class="n">macro_name</span> </pre></div> </div> <p>or the python expression:</p> <div class="highlight-python"><div class="highlight"><pre><span class="n">templates</span><span class="p">[</span><span class="n">name</span><span class="p">]</span><span class="o">.</span><span class="n">macros</span><span class="p">[</span><span class="n">macro_name</span><span class="p">]</span> </pre></div> </div> </div> <div class="section" id="the-repeat-variable"> <h4><a class="toc-backref" href="#id28">The repeat variable</a></h4> <p>The repeat variable holds an entry for each active iteration. That is, if you have a <tt class="docutils literal"><span class="pre">tal:repeat="user</span> <span class="pre">db/users"</span></tt> command, then there will be a repeat variable entry called “user”. This may be accessed as either:</p> <div class="highlight-python"><pre>repeat/user python:repeat['user']</pre> </div> <p>The “user” entry has a number of methods available for information:</p> <table border="1" class="docutils"> <colgroup> <col width="21%" /> <col width="79%" /> </colgroup> <thead valign="bottom"> <tr><th class="head">Method</th> <th class="head">Description</th> </tr> </thead> <tbody valign="top"> <tr><td>first</td> <td>True if the current item is the first in the sequence.</td> </tr> <tr><td>last</td> <td>True if the current item is the last in the sequence.</td> </tr> <tr><td>even</td> <td>True if the current item is an even item in the sequence.</td> </tr> <tr><td>odd</td> <td>True if the current item is an odd item in the sequence.</td> </tr> <tr><td>number</td> <td>Current position in the sequence, starting from 1.</td> </tr> <tr><td>letter</td> <td>Current position in the sequence as a letter, a through z, then aa through zz, and so on.</td> </tr> <tr><td>Letter</td> <td>Same as letter(), except uppercase.</td> </tr> <tr><td>roman</td> <td>Current position in the sequence as lowercase roman numerals.</td> </tr> <tr><td>Roman</td> <td>Same as roman(), except uppercase.</td> </tr> </tbody> </table> </div> <div class="section" id="the-utils-variable"> <h4><a class="toc-backref" href="#id29">The utils variable</a></h4> <p>This is implemented by the <tt class="docutils literal"><span class="pre">roundup.cgi.templating.TemplatingUtils</span></tt> class, but it may be extended as described below.</p> <table border="1" class="docutils"> <colgroup> <col width="21%" /> <col width="79%" /> </colgroup> <thead valign="bottom"> <tr><th class="head">Method</th> <th class="head">Description</th> </tr> </thead> <tbody valign="top"> <tr><td>Batch</td> <td>return a batch object using the supplied list</td> </tr> <tr><td>url_quote</td> <td>quote some text as safe for a URL (ie. space, %, ...)</td> </tr> <tr><td>html_quote</td> <td>quote some text as safe in HTML (ie. <, >, ...)</td> </tr> <tr><td>html_calendar</td> <td>renders an HTML calendar used by the <tt class="docutils literal"><span class="pre">_generic.calendar.html</span></tt> template (itself invoked by the popupCalendar DateHTMLProperty method</td> </tr> </tbody> </table> <p>You may add additional utility methods by writing them in your tracker <tt class="docutils literal"><span class="pre">extensions</span></tt> directory and registering them with the templating system using <tt class="docutils literal"><span class="pre">instance.registerUtil</span></tt> (see <a class="reference internal" href="#adding-a-time-log-to-your-issues">adding a time log to your issues</a> for an example of this).</p> <div class="section" id="batching"> <h5><a class="toc-backref" href="#id30">Batching</a></h5> <p>Use Batch to turn a list of items, or item ids of a given class, into a series of batches. Its usage is:</p> <div class="highlight-python"><pre>python:utils.Batch(sequence, size, start, end=0, orphan=0, overlap=0)</pre> </div> <p>or, to get the current index batch:</p> <div class="highlight-python"><div class="highlight"><pre><span class="n">request</span><span class="o">/</span><span class="n">batch</span> </pre></div> </div> <p>The parameters are:</p> <table border="1" class="docutils"> <colgroup> <col width="13%" /> <col width="87%" /> </colgroup> <thead valign="bottom"> <tr><th class="head">Parameter</th> <th class="head">Usage</th> </tr> </thead> <tbody valign="top"> <tr><td>sequence</td> <td>a list of HTMLItems</td> </tr> <tr><td>size</td> <td>how big to make the sequence.</td> </tr> <tr><td>start</td> <td>where to start (0-indexed) in the sequence.</td> </tr> <tr><td>end</td> <td>where to end (0-indexed) in the sequence.</td> </tr> <tr><td>orphan</td> <td>if the next batch would contain less items than this value, then it is combined with this batch</td> </tr> <tr><td>overlap</td> <td>the number of items shared between adjacent batches</td> </tr> </tbody> </table> <p>All of the parameters are assigned as attributes on the batch object. In addition, it has several more attributes:</p> <table border="1" class="docutils"> <colgroup> <col width="21%" /> <col width="79%" /> </colgroup> <thead valign="bottom"> <tr><th class="head">Attribute</th> <th class="head">Description</th> </tr> </thead> <tbody valign="top"> <tr><td>start</td> <td>indicates the start index of the batch. <em>Unlike the argument, is a 1-based index (I know, lame)</em></td> </tr> <tr><td>first</td> <td>indicates the start index of the batch <em>as a 0-based index</em></td> </tr> <tr><td>length</td> <td>the actual number of elements in the batch</td> </tr> <tr><td>sequence_length</td> <td>the length of the original, unbatched, sequence.</td> </tr> </tbody> </table> <p>And several methods:</p> <table border="1" class="docutils"> <colgroup> <col width="21%" /> <col width="79%" /> </colgroup> <thead valign="bottom"> <tr><th class="head">Method</th> <th class="head">Description</th> </tr> </thead> <tbody valign="top"> <tr><td>previous</td> <td>returns a new Batch with the previous batch settings</td> </tr> <tr><td>next</td> <td>returns a new Batch with the next batch settings</td> </tr> <tr><td>propchanged</td> <td>detect if the named property changed on the current item when compared to the last item</td> </tr> </tbody> </table> <p>An example of batching:</p> <div class="highlight-python"><pre><table class="otherinfo"> <tr><th colspan="4" class="header">Existing Keywords</th></tr> <tr tal:define="keywords db/keyword/list" tal:repeat="start python:range(0, len(keywords), 4)"> <td tal:define="batch python:utils.Batch(keywords, 4, start)" tal:repeat="keyword batch" tal:content="keyword/name"> keyword here</td> </tr> </table></pre> </div> <p>... which will produce a table with four columns containing the items of the “keyword” class (well, their “name” anyway).</p> </div> </div> <div class="section" id="translations"> <h4><a class="toc-backref" href="#id31">Translations</a></h4> <p>Should you wish to enable multiple languages in template content that you create you’ll need to add new locale files in the tracker home under a <tt class="docutils literal"><span class="pre">locale</span></tt> directory. Use the instructions in the <tt class="docutils literal"><span class="pre">developer's</span> <span class="pre">guide</span></tt> to create the locale files.</p> </div> </div> <div class="section" id="displaying-properties"> <h3><a class="toc-backref" href="#id32">Displaying Properties</a></h3> <p>Properties appear in the user interface in three contexts: in indices, in editors, and as search arguments. For each type of property, there are several display possibilities. For example, in an index view, a string property may just be printed as a plain string, but in an editor view, that property may be displayed in an editable field.</p> </div> <div class="section" id="index-views"> <h3><a class="toc-backref" href="#id33">Index Views</a></h3> <p>This is one of the class context views. It is also the default view for classes. The template used is “<em>classname</em>.index”.</p> <div class="section" id="index-view-specifiers"> <h4><a class="toc-backref" href="#id34">Index View Specifiers</a></h4> <p>An index view specifier (URL fragment) looks like this (whitespace has been added for clarity):</p> <div class="highlight-python"><pre>/issue?status=unread,in-progress,resolved& keyword=security,ui& @group=priority,-status& @sort=-activity& @filters=status,keyword& @columns=title,status,fixer</pre> </div> <p>The index view is determined by two parts of the specifier: the layout part and the filter part. The layout part consists of the query parameters that begin with colons, and it determines the way that the properties of selected items are displayed. The filter part consists of all the other query parameters, and it determines the criteria by which items are selected for display. The filter part is interactively manipulated with the form widgets displayed in the filter section. The layout part is interactively manipulated by clicking on the column headings in the table.</p> <p>The filter part selects the union of the sets of items with values matching any specified Link properties and the intersection of the sets of items with values matching any specified Multilink properties.</p> <p>The example specifies an index of “issue” items. Only items with a “status” of either “unread” or “in-progress” or “resolved” are displayed, and only items with “keyword” values including both “security” and “ui” are displayed. The items are grouped by priority arranged in ascending order and in descending order by status; and within groups, sorted by activity, arranged in descending order. The filter section shows filters for the “status” and “keyword” properties, and the table includes columns for the “title”, “status”, and “fixer” properties.</p> <table border="1" class="docutils"> <colgroup> <col width="16%" /> <col width="84%" /> </colgroup> <thead valign="bottom"> <tr><th class="head">Argument</th> <th class="head">Description</th> </tr> </thead> <tbody valign="top"> <tr><td>@sort</td> <td>sort by prop name, optionally preceeded with ‘-‘ to give descending or nothing for ascending sorting. Several properties can be specified delimited with comma. Internally a search-page using several sort properties may use @sort0, @sort1 etc. with option @sortdir0, @sortdir1 etc. for the direction of sorting (a non-empty value of sortdir0 specifies reverse order).</td> </tr> <tr><td>@group</td> <td>group by prop name, optionally preceeded with ‘-‘ or to sort in descending or nothing for ascending order. Several properties can be specified delimited with comma. Internally a search-page using several grouping properties may use @group0, @group1 etc. with option @groupdir0, @groupdir1 etc. for the direction of grouping (a non-empty value of groupdir0 specifies reverse order).</td> </tr> <tr><td>@columns</td> <td>selects the columns that should be displayed. Default is all.</td> </tr> <tr><td>@filter</td> <td>indicates which properties are being used in filtering. Default is none.</td> </tr> <tr><td>propname</td> <td>selects the values the item properties given by propname must have (very basic search/filter).</td> </tr> <tr><td>@search_text</td> <td>if supplied, performs a full-text search (message bodies, issue titles, etc)</td> </tr> </tbody> </table> </div> </div> <div class="section" id="searching-views"> <h3><a class="toc-backref" href="#id35">Searching Views</a></h3> <div class="admonition note"> <p class="first admonition-title">Note</p> <p class="last">if you add a new column to the <tt class="docutils literal"><span class="pre">@columns</span></tt> form variable potentials then you will need to add the column to the appropriate <a class="reference internal" href="#index-views">index views</a> template so that it is actually displayed.</p> </div> <p>This is one of the class context views. The template used is typically “<em>classname</em>.search”. The form on this page should have “search” as its <tt class="docutils literal"><span class="pre">@action</span></tt> variable. The “search” action:</p> <ul class="simple"> <li>sets up additional filtering, as well as performing indexed text searching</li> <li>sets the <tt class="docutils literal"><span class="pre">@filter</span></tt> variable correctly</li> <li>saves the query off if <tt class="docutils literal"><span class="pre">@query_name</span></tt> is set.</li> </ul> <p>The search page should lay out any fields that you wish to allow the user to search on. If your schema contains a large number of properties, you should be wary of making all of those properties available for searching, as this can cause confusion. If the additional properties are Strings, consider having their value indexed, and then they will be searchable using the full text indexed search. This is both faster, and more useful for the end user.</p> <p>If the search view does specify the “search” <tt class="docutils literal"><span class="pre">@action</span></tt>, then it may also provide an additional argument:</p> <table border="1" class="docutils"> <colgroup> <col width="16%" /> <col width="84%" /> </colgroup> <thead valign="bottom"> <tr><th class="head">Argument</th> <th class="head">Description</th> </tr> </thead> <tbody valign="top"> <tr><td>@query_name</td> <td>if supplied, the index parameters (including @search_text) will be saved off as a the query item and registered against the user’s queries property. Note that the <em>classic</em> template schema has this ability, but the <em>minimal</em> template schema does not.</td> </tr> </tbody> </table> </div> <div class="section" id="item-views"> <h3><a class="toc-backref" href="#id36">Item Views</a></h3> <p>The basic view of a hyperdb item is provided by the “<em>classname</em>.item” template. It generally has three sections; an “editor”, a “spool” and a “history” section.</p> <div class="section" id="editor-section"> <h4><a class="toc-backref" href="#id37">Editor Section</a></h4> <p>The editor section is used to manipulate the item - it may be a static display if the user doesn’t have permission to edit the item.</p> <p>Here’s an example of a basic editor template (this is the default “classic” template issue item edit form - from the “issue.item.html” template):</p> <div class="highlight-python"><pre><table class="form"> <tr> <th>Title</th> <td colspan="3" tal:content="structure python:context.title.field(size=60)">title</td> </tr> <tr> <th>Priority</th> <td tal:content="structure context/priority/menu">priority</td> <th>Status</th> <td tal:content="structure context/status/menu">status</td> </tr> <tr> <th>Superseder</th> <td> <span tal:replace="structure python:context.superseder.field(showid=1, size=20)" /> <span tal:replace="structure python:db.issue.classhelp('id,title')" /> <span tal:condition="context/superseder"> <br>View: <span tal:replace="structure python:context.superseder.link(showid=1)" /> </span> </td> <th>Nosy List</th> <td> <span tal:replace="structure context/nosy/field" /> <span tal:replace="structure python:db.user.classhelp('username,realname,address,phone')" /> </td> </tr> <tr> <th>Assigned To</th> <td tal:content="structure context/assignedto/menu"> assignedto menu </td> <td>&nbsp;</td> <td>&nbsp;</td> </tr> <tr> <th>Change Note</th> <td colspan="3"> <textarea name=":note" wrap="hard" rows="5" cols="60"></textarea> </td> </tr> <tr> <th>File</th> <td colspan="3"><input type="file" name=":file" size="40"></td> </tr> <tr> <td>&nbsp;</td> <td colspan="3" tal:content="structure context/submit"> submit button will go here </td> </tr> </table></pre> </div> <p>When a change is submitted, the system automatically generates a message describing the changed properties. As shown in the example, the editor template can use the “:note” and “:file” fields, which are added to the standard changenote message generated by Roundup.</p> <div class="section" id="form-values"> <h5><a class="toc-backref" href="#id38">Form values</a></h5> <p>We have a number of ways to pull properties out of the form in order to meet the various needs of:</p> <ol class="arabic simple"> <li>editing the current item (perhaps an issue item)</li> <li>editing information related to the current item (eg. messages or attached files)</li> <li>creating new information to be linked to the current item (eg. time spent on an issue)</li> </ol> <p>In the following, <tt class="docutils literal"><span class="pre"><bracketed></span></tt> values are variable, “:” may be one of “:” or “@”, and other text (“required”) is fixed.</p> <p>Properties are specified as form variables:</p> <dl class="docutils"> <dt><tt class="docutils literal"><span class="pre"><propname></span></tt></dt> <dd>property on the current context item</dd> <dt><tt class="docutils literal"><span class="pre"><designator>:<propname></span></tt></dt> <dd>property on the indicated item (for editing related information)</dd> <dt><tt class="docutils literal"><span class="pre"><classname>-<N>:<propname></span></tt></dt> <dd>property on the Nth new item of classname (generally for creating new items to attach to the current item)</dd> </dl> <p>Once we have determined the “propname”, we check to see if it is one of the special form values:</p> <dl class="docutils"> <dt><tt class="docutils literal"><span class="pre">@required</span></tt></dt> <dd>The named property values must be supplied or a ValueError will be raised.</dd> <dt><tt class="docutils literal"><span class="pre">@remove@<propname>=id(s)</span></tt></dt> <dd>The ids will be removed from the multilink property.</dd> <dt><tt class="docutils literal"><span class="pre">:add:<propname>=id(s)</span></tt></dt> <dd>The ids will be added to the multilink property.</dd> <dt><tt class="docutils literal"><span class="pre">:link:<propname>=<designator></span></tt></dt> <dd>Used to add a link to new items created during edit. These are collected and returned in <tt class="docutils literal"><span class="pre">all_links</span></tt>. This will result in an additional linking operation (either Link set or Multilink append) after the edit/create is done using <tt class="docutils literal"><span class="pre">all_props</span></tt> in <tt class="docutils literal"><span class="pre">_editnodes</span></tt>. The <propname> on the current item will be set/appended the id of the newly created item of class <designator> (where <designator> must be <classname>-<N>).</dd> </dl> <p>Any of the form variables may be prefixed with a classname or designator.</p> <p>Two special form values are supported for backwards compatibility:</p> <dl class="docutils"> <dt><tt class="docutils literal"><span class="pre">:note</span></tt></dt> <dd>create a message (with content, author and date), linked to the context item. This is ALWAYS designated “msg-1”.</dd> <dt><tt class="docutils literal"><span class="pre">:file</span></tt></dt> <dd>create a file, attached to the current item and any message created by :note. This is ALWAYS designated “file-1”.</dd> </dl> </div> </div> <div class="section" id="spool-section"> <h4><a class="toc-backref" href="#id39">Spool Section</a></h4> <p>The spool section lists related information like the messages and files of an issue.</p> <p>TODO</p> </div> <div class="section" id="history-section"> <h4><a class="toc-backref" href="#id40">History Section</a></h4> <p>The final section displayed is the history of the item - its database journal. This is generally generated with the template:</p> <div class="highlight-python"><pre><tal:block tal:replace="structure context/history" /></pre> </div> <p><em>To be done:</em></p> <p><em>The actual history entries of the item may be accessed for manual templating through the “journal” method of the item</em>:</p> <div class="highlight-python"><pre><tal:block tal:repeat="entry context/journal"> a journal entry </tal:block></pre> </div> <p><em>where each journal entry is an HTMLJournalEntry.</em></p> </div> </div> <div class="section" id="defining-new-web-actions"> <h3><a class="toc-backref" href="#id41">Defining new web actions</a></h3> <p>You may define new actions to be triggered by the <tt class="docutils literal"><span class="pre">@action</span></tt> form variable. These are added to the tracker <tt class="docutils literal"><span class="pre">extensions</span></tt> directory and registered using <tt class="docutils literal"><span class="pre">instance.registerAction</span></tt>.</p> <p>All the existing Actions are defined in <tt class="docutils literal"><span class="pre">roundup.cgi.actions</span></tt>.</p> <p>Adding action classes takes three steps; first you <a class="reference internal" href="#define-the-new-action-class">define the new action class</a>, then you <a class="reference internal" href="#register-the-action-class">register the action class</a> with the cgi interface so it may be triggered by the <tt class="docutils literal"><span class="pre">@action</span></tt> form variable. Finally you <a class="reference internal" href="#use-the-new-action">use the new action</a> in your HTML form.</p> <p>See “<a class="reference internal" href="#setting-up-a-wizard-or-druid-for-controlled-adding-of-issues">setting up a “wizard” (or “druid”) for controlled adding of issues</a>” for an example.</p> <div class="section" id="define-the-new-action-class"> <h4><a class="toc-backref" href="#id42">Define the new action class</a></h4> <p>Create a new action class in your tracker’s <tt class="docutils literal"><span class="pre">extensions</span></tt> directory, for example <tt class="docutils literal"><span class="pre">myaction.py</span></tt>:</p> <div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">roundup.cgi.actions</span> <span class="kn">import</span> <span class="n">Action</span> <span class="k">class</span> <span class="nc">MyAction</span><span class="p">(</span><span class="n">Action</span><span class="p">):</span> <span class="k">def</span> <span class="nf">handle</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> <span class="sd">''' Perform some action. No return value is required.</span> <span class="sd"> '''</span> </pre></div> </div> <p>The <em>self.client</em> attribute is an instance of <tt class="docutils literal"><span class="pre">roundup.cgi.client.Client</span></tt>. See the docstring of that class for details of what it can do.</p> <p>The method will typically check the <tt class="docutils literal"><span class="pre">self.form</span></tt> variable’s contents. It may then:</p> <ul class="simple"> <li>add information to <tt class="docutils literal"><span class="pre">self.client.ok_message</span></tt> or <tt class="docutils literal"><span class="pre">self.client.error_message</span></tt></li> <li>change the <tt class="docutils literal"><span class="pre">self.client.template</span></tt> variable to alter what the user will see next</li> <li>raise Unauthorised, SendStaticFile, SendFile, NotFound or Redirect exceptions (import them from roundup.cgi.exceptions)</li> </ul> </div> <div class="section" id="register-the-action-class"> <h4><a class="toc-backref" href="#id43">Register the action class</a></h4> <p>The class is now written, but isn’t available to the user until you register it with the following code appended to your <tt class="docutils literal"><span class="pre">myaction.py</span></tt> file:</p> <div class="highlight-python"><div class="highlight"><pre><span class="k">def</span> <span class="nf">init</span><span class="p">(</span><span class="n">instance</span><span class="p">):</span> <span class="n">instance</span><span class="o">.</span><span class="n">registerAction</span><span class="p">(</span><span class="s">'myaction'</span><span class="p">,</span> <span class="n">myActionClass</span><span class="p">)</span> </pre></div> </div> <p>This maps the action name “myaction” to the action class we defined.</p> </div> <div class="section" id="use-the-new-action"> <h4><a class="toc-backref" href="#id44">Use the new action</a></h4> <p>In your HTML form, add a hidden form element like so:</p> <div class="highlight-python"><pre><input type="hidden" name="@action" value="myaction"></pre> </div> <p>where “myaction” is the name you registered in the previous step.</p> </div> <div class="section" id="actions-may-return-content-to-the-user"> <h4><a class="toc-backref" href="#id45">Actions may return content to the user</a></h4> <p>Actions generally perform some database manipulation and then pass control on to the rendering of a template in the current context (see <a class="reference internal" href="#determining-web-context">Determining web context</a> for how that works.) Some actions will want to generate the actual content returned to the user. Action methods may return their own content string to be displayed to the user, overriding the templating step. In this situation, we assume that the content is HTML by default. You may override the content type indicated to the user by calling <tt class="docutils literal"><span class="pre">setHeader</span></tt>:</p> <div class="highlight-python"><div class="highlight"><pre><span class="bp">self</span><span class="o">.</span><span class="n">client</span><span class="o">.</span><span class="n">setHeader</span><span class="p">(</span><span class="s">'Content-Type'</span><span class="p">,</span> <span class="s">'text/csv'</span><span class="p">)</span> </pre></div> </div> <p>This example indicates that the value sent back to the user is actually comma-separated value content (eg. something to be loaded into a spreadsheet or database).</p> </div> </div> <div class="section" id="bit-character-set-support-in-web-interface"> <h3><a class="toc-backref" href="#id46">8-bit character set support in Web interface</a></h3> <p>The web interface uses UTF-8 default. It may be overridden in both forms and a browser cookie.</p> <ul class="simple"> <li>In forms, use the <tt class="docutils literal"><span class="pre">@charset</span></tt> variable.</li> <li>To use the cookie override, have the <tt class="docutils literal"><span class="pre">roundup_charset</span></tt> cookie set.</li> </ul> <p>In both cases, the value is a valid charset name (eg. <tt class="docutils literal"><span class="pre">utf-8</span></tt> or <tt class="docutils literal"><span class="pre">kio8-r</span></tt>).</p> <p>Inside Roundup, all strings are stored and processed in utf-8. Unfortunately, some older browsers do not work properly with utf-8-encoded pages (e.g. Netscape Navigator 4 displays wrong characters in form fields). This version allows one to change the character set for http transfers. To do so, you may add the following code to your <tt class="docutils literal"><span class="pre">page.html</span></tt> template:</p> <div class="highlight-python"><pre><tal:block define="uri string:${request/base}${request/env/PATH_INFO}"> <a tal:attributes="href python:request.indexargs_url(uri, {'@charset':'utf-8'})">utf-8</a> <a tal:attributes="href python:request.indexargs_url(uri, {'@charset':'koi8-r'})">koi8-r</a> </tal:block></pre> </div> <p>(substitute <tt class="docutils literal"><span class="pre">koi8-r</span></tt> with appropriate charset for your language). Charset preference is kept in the browser cookie <tt class="docutils literal"><span class="pre">roundup_charset</span></tt>.</p> <p><tt class="docutils literal"><span class="pre">meta</span> <span class="pre">http-equiv</span></tt> lines added to the tracker templates in version 0.6.0 should be changed to include actual character set name:</p> <div class="highlight-python"><pre><meta http-equiv="Content-Type" tal:attributes="content string:text/html;; charset=${request/client/charset}" /></pre> </div> <p>The charset is also sent in the http header.</p> </div> </div> <div class="section" id="examples"> <h2>Examples</h2> <div class="contents local topic" id="id5"> <ul class="simple"> <li><a class="reference internal" href="#changing-what-s-stored-in-the-database" id="id47">Changing what’s stored in the database</a><ul> <li><a class="reference internal" href="#adding-a-new-field-to-the-classic-schema" id="id48">Adding a new field to the classic schema</a></li> <li><a class="reference internal" href="#adding-a-new-constrained-field-to-the-classic-schema" id="id49">Adding a new constrained field to the classic schema</a></li> <li><a class="reference internal" href="#adding-a-time-log-to-your-issues" id="id50">Adding a time log to your issues</a></li> <li><a class="reference internal" href="#tracking-different-types-of-issues" id="id51">Tracking different types of issues</a></li> </ul> </li> <li><a class="reference internal" href="#using-external-user-databases" id="id52">Using External User Databases</a><ul> <li><a class="reference internal" href="#using-an-external-password-validation-source" id="id53">Using an external password validation source</a></li> <li><a class="reference internal" href="#using-a-un-x-passwd-file-as-the-user-database" id="id54">Using a UN*X passwd file as the user database</a></li> <li><a class="reference internal" href="#using-an-ldap-database-for-user-information" id="id55">Using an LDAP database for user information</a></li> </ul> </li> <li><a class="reference internal" href="#changes-to-tracker-behaviour" id="id56">Changes to Tracker Behaviour</a><ul> <li><a class="reference internal" href="#preventing-spam" id="id57">Preventing SPAM</a></li> <li><a class="reference internal" href="#stop-nosy-messages-going-to-people-on-vacation" id="id58">Stop “nosy” messages going to people on vacation</a></li> <li><a class="reference internal" href="#adding-in-state-transition-control" id="id59">Adding in state transition control</a></li> <li><a class="reference internal" href="#blocking-issues-that-depend-on-other-issues" id="id60">Blocking issues that depend on other issues</a></li> <li><a class="reference internal" href="#add-users-to-the-nosy-list-based-on-the-keyword" id="id61">Add users to the nosy list based on the keyword</a></li> </ul> </li> <li><a class="reference internal" href="#changes-to-security-and-permissions" id="id62">Changes to Security and Permissions</a><ul> <li><a class="reference internal" href="#restricting-the-list-of-users-that-are-assignable-to-a-task" id="id63">Restricting the list of users that are assignable to a task</a></li> <li><a class="reference internal" href="#users-may-only-edit-their-issues" id="id64">Users may only edit their issues</a></li> <li><a class="reference internal" href="#all-users-may-only-view-and-edit-issues-files-and-messages-they-create" id="id65">All users may only view and edit issues, files and messages they create</a></li> <li><a class="reference internal" href="#moderating-user-registration" id="id66">Moderating user registration</a></li> </ul> </li> <li><a class="reference internal" href="#changes-to-the-web-user-interface" id="id67">Changes to the Web User Interface</a><ul> <li><a class="reference internal" href="#adding-action-links-to-the-index-page" id="id68">Adding action links to the index page</a></li> <li><a class="reference internal" href="#colouring-the-rows-in-the-issue-index-according-to-priority" id="id69">Colouring the rows in the issue index according to priority</a></li> <li><a class="reference internal" href="#editing-multiple-items-in-an-index-view" id="id70">Editing multiple items in an index view</a></li> <li><a class="reference internal" href="#displaying-only-message-summaries-in-the-issue-display" id="id71">Displaying only message summaries in the issue display</a></li> <li><a class="reference internal" href="#enabling-display-of-either-message-summaries-or-the-entire-messages" id="id72">Enabling display of either message summaries or the entire messages</a></li> <li><a class="reference internal" href="#setting-up-a-wizard-or-druid-for-controlled-adding-of-issues" id="id73">Setting up a “wizard” (or “druid”) for controlled adding of issues</a></li> </ul> </li> </ul> </div> <div class="section" id="changing-what-s-stored-in-the-database"> <h3><a class="toc-backref" href="#id47">Changing what’s stored in the database</a></h3> <p>The following examples illustrate ways to change the information stored in the database.</p> <div class="section" id="adding-a-new-field-to-the-classic-schema"> <h4><a class="toc-backref" href="#id48">Adding a new field to the classic schema</a></h4> <p>This example shows how to add a simple field (a due date) to the default classic schema. It does not add any additional behaviour, such as enforcing the due date, or causing automatic actions to fire if the due date passes.</p> <p>You add new fields by editing the <tt class="docutils literal"><span class="pre">schema.py</span></tt> file in you tracker’s home. Schema changes are automatically applied to the database on the next tracker access (note that roundup-server would need to be restarted as it caches the schema).</p> <ol class="arabic"> <li><p class="first">Modify the <tt class="docutils literal"><span class="pre">schema.py</span></tt>:</p> <div class="highlight-python"><div class="highlight"><pre><span class="n">issue</span> <span class="o">=</span> <span class="n">IssueClass</span><span class="p">(</span><span class="n">db</span><span class="p">,</span> <span class="s">"issue"</span><span class="p">,</span> <span class="n">assignedto</span><span class="o">=</span><span class="n">Link</span><span class="p">(</span><span class="s">"user"</span><span class="p">),</span> <span class="n">keyword</span><span class="o">=</span><span class="n">Multilink</span><span class="p">(</span><span class="s">"keyword"</span><span class="p">),</span> <span class="n">priority</span><span class="o">=</span><span class="n">Link</span><span class="p">(</span><span class="s">"priority"</span><span class="p">),</span> <span class="n">status</span><span class="o">=</span><span class="n">Link</span><span class="p">(</span><span class="s">"status"</span><span class="p">),</span> <span class="n">due_date</span><span class="o">=</span><span class="n">Date</span><span class="p">())</span> </pre></div> </div> </li> <li><p class="first">Add an edit field to the <tt class="docutils literal"><span class="pre">issue.item.html</span></tt> template:</p> <div class="highlight-python"><pre><tr> <th>Due Date</th> <td tal:content="structure context/due_date/field" /> </tr></pre> </div> <p>If you want to show only the date part of due_date then do this instead:</p> <div class="highlight-python"><pre><tr> <th>Due Date</th> <td tal:content="structure python:context.due_date.field(format='%Y-%m-%d')" /> </tr></pre> </div> </li> <li><p class="first">Add the property to the <tt class="docutils literal"><span class="pre">issue.index.html</span></tt> page:</p> <div class="highlight-python"><pre>(in the heading row) <th tal:condition="request/show/due_date">Due Date</th> (in the data row) <td tal:condition="request/show/due_date" tal:content="i/due_date" /></pre> </div> <p>If you want format control of the display of the due date you can enter the following in the data row to show only the actual due date:</p> <div class="highlight-python"><pre><td tal:condition="request/show/due_date" tal:content="python:i.due_date.pretty('%Y-%m-%d')">&nbsp;</td></pre> </div> </li> <li><p class="first">Add the property to the <tt class="docutils literal"><span class="pre">issue.search.html</span></tt> page:</p> <div class="highlight-python"><pre><tr tal:define="name string:due_date"> <th i18n:translate="">Due Date:</th> <td metal:use-macro="search_input"></td> <td metal:use-macro="column_input"></td> <td metal:use-macro="sort_input"></td> <td metal:use-macro="group_input"></td> </tr></pre> </div> </li> <li><p class="first">If you wish for the due date to appear in the standard views listed in the sidebar of the web interface then you’ll need to add “due_date” to the columns and columns_showall lists in your <tt class="docutils literal"><span class="pre">page.html</span></tt>:</p> <div class="highlight-python"><pre>columns string:id,activity,due_date,title,creator,status; columns_showall string:id,activity,due_date,title,creator,assignedto,status;</pre> </div> </li> </ol> </div> <div class="section" id="adding-a-new-constrained-field-to-the-classic-schema"> <h4><a class="toc-backref" href="#id49">Adding a new constrained field to the classic schema</a></h4> <p>This example shows how to add a new constrained property (i.e. a selection of distinct values) to your tracker.</p> <div class="section" id="introduction"> <h5>Introduction</h5> <p>To make the classic schema of Roundup useful as a TODO tracking system for a group of systems administrators, it needs an extra data field per issue: a category.</p> <p>This would let sysadmins quickly list all TODOs in their particular area of interest without having to do complex queries, and without relying on the spelling capabilities of other sysadmins (a losing proposition at best).</p> </div> <div class="section" id="adding-a-field-to-the-database"> <h5>Adding a field to the database</h5> <p>This is the easiest part of the change. The category would just be a plain string, nothing fancy. To change what is in the database you need to add some lines to the <tt class="docutils literal"><span class="pre">schema.py</span></tt> file of your tracker instance. Under the comment:</p> <div class="highlight-python"><div class="highlight"><pre><span class="c"># add any additional database schema configuration here</span> </pre></div> </div> <p>add:</p> <div class="highlight-python"><div class="highlight"><pre><span class="n">category</span> <span class="o">=</span> <span class="n">Class</span><span class="p">(</span><span class="n">db</span><span class="p">,</span> <span class="s">"category"</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="n">String</span><span class="p">())</span> <span class="n">category</span><span class="o">.</span><span class="n">setkey</span><span class="p">(</span><span class="s">"name"</span><span class="p">)</span> </pre></div> </div> <p>Here we are setting up a chunk of the database which we are calling “category”. It contains a string, which we are refering to as “name” for lack of a more imaginative title. (Since “name” is one of the properties that Roundup looks for on items if you do not set a key for them, it’s probably a good idea to stick with it for new classes if at all appropriate.) Then we are setting the key of this chunk of the database to be that “name”. This is equivalent to an index for database types. This also means that there can only be one category with a given name.</p> <p>Adding the above lines allows us to create categories, but they’re not tied to the issues that we are going to be creating. It’s just a list of categories off on its own, which isn’t much use. We need to link it in with the issues. To do that, find the lines in <tt class="docutils literal"><span class="pre">schema.py</span></tt> which set up the “issue” class, and then add a link to the category:</p> <div class="highlight-python"><div class="highlight"><pre><span class="n">issue</span> <span class="o">=</span> <span class="n">IssueClass</span><span class="p">(</span><span class="n">db</span><span class="p">,</span> <span class="s">"issue"</span><span class="p">,</span> <span class="o">...</span> <span class="p">,</span> <span class="n">category</span><span class="o">=</span><span class="n">Multilink</span><span class="p">(</span><span class="s">"category"</span><span class="p">),</span> <span class="o">...</span> <span class="p">)</span> </pre></div> </div> <p>The <tt class="docutils literal"><span class="pre">Multilink()</span></tt> means that each issue can have many categories. If you were adding something with a one-to-one relationship to issues (such as the “assignedto” property), use <tt class="docutils literal"><span class="pre">Link()</span></tt> instead.</p> <p>That is all you need to do to change the schema. The rest of the effort is fiddling around so you can actually use the new category.</p> </div> <div class="section" id="populating-the-new-category-class"> <h5>Populating the new category class</h5> <p>If you haven’t initialised the database with the <tt class="docutils literal"><span class="pre">roundup-admin</span></tt> “initialise” command, then you can add the following to the tracker <tt class="docutils literal"><span class="pre">initial_data.py</span></tt> under the comment:</p> <div class="highlight-python"><div class="highlight"><pre><span class="c"># add any additional database creation steps here - but only if you</span> <span class="c"># haven't initialised the database with the admin "initialise" command</span> </pre></div> </div> <p>Add:</p> <div class="highlight-python"><div class="highlight"><pre><span class="n">category</span> <span class="o">=</span> <span class="n">db</span><span class="o">.</span><span class="n">getclass</span><span class="p">(</span><span class="s">'category'</span><span class="p">)</span> <span class="n">category</span><span class="o">.</span><span class="n">create</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s">"scipy"</span><span class="p">)</span> <span class="n">category</span><span class="o">.</span><span class="n">create</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s">"chaco"</span><span class="p">)</span> <span class="n">category</span><span class="o">.</span><span class="n">create</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s">"weave"</span><span class="p">)</span> </pre></div> </div> <p>If the database has already been initalised, then you need to use the <tt class="docutils literal"><span class="pre">roundup-admin</span></tt> tool:</p> <div class="highlight-python"><pre>% roundup-admin -i <tracker home> Roundup <version> ready for input. Type "help" for help. roundup> create category name=scipy 1 roundup> create category name=chaco 2 roundup> create category name=weave 3 roundup> exit... There are unsaved changes. Commit them (y/N)? y</pre> </div> </div> <div class="section" id="setting-up-security-on-the-new-objects"> <h5>Setting up security on the new objects</h5> <p>By default only the admin user can look at and change objects. This doesn’t suit us, as we want any user to be able to create new categories as required, and obviously everyone needs to be able to view the categories of issues for it to be useful.</p> <p>We therefore need to change the security of the category objects. This is also done in <tt class="docutils literal"><span class="pre">schema.py</span></tt>.</p> <p>There are currently two loops which set up permissions and then assign them to various roles. Simply add the new “category” to both lists:</p> <div class="highlight-python"><div class="highlight"><pre><span class="c"># Assign the access and edit permissions for issue, file and message</span> <span class="c"># to regular users now</span> <span class="k">for</span> <span class="n">cl</span> <span class="ow">in</span> <span class="s">'issue'</span><span class="p">,</span> <span class="s">'file'</span><span class="p">,</span> <span class="s">'msg'</span><span class="p">,</span> <span class="s">'category'</span><span class="p">:</span> <span class="n">p</span> <span class="o">=</span> <span class="n">db</span><span class="o">.</span><span class="n">security</span><span class="o">.</span><span class="n">getPermission</span><span class="p">(</span><span class="s">'View'</span><span class="p">,</span> <span class="n">cl</span><span class="p">)</span> <span class="n">db</span><span class="o">.</span><span class="n">security</span><span class="o">.</span><span class="n">addPermissionToRole</span><span class="p">(</span><span class="s">'User'</span><span class="p">,</span> <span class="s">'View'</span><span class="p">,</span> <span class="n">cl</span><span class="p">)</span> <span class="n">db</span><span class="o">.</span><span class="n">security</span><span class="o">.</span><span class="n">addPermissionToRole</span><span class="p">(</span><span class="s">'User'</span><span class="p">,</span> <span class="s">'Edit'</span><span class="p">,</span> <span class="n">cl</span><span class="p">)</span> <span class="n">db</span><span class="o">.</span><span class="n">security</span><span class="o">.</span><span class="n">addPermissionToRole</span><span class="p">(</span><span class="s">'User'</span><span class="p">,</span> <span class="s">'Create'</span><span class="p">,</span> <span class="n">cl</span><span class="p">)</span> </pre></div> </div> <p>These lines assign the “View” and “Edit” Permissions to the “User” role, so that normal users can view and edit “category” objects.</p> <p>This is all the work that needs to be done for the database. It will store categories, and let users view and edit them. Now on to the interface stuff.</p> </div> <div class="section" id="changing-the-web-left-hand-frame"> <h5>Changing the web left hand frame</h5> <p>We need to give the users the ability to create new categories, and the place to put the link to this functionality is in the left hand function bar, under the “Issues” area. The file that defines how this area looks is <tt class="docutils literal"><span class="pre">html/page.html</span></tt>, which is what we are going to be editing next.</p> <p>If you look at this file you can see that it contains a lot of “classblock” sections which are chunks of HTML that will be included or excluded in the output depending on whether the condition in the classblock is met. We are going to add the category code at the end of the classblock for the <em>issue</em> class:</p> <div class="highlight-python"><pre><p class="classblock" tal:condition="python:request.user.hasPermission('View', 'category')"> <b>Categories</b><br> <a tal:condition="python:request.user.hasPermission('Edit', 'category')" href="category?@template=item">New Category<br></a> </p></pre> </div> <p>The first two lines is the classblock definition, which sets up a condition that only users who have “View” permission for the “category” object will have this section included in their output. Next comes a plain “Categories” header in bold. Everyone who can view categories will get that.</p> <p>Next comes the link to the editing area of categories. This link will only appear if the condition - that the user has “Edit” permissions for the “category” objects - is matched. If they do have permission then they will get a link to another page which will let the user add new categories.</p> <p>Note that if you have permission to <em>view</em> but not to <em>edit</em> categories, then all you will see is a “Categories” header with nothing underneath it. This is obviously not very good interface design, but will do for now. I just claim that it is so I can add more links in this section later on. However, to fix the problem you could change the condition in the classblock statement, so that only users with “Edit” permission would see the “Categories” stuff.</p> </div> <div class="section" id="setting-up-a-page-to-edit-categories"> <h5>Setting up a page to edit categories</h5> <p>We defined code in the previous section which let users with the appropriate permissions see a link to a page which would let them edit conditions. Now we have to write that page.</p> <p>The link was for the <em>item</em> template of the <em>category</em> object. This translates into Roundup looking for a file called <tt class="docutils literal"><span class="pre">category.item.html</span></tt> in the <tt class="docutils literal"><span class="pre">html</span></tt> tracker directory. This is the file that we are going to write now.</p> <p>First, we add an info tag in a comment which doesn’t affect the outcome of the code at all, but is useful for debugging. If you load a page in a browser and look at the page source, you can see which sections come from which files by looking for these comments:</p> <div class="highlight-python"><pre><!-- category.item --></pre> </div> <p>Next we need to add in the METAL macro stuff so we get the normal page trappings:</p> <div class="highlight-python"><pre><tal:block metal:use-macro="templates/page/macros/icing"> <title metal:fill-slot="head_title">Category editing</title> <td class="page-header-top" metal:fill-slot="body_title"> <h2>Category editing</h2> </td> <td class="content" metal:fill-slot="content"></pre> </div> <p>Next we need to setup up a standard HTML form, which is the whole purpose of this file. We link to some handy javascript which sends the form through only once. This is to stop users hitting the send button multiple times when they are impatient and thus having the form sent multiple times:</p> <div class="highlight-python"><pre><form method="POST" onSubmit="return submit_once()" enctype="multipart/form-data"></pre> </div> <p>Next we define some code which sets up the minimum list of fields that we require the user to enter. There will be only one field - “name” - so they better put something in it, otherwise the whole form is pointless:</p> <div class="highlight-python"><pre><input type="hidden" name="@required" value="name"></pre> </div> <p>To get everything to line up properly we will put everything in a table, and put a nice big header on it so the user has an idea what is happening:</p> <div class="highlight-python"><pre><table class="form"> <tr><th class="header" colspan="2">Category</th></tr></pre> </div> <p>Next, we need the field into which the user is going to enter the new category. The <tt class="docutils literal"><span class="pre">context.name.field(size=60)</span></tt> bit tells Roundup to generate a normal HTML field of size 60, and the contents of that field will be the “name” variable of the current context (namely “category”). The upshot of this is that when the user types something in to the form, a new category will be created with that name:</p> <div class="highlight-python"><pre><tr> <th>Name</th> <td tal:content="structure python:context.name.field(size=60)"> name</td> </tr></pre> </div> <p>Then a submit button so that the user can submit the new category:</p> <div class="highlight-python"><pre><tr> <td>&nbsp;</td> <td colspan="3" tal:content="structure context/submit"> submit button will go here </td> </tr></pre> </div> <p>Finally we finish off the tags we used at the start to do the METAL stuff:</p> <div class="highlight-python"><pre> </td> </tal:block></pre> </div> <p>So putting it all together, and closing the table and form we get:</p> <div class="highlight-python"><pre><!-- category.item --> <tal:block metal:use-macro="templates/page/macros/icing"> <title metal:fill-slot="head_title">Category editing</title> <td class="page-header-top" metal:fill-slot="body_title"> <h2>Category editing</h2> </td> <td class="content" metal:fill-slot="content"> <form method="POST" onSubmit="return submit_once()" enctype="multipart/form-data"> <table class="form"> <tr><th class="header" colspan="2">Category</th></tr> <tr> <th>Name</th> <td tal:content="structure python:context.name.field(size=60)"> name</td> </tr> <tr> <td> &nbsp; <input type="hidden" name="@required" value="name"> </td> <td colspan="3" tal:content="structure context/submit"> submit button will go here </td> </tr> </table> </form> </td> </tal:block></pre> </div> <p>This is quite a lot to just ask the user one simple question, but there is a lot of setup for basically one line (the form line) to do its work. To add another field to “category” would involve one more line (well, maybe a few extra to get the formatting correct).</p> </div> <div class="section" id="adding-the-category-to-the-issue"> <h5>Adding the category to the issue</h5> <p>We now have the ability to create issues to our heart’s content, but that is pointless unless we can assign categories to issues. Just like the <tt class="docutils literal"><span class="pre">html/category.item.html</span></tt> file was used to define how to add a new category, the <tt class="docutils literal"><span class="pre">html/issue.item.html</span></tt> is used to define how a new issue is created.</p> <p>Just like <tt class="docutils literal"><span class="pre">category.issue.html</span></tt>, this file defines a form which has a table to lay things out. It doesn’t matter where in the table we add new stuff, it is entirely up to your sense of aesthetics:</p> <div class="highlight-python"><pre><th>Category</th> <td> <span tal:replace="structure context/category/field" /> <span tal:replace="structure python:db.category.classhelp('name', property='category', width='200')" /> </td></pre> </div> <p>First, we define a nice header so that the user knows what the next section is, then the middle line does what we are most interested in. This <tt class="docutils literal"><span class="pre">context/category/field</span></tt> gets replaced by a field which contains the category in the current context (the current context being the new issue).</p> <p>The classhelp lines generate a link (labelled “list”) to a popup window which contains the list of currently known categories.</p> </div> <div class="section" id="searching-on-categories"> <h5>Searching on categories</h5> <p>Now we can add categories, and create issues with categories. The next obvious thing that we would like to be able to do, would be to search for issues based on their category, so that, for example, anyone working on the web server could look at all issues in the category “Web”.</p> <p>If you look for “Search Issues” in the <tt class="docutils literal"><span class="pre">html/page.html</span></tt> file, you will find that it looks something like <tt class="docutils literal"><span class="pre"><a</span> <span class="pre">href="issue?@template=search">Search</span> <span class="pre">Issues</a></span></tt>. This shows us that when you click on “Search Issues” it will be looking for a <tt class="docutils literal"><span class="pre">issue.search.html</span></tt> file to display. So that is the file that we will change.</p> <p>If you look at this file it should begin to seem familiar, although it does use some new macros. You can add the new category search code anywhere you like within that form:</p> <div class="highlight-python"><pre><tr tal:define="name string:category; db_klass string:category; db_content string:name;"> <th>Priority:</th> <td metal:use-macro="search_select"></td> <td metal:use-macro="column_input"></td> <td metal:use-macro="sort_input"></td> <td metal:use-macro="group_input"></td> </tr></pre> </div> <p>The definitions in the <tt class="docutils literal"><span class="pre"><tr></span></tt> opening tag are used by the macros:</p> <ul class="simple"> <li><tt class="docutils literal"><span class="pre">search_select</span></tt> expands to a drop-down box with all categories using <tt class="docutils literal"><span class="pre">db_klass</span></tt> and <tt class="docutils literal"><span class="pre">db_content</span></tt>.</li> <li><tt class="docutils literal"><span class="pre">column_input</span></tt> expands to a checkbox for selecting what columns should be displayed.</li> <li><tt class="docutils literal"><span class="pre">sort_input</span></tt> expands to a radio button for selecting what property should be sorted on.</li> <li><tt class="docutils literal"><span class="pre">group_input</span></tt> expands to a radio button for selecting what property should be grouped on.</li> </ul> <p>The category search code above would expand to the following:</p> <div class="highlight-python"><pre><tr> <th>Category:</th> <td> <select name="category"> <option value="">don't care</option> <option value="">------------</option> <option value="1">scipy</option> <option value="2">chaco</option> <option value="3">weave</option> </select> </td> <td><input type="checkbox" name=":columns" value="category"></td> <td><input type="radio" name=":sort0" value="category"></td> <td><input type="radio" name=":group0" value="category"></td> </tr></pre> </div> </div> <div class="section" id="adding-category-to-the-default-view"> <h5>Adding category to the default view</h5> <p>We can now add categories, add issues with categories, and search for issues based on categories. This is everything that we need to do; however, there is some more icing that we would like. I think the category of an issue is important enough that it should be displayed by default when listing all the issues.</p> <p>Unfortunately, this is a bit less obvious than the previous steps. The code defining how the issues look is in <tt class="docutils literal"><span class="pre">html/issue.index.html</span></tt>. This is a large table with a form down at the bottom for redisplaying and so forth.</p> <p>Firstly we need to add an appropriate header to the start of the table:</p> <div class="highlight-python"><pre><th tal:condition="request/show/category">Category</th></pre> </div> <p>The <em>condition</em> part of this statement is to avoid displaying the Category column if the user has selected not to see it.</p> <p>The rest of the table is a loop which will go through every issue that matches the display criteria. The loop variable is “i” - which means that every issue gets assigned to “i” in turn.</p> <p>The new part of code to display the category will look like this:</p> <div class="highlight-python"><pre><td tal:condition="request/show/category" tal:content="i/category"></td></pre> </div> <p>The condition is the same as above: only display the condition when the user hasn’t asked for it to be hidden. The next part is to set the content of the cell to be the category part of “i” - the current issue.</p> <p>Finally we have to edit <tt class="docutils literal"><span class="pre">html/page.html</span></tt> again. This time, we need to tell it that when the user clicks on “Unassigned Issues” or “All Issues”, the category column should be included in the resulting list. If you scroll down the page file, you can see the links with lots of options. The option that we are interested in is the <tt class="docutils literal"><span class="pre">:columns=</span></tt> one which tells roundup which fields of the issue to display. Simply add “category” to that list and it all should work.</p> </div> </div> <div class="section" id="adding-a-time-log-to-your-issues"> <h4><a class="toc-backref" href="#id50">Adding a time log to your issues</a></h4> <p>We want to log the dates and amount of time spent working on issues, and be able to give a summary of the total time spent on a particular issue.</p> <ol class="arabic"> <li><p class="first">Add a new class to your tracker <tt class="docutils literal"><span class="pre">schema.py</span></tt>:</p> <div class="highlight-python"><div class="highlight"><pre><span class="c"># storage for time logging</span> <span class="n">timelog</span> <span class="o">=</span> <span class="n">Class</span><span class="p">(</span><span class="n">db</span><span class="p">,</span> <span class="s">"timelog"</span><span class="p">,</span> <span class="n">period</span><span class="o">=</span><span class="n">Interval</span><span class="p">())</span> </pre></div> </div> <p>Note that we automatically get the date of the time log entry creation through the standard property “creation”.</p> <p>You will need to grant “Creation” permission to the users who are allowed to add timelog entries. You may do this with:</p> <div class="highlight-python"><div class="highlight"><pre><span class="n">db</span><span class="o">.</span><span class="n">security</span><span class="o">.</span><span class="n">addPermissionToRole</span><span class="p">(</span><span class="s">'User'</span><span class="p">,</span> <span class="s">'Create'</span><span class="p">,</span> <span class="s">'timelog'</span><span class="p">)</span> <span class="n">db</span><span class="o">.</span><span class="n">security</span><span class="o">.</span><span class="n">addPermissionToRole</span><span class="p">(</span><span class="s">'User'</span><span class="p">,</span> <span class="s">'View'</span><span class="p">,</span> <span class="s">'timelog'</span><span class="p">)</span> </pre></div> </div> <p>If users are also able to <em>edit</em> timelog entries, then also include:</p> <div class="highlight-python"><div class="highlight"><pre><span class="n">db</span><span class="o">.</span><span class="n">security</span><span class="o">.</span><span class="n">addPermissionToRole</span><span class="p">(</span><span class="s">'User'</span><span class="p">,</span> <span class="s">'Edit'</span><span class="p">,</span> <span class="s">'timelog'</span><span class="p">)</span> </pre></div> </div> </li> <li><p class="first">Link to the new class from your issue class (again, in <tt class="docutils literal"><span class="pre">schema.py</span></tt>):</p> <div class="highlight-python"><div class="highlight"><pre><span class="n">issue</span> <span class="o">=</span> <span class="n">IssueClass</span><span class="p">(</span><span class="n">db</span><span class="p">,</span> <span class="s">"issue"</span><span class="p">,</span> <span class="n">assignedto</span><span class="o">=</span><span class="n">Link</span><span class="p">(</span><span class="s">"user"</span><span class="p">),</span> <span class="n">keyword</span><span class="o">=</span><span class="n">Multilink</span><span class="p">(</span><span class="s">"keyword"</span><span class="p">),</span> <span class="n">priority</span><span class="o">=</span><span class="n">Link</span><span class="p">(</span><span class="s">"priority"</span><span class="p">),</span> <span class="n">status</span><span class="o">=</span><span class="n">Link</span><span class="p">(</span><span class="s">"status"</span><span class="p">),</span> <span class="n">times</span><span class="o">=</span><span class="n">Multilink</span><span class="p">(</span><span class="s">"timelog"</span><span class="p">))</span> </pre></div> </div> <p>the “times” property is the new link to the “timelog” class.</p> </li> <li><p class="first">We’ll need to let people add in times to the issue, so in the web interface we’ll have a new entry field. This is a special field because unlike the other fields in the <tt class="docutils literal"><span class="pre">issue.item</span></tt> template, it affects a different item (a timelog item) and not the template’s item (an issue). We have a special syntax for form fields that affect items other than the template default item (see the cgi documentation on <a class="reference internal" href="#special-form-variables">special form variables</a>). In particular, we add a field to capture a new timelog item’s period:</p> <div class="highlight-python"><pre><tr> <th>Time Log</th> <td colspan=3><input type="text" name="timelog-1@period" /> (enter as '3y 1m 4d 2:40:02' or parts thereof) </td> </tr></pre> </div> <p>and another hidden field that links that new timelog item (new because it’s marked as having id “-1”) to the issue item. It looks like this:</p> <div class="highlight-python"><pre><input type="hidden" name="@link@times" value="timelog-1" /></pre> </div> <p>On submission, the “-1” timelog item will be created and assigned a real item id. The “times” property of the issue will have the new id added to it.</p> <p>The full entry will now look like this:</p> <div class="highlight-python"><pre><tr> <th>Time Log</th> <td colspan=3><input type="text" name="timelog-1@period" /> (enter as '3y 1m 4d 2:40:02' or parts thereof) <input type="hidden" name="@link@times" value="timelog-1" /> </td> </tr></pre> </div> </li> <li><p class="first">We want to display a total of the timelog times that have been accumulated for an issue. To do this, we’ll need to actually write some Python code, since it’s beyond the scope of PageTemplates to perform such calculations. We do this by adding a module <tt class="docutils literal"><span class="pre">timespent.py</span></tt> to the <tt class="docutils literal"><span class="pre">extensions</span></tt> directory in our tracker. The contents of this file is as follows:</p> <div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">roundup</span> <span class="kn">import</span> <span class="n">date</span> <span class="k">def</span> <span class="nf">totalTimeSpent</span><span class="p">(</span><span class="n">times</span><span class="p">):</span> <span class="sd">''' Call me with a list of timelog items (which have an</span> <span class="sd"> Interval "period" property)</span> <span class="sd"> '''</span> <span class="n">total</span> <span class="o">=</span> <span class="n">date</span><span class="o">.</span><span class="n">Interval</span><span class="p">(</span><span class="s">'0d'</span><span class="p">)</span> <span class="k">for</span> <span class="n">time</span> <span class="ow">in</span> <span class="n">times</span><span class="p">:</span> <span class="n">total</span> <span class="o">+=</span> <span class="n">time</span><span class="o">.</span><span class="n">period</span><span class="o">.</span><span class="n">_value</span> <span class="k">return</span> <span class="n">total</span> <span class="k">def</span> <span class="nf">init</span><span class="p">(</span><span class="n">instance</span><span class="p">):</span> <span class="n">instance</span><span class="o">.</span><span class="n">registerUtil</span><span class="p">(</span><span class="s">'totalTimeSpent'</span><span class="p">,</span> <span class="n">totalTimeSpent</span><span class="p">)</span> </pre></div> </div> <p>We will now be able to access the <tt class="docutils literal"><span class="pre">totalTimeSpent</span></tt> function via the <tt class="docutils literal"><span class="pre">utils</span></tt> variable in our templates, as shown in the next step.</p> </li> <li><p class="first">Display the timelog for an issue:</p> <div class="highlight-python"><pre><table class="otherinfo" tal:condition="context/times"> <tr><th colspan="3" class="header">Time Log <tal:block tal:replace="python:utils.totalTimeSpent(context.times)" /> </th></tr> <tr><th>Date</th><th>Period</th><th>Logged By</th></tr> <tr tal:repeat="time context/times"> <td tal:content="time/creation"></td> <td tal:content="time/period"></td> <td tal:content="time/creator"></td> </tr> </table></pre> </div> <p>I put this just above the Messages log in my issue display. Note our use of the <tt class="docutils literal"><span class="pre">totalTimeSpent</span></tt> method which will total up the times for the issue and return a new Interval. That will be automatically displayed in the template as text like “+ 1y 2:40” (1 year, 2 hours and 40 minutes).</p> </li> <li><p class="first">If you’re using a persistent web server - <tt class="docutils literal"><span class="pre">roundup-server</span></tt> or <tt class="docutils literal"><span class="pre">mod_python</span></tt> for example - then you’ll need to restart that to pick up the code changes. When that’s done, you’ll be able to use the new time logging interface.</p> </li> </ol> <p>An extension of this modification attaches the timelog entries to any change message entered at the time of the timelog entry:</p> <ol class="upperalpha"> <li><p class="first">Add a link to the timelog to the msg class in <tt class="docutils literal"><span class="pre">schema.py</span></tt>:</p> <blockquote> <dl class="docutils"> <dt>msg = FileClass(db, “msg”,</dt> <dd><p class="first last">author=Link(“user”, do_journal=’no’), recipients=Multilink(“user”, do_journal=’no’), date=Date(), summary=String(), files=Multilink(“file”), messageid=String(), inreplyto=String(), times=Multilink(“timelog”))</p> </dd> </dl> </blockquote> </li> <li><p class="first">Add a new hidden field that links that new timelog item (new because it’s marked as having id “-1”) to the new message. The link is placed in <tt class="docutils literal"><span class="pre">issue.item.html</span></tt> in the same section that handles the timelog entry.</p> <p>It looks like this after this addition:</p> <div class="highlight-python"><pre><tr> <th>Time Log</th> <td colspan=3><input type="text" name="timelog-1@period" /> (enter as '3y 1m 4d 2:40:02' or parts thereof) <input type="hidden" name="@link@times" value="timelog-1" /> <input type="hidden" name="msg-1@link@times" value="timelog-1" /> </td> </tr></pre> </div> <p>The “times” property of the message will have the new id added to it.</p> </li> <li><p class="first">Add the timelog listing from step 5. to the <tt class="docutils literal"><span class="pre">msg.item.html</span></tt> template so that the timelog entry appears on the message view page. Note that the call to totalTimeSpent is not used here since there will only be one single timelog entry for each message.</p> <p>I placed it after the Date entry like this:</p> <div class="highlight-python"><pre><tr> <th i18n:translate="">Date:</th> <td tal:content="context/date"></td> </tr> </table> <table class="otherinfo" tal:condition="context/times"> <tr><th colspan="3" class="header">Time Log</th></tr> <tr><th>Date</th><th>Period</th><th>Logged By</th></tr> <tr tal:repeat="time context/times"> <td tal:content="time/creation"></td> <td tal:content="time/period"></td> <td tal:content="time/creator"></td> </tr> </table> <table class="messages"></pre> </div> </li> </ol> </div> <div class="section" id="tracking-different-types-of-issues"> <h4><a class="toc-backref" href="#id51">Tracking different types of issues</a></h4> <p>Sometimes you will want to track different types of issues - developer, customer support, systems, sales leads, etc. A single Roundup tracker is able to support multiple types of issues. This example demonstrates adding a system support issue class to a tracker.</p> <ol class="arabic"> <li><p class="first">Figure out what information you’re going to want to capture. OK, so this is obvious, but sometimes it’s better to actually sit down for a while and think about the schema you’re going to implement.</p> </li> <li><p class="first">Add the new issue class to your tracker’s <tt class="docutils literal"><span class="pre">schema.py</span></tt>. Just after the “issue” class definition, add:</p> <div class="highlight-python"><div class="highlight"><pre><span class="c"># list our systems</span> <span class="n">system</span> <span class="o">=</span> <span class="n">Class</span><span class="p">(</span><span class="n">db</span><span class="p">,</span> <span class="s">"system"</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="n">String</span><span class="p">(),</span> <span class="n">order</span><span class="o">=</span><span class="n">Number</span><span class="p">())</span> <span class="n">system</span><span class="o">.</span><span class="n">setkey</span><span class="p">(</span><span class="s">"name"</span><span class="p">)</span> <span class="c"># store issues related to those systems</span> <span class="n">support</span> <span class="o">=</span> <span class="n">IssueClass</span><span class="p">(</span><span class="n">db</span><span class="p">,</span> <span class="s">"support"</span><span class="p">,</span> <span class="n">assignedto</span><span class="o">=</span><span class="n">Link</span><span class="p">(</span><span class="s">"user"</span><span class="p">),</span> <span class="n">keyword</span><span class="o">=</span><span class="n">Multilink</span><span class="p">(</span><span class="s">"keyword"</span><span class="p">),</span> <span class="n">status</span><span class="o">=</span><span class="n">Link</span><span class="p">(</span><span class="s">"status"</span><span class="p">),</span> <span class="n">deadline</span><span class="o">=</span><span class="n">Date</span><span class="p">(),</span> <span class="n">affects</span><span class="o">=</span><span class="n">Multilink</span><span class="p">(</span><span class="s">"system"</span><span class="p">))</span> </pre></div> </div> </li> <li><p class="first">Copy the existing <tt class="docutils literal"><span class="pre">issue.*</span></tt> (item, search and index) templates in the tracker’s <tt class="docutils literal"><span class="pre">html</span></tt> to <tt class="docutils literal"><span class="pre">support.*</span></tt>. Edit them so they use the properties defined in the <tt class="docutils literal"><span class="pre">support</span></tt> class. Be sure to check for hidden form variables like “required” to make sure they have the correct set of required properties.</p> </li> <li><p class="first">Edit the modules in the <tt class="docutils literal"><span class="pre">detectors</span></tt>, adding lines to their <tt class="docutils literal"><span class="pre">init</span></tt> functions where appropriate. Look for <tt class="docutils literal"><span class="pre">audit</span></tt> and <tt class="docutils literal"><span class="pre">react</span></tt> registrations on the <tt class="docutils literal"><span class="pre">issue</span></tt> class, and duplicate them for <tt class="docutils literal"><span class="pre">support</span></tt>.</p> </li> <li><p class="first">Create a new sidebar box for the new support class. Duplicate the existing issues one, changing the <tt class="docutils literal"><span class="pre">issue</span></tt> class name to <tt class="docutils literal"><span class="pre">support</span></tt>.</p> </li> <li><p class="first">Re-start your tracker and start using the new <tt class="docutils literal"><span class="pre">support</span></tt> class.</p> </li> </ol> <p>Optionally, you might want to restrict the users able to access this new class to just the users with a new “SysAdmin” Role. To do this, we add some security declarations:</p> <div class="highlight-python"><div class="highlight"><pre><span class="n">db</span><span class="o">.</span><span class="n">security</span><span class="o">.</span><span class="n">addPermissionToRole</span><span class="p">(</span><span class="s">'SysAdmin'</span><span class="p">,</span> <span class="s">'View'</span><span class="p">,</span> <span class="s">'support'</span><span class="p">)</span> <span class="n">db</span><span class="o">.</span><span class="n">security</span><span class="o">.</span><span class="n">addPermissionToRole</span><span class="p">(</span><span class="s">'SysAdmin'</span><span class="p">,</span> <span class="s">'Create'</span><span class="p">,</span> <span class="s">'support'</span><span class="p">)</span> <span class="n">db</span><span class="o">.</span><span class="n">security</span><span class="o">.</span><span class="n">addPermissionToRole</span><span class="p">(</span><span class="s">'SysAdmin'</span><span class="p">,</span> <span class="s">'Edit'</span><span class="p">,</span> <span class="s">'support'</span><span class="p">)</span> </pre></div> </div> <p>You would then (as an “admin” user) edit the details of the appropriate users, and add “SysAdmin” to their Roles list.</p> <p>Alternatively, you might want to change the Edit/View permissions granted for the <tt class="docutils literal"><span class="pre">issue</span></tt> class so that it’s only available to users with the “System” or “Developer” Role, and then the new class you’re adding is available to all with the “User” Role.</p> </div> </div> <div class="section" id="using-external-user-databases"> <h3><a class="toc-backref" href="#id52">Using External User Databases</a></h3> <div class="section" id="using-an-external-password-validation-source"> <h4><a class="toc-backref" href="#id53">Using an external password validation source</a></h4> <div class="admonition note"> <p class="first admonition-title">Note</p> <p class="last">You will need to either have an “admin” user in your external password source <em>or</em> have one of your regular users have the Admin Role assigned. If you need to assign the Role <em>after</em> making the changes below, you may use the <tt class="docutils literal"><span class="pre">roundup-admin</span></tt> program to edit a user’s details.</p> </div> <p>We have a centrally-managed password changing system for our users. This results in a UN*X passwd-style file that we use for verification of users. Entries in the file consist of <tt class="docutils literal"><span class="pre">name:password</span></tt> where the password is encrypted using the standard UN*X <tt class="docutils literal"><span class="pre">crypt()</span></tt> function (see the <tt class="docutils literal"><span class="pre">crypt</span></tt> module in your Python distribution). An example entry would be:</p> <div class="highlight-python"><pre>admin:aamrgyQfDFSHw</pre> </div> <p>Each user of Roundup must still have their information stored in the Roundup database - we just use the passwd file to check their password. To do this, we need to override the standard <tt class="docutils literal"><span class="pre">verifyPassword</span></tt> method defined in <tt class="docutils literal"><span class="pre">roundup.cgi.actions.LoginAction</span></tt> and register the new class. The following is added as <tt class="docutils literal"><span class="pre">externalpassword.py</span></tt> in the tracker <tt class="docutils literal"><span class="pre">extensions</span></tt> directory:</p> <div class="highlight-python"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">os</span><span class="o">,</span> <span class="nn">crypt</span> <span class="kn">from</span> <span class="nn">roundup.cgi.actions</span> <span class="kn">import</span> <span class="n">LoginAction</span> <span class="k">class</span> <span class="nc">ExternalPasswordLoginAction</span><span class="p">(</span><span class="n">LoginAction</span><span class="p">):</span> <span class="k">def</span> <span class="nf">verifyPassword</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">userid</span><span class="p">,</span> <span class="n">password</span><span class="p">):</span> <span class="sd">'''Look through the file, line by line, looking for a</span> <span class="sd"> name that matches.</span> <span class="sd"> '''</span> <span class="c"># get the user's username</span> <span class="n">username</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db</span><span class="o">.</span><span class="n">user</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">userid</span><span class="p">,</span> <span class="s">'username'</span><span class="p">)</span> <span class="c"># the passwords are stored in the "passwd.txt" file in the</span> <span class="c"># tracker home</span> <span class="nb">file</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">db</span><span class="o">.</span><span class="n">config</span><span class="o">.</span><span class="n">TRACKER_HOME</span><span class="p">,</span> <span class="s">'passwd.txt'</span><span class="p">)</span> <span class="c"># see if we can find a match</span> <span class="k">for</span> <span class="n">ent</span> <span class="ow">in</span> <span class="p">[</span><span class="n">line</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s">':'</span><span class="p">)</span> <span class="k">for</span> <span class="n">line</span> <span class="ow">in</span> <span class="nb">open</span><span class="p">(</span><span class="nb">file</span><span class="p">)</span><span class="o">.</span><span class="n">readlines</span><span class="p">()]:</span> <span class="k">if</span> <span class="n">ent</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="n">username</span><span class="p">:</span> <span class="k">return</span> <span class="n">crypt</span><span class="o">.</span><span class="n">crypt</span><span class="p">(</span><span class="n">password</span><span class="p">,</span> <span class="n">ent</span><span class="p">[</span><span class="mi">1</span><span class="p">][:</span><span class="mi">2</span><span class="p">])</span> <span class="o">==</span> <span class="n">ent</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="c"># user doesn't exist in the file</span> <span class="k">return</span> <span class="mi">0</span> <span class="k">def</span> <span class="nf">init</span><span class="p">(</span><span class="n">instance</span><span class="p">):</span> <span class="n">instance</span><span class="o">.</span><span class="n">registerAction</span><span class="p">(</span><span class="s">'login'</span><span class="p">,</span> <span class="n">ExternalPasswordLoginAction</span><span class="p">)</span> </pre></div> </div> <p>You should also remove the redundant password fields from the <tt class="docutils literal"><span class="pre">user.item</span></tt> template.</p> </div> <div class="section" id="using-a-un-x-passwd-file-as-the-user-database"> <h4><a class="toc-backref" href="#id54">Using a UN*X passwd file as the user database</a></h4> <p>On some systems the primary store of users is the UN*X passwd file. It holds information on users such as their username, real name, password and primary user group.</p> <p>Roundup can use this store as its primary source of user information, but it needs additional information too - email address(es), roundup Roles, vacation flags, roundup hyperdb item ids, etc. Also, “retired” users must still exist in the user database, unlike some passwd files in which the users are removed when they no longer have access to a system.</p> <p>To make use of the passwd file, we therefore synchronise between the two user stores. We also use the passwd file to validate the user logins, as described in the previous example, <a class="reference internal" href="#using-an-external-password-validation-source">using an external password validation source</a>. We keep the user lists in sync using a fairly simple script that runs once a day, or several times an hour if more immediate access is needed. In short, it:</p> <ol class="arabic simple"> <li>parses the passwd file, finding usernames, passwords and real names,</li> <li>compares that list to the current roundup user list:<ol class="loweralpha"> <li>entries no longer in the passwd file are <em>retired</em></li> <li>entries with mismatching real names are <em>updated</em></li> <li>entries only exist in the passwd file are <em>created</em></li> </ol> </li> <li>send an email to administrators to let them know what’s been done.</li> </ol> <p>The retiring and updating are simple operations, requiring only a call to <tt class="docutils literal"><span class="pre">retire()</span></tt> or <tt class="docutils literal"><span class="pre">set()</span></tt>. The creation operation requires more information though - the user’s email address and their Roundup Roles. We’re going to assume that the user’s email address is the same as their login name, so we just append the domain name to that. The Roles are determined using the passwd group identifier - mapping their UN*X group to an appropriate set of Roles.</p> <p>The script to perform all this, broken up into its main components, is as follows. Firstly, we import the necessary modules and open the tracker we’re to work on:</p> <div class="highlight-python"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">sys</span><span class="o">,</span> <span class="nn">os</span><span class="o">,</span> <span class="nn">smtplib</span> <span class="kn">from</span> <span class="nn">roundup</span> <span class="kn">import</span> <span class="n">instance</span><span class="p">,</span> <span class="n">date</span> <span class="c"># open the tracker</span> <span class="n">tracker_home</span> <span class="o">=</span> <span class="n">sys</span><span class="o">.</span><span class="n">argv</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="n">tracker</span> <span class="o">=</span> <span class="n">instance</span><span class="o">.</span><span class="n">open</span><span class="p">(</span><span class="n">tracker_home</span><span class="p">)</span> </pre></div> </div> <p>Next we read in the <em>passwd</em> file from the tracker home:</p> <div class="highlight-python"><div class="highlight"><pre><span class="c"># read in the users from the "passwd.txt" file</span> <span class="nb">file</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">tracker_home</span><span class="p">,</span> <span class="s">'passwd.txt'</span><span class="p">)</span> <span class="n">users</span> <span class="o">=</span> <span class="p">[</span><span class="n">x</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s">':'</span><span class="p">)</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="nb">open</span><span class="p">(</span><span class="nb">file</span><span class="p">)</span><span class="o">.</span><span class="n">readlines</span><span class="p">()]</span> </pre></div> </div> <p>Handle special users (those to ignore in the file, and those who don’t appear in the file):</p> <div class="highlight-python"><div class="highlight"><pre><span class="c"># users to not keep ever, pre-load with the users I know aren't</span> <span class="c"># "real" users</span> <span class="n">ignore</span> <span class="o">=</span> <span class="p">[</span><span class="s">'ekmmon'</span><span class="p">,</span> <span class="s">'bfast'</span><span class="p">,</span> <span class="s">'csrmail'</span><span class="p">]</span> <span class="c"># users to keep - pre-load with the roundup-specific users</span> <span class="n">keep</span> <span class="o">=</span> <span class="p">[</span><span class="s">'comment_pool'</span><span class="p">,</span> <span class="s">'network_pool'</span><span class="p">,</span> <span class="s">'admin'</span><span class="p">,</span> <span class="s">'dev-team'</span><span class="p">,</span> <span class="s">'cs_pool'</span><span class="p">,</span> <span class="s">'anonymous'</span><span class="p">,</span> <span class="s">'system_pool'</span><span class="p">,</span> <span class="s">'automated'</span><span class="p">]</span> </pre></div> </div> <p>Now we map the UN*X group numbers to the Roles that users should have:</p> <div class="highlight-python"><div class="highlight"><pre><span class="n">roles</span> <span class="o">=</span> <span class="p">{</span> <span class="s">'501'</span><span class="p">:</span> <span class="s">'User,Tech'</span><span class="p">,</span> <span class="c"># tech</span> <span class="s">'502'</span><span class="p">:</span> <span class="s">'User'</span><span class="p">,</span> <span class="c"># finance</span> <span class="s">'503'</span><span class="p">:</span> <span class="s">'User,CSR'</span><span class="p">,</span> <span class="c"># customer service reps</span> <span class="s">'504'</span><span class="p">:</span> <span class="s">'User'</span><span class="p">,</span> <span class="c"># sales</span> <span class="s">'505'</span><span class="p">:</span> <span class="s">'User'</span><span class="p">,</span> <span class="c"># marketing</span> <span class="p">}</span> </pre></div> </div> <p>Now we do all the work. Note that the body of the script (where we have the tracker database open) is wrapped in a <tt class="docutils literal"><span class="pre">try</span></tt> / <tt class="docutils literal"><span class="pre">finally</span></tt> clause, so that we always close the database cleanly when we’re finished. So, we now do all the work:</p> <div class="highlight-python"><div class="highlight"><pre><span class="c"># open the database</span> <span class="n">db</span> <span class="o">=</span> <span class="n">tracker</span><span class="o">.</span><span class="n">open</span><span class="p">(</span><span class="s">'admin'</span><span class="p">)</span> <span class="k">try</span><span class="p">:</span> <span class="c"># store away messages to send to the tracker admins</span> <span class="n">msg</span> <span class="o">=</span> <span class="p">[]</span> <span class="c"># loop over the users list read in from the passwd file</span> <span class="k">for</span> <span class="n">user</span><span class="p">,</span><span class="n">passw</span><span class="p">,</span><span class="n">uid</span><span class="p">,</span><span class="n">gid</span><span class="p">,</span><span class="n">real</span><span class="p">,</span><span class="n">home</span><span class="p">,</span><span class="n">shell</span> <span class="ow">in</span> <span class="n">users</span><span class="p">:</span> <span class="k">if</span> <span class="n">user</span> <span class="ow">in</span> <span class="n">ignore</span><span class="p">:</span> <span class="c"># this user shouldn't appear in our tracker</span> <span class="k">continue</span> <span class="n">keep</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">user</span><span class="p">)</span> <span class="k">try</span><span class="p">:</span> <span class="c"># see if the user exists in the tracker</span> <span class="n">uid</span> <span class="o">=</span> <span class="n">db</span><span class="o">.</span><span class="n">user</span><span class="o">.</span><span class="n">lookup</span><span class="p">(</span><span class="n">user</span><span class="p">)</span> <span class="c"># yes, they do - now check the real name for correctness</span> <span class="k">if</span> <span class="n">real</span> <span class="o">!=</span> <span class="n">db</span><span class="o">.</span><span class="n">user</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">uid</span><span class="p">,</span> <span class="s">'realname'</span><span class="p">):</span> <span class="n">db</span><span class="o">.</span><span class="n">user</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="n">uid</span><span class="p">,</span> <span class="n">realname</span><span class="o">=</span><span class="n">real</span><span class="p">)</span> <span class="n">msg</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s">'FIX </span><span class="si">%s</span><span class="s"> - </span><span class="si">%s</span><span class="s">'</span><span class="o">%</span><span class="p">(</span><span class="n">user</span><span class="p">,</span> <span class="n">real</span><span class="p">))</span> <span class="k">except</span> <span class="ne">KeyError</span><span class="p">:</span> <span class="c"># nope, the user doesn't exist</span> <span class="n">db</span><span class="o">.</span><span class="n">user</span><span class="o">.</span><span class="n">create</span><span class="p">(</span><span class="n">username</span><span class="o">=</span><span class="n">user</span><span class="p">,</span> <span class="n">realname</span><span class="o">=</span><span class="n">real</span><span class="p">,</span> <span class="n">address</span><span class="o">=</span><span class="s">'</span><span class="si">%s</span><span class="s">@ekit-inc.com'</span><span class="o">%</span><span class="n">user</span><span class="p">,</span> <span class="n">roles</span><span class="o">=</span><span class="n">roles</span><span class="p">[</span><span class="n">gid</span><span class="p">])</span> <span class="n">msg</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s">'ADD </span><span class="si">%s</span><span class="s"> - </span><span class="si">%s</span><span class="s"> (</span><span class="si">%s</span><span class="s">)'</span><span class="o">%</span><span class="p">(</span><span class="n">user</span><span class="p">,</span> <span class="n">real</span><span class="p">,</span> <span class="n">roles</span><span class="p">[</span><span class="n">gid</span><span class="p">]))</span> <span class="c"># now check that all the users in the tracker are also in our</span> <span class="c"># "keep" list - retire those who aren't</span> <span class="k">for</span> <span class="n">uid</span> <span class="ow">in</span> <span class="n">db</span><span class="o">.</span><span class="n">user</span><span class="o">.</span><span class="n">list</span><span class="p">():</span> <span class="n">user</span> <span class="o">=</span> <span class="n">db</span><span class="o">.</span><span class="n">user</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">uid</span><span class="p">,</span> <span class="s">'username'</span><span class="p">)</span> <span class="k">if</span> <span class="n">user</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">keep</span><span class="p">:</span> <span class="n">db</span><span class="o">.</span><span class="n">user</span><span class="o">.</span><span class="n">retire</span><span class="p">(</span><span class="n">uid</span><span class="p">)</span> <span class="n">msg</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s">'RET </span><span class="si">%s</span><span class="s">'</span><span class="o">%</span><span class="n">user</span><span class="p">)</span> <span class="c"># if we did work, then send email to the tracker admins</span> <span class="k">if</span> <span class="n">msg</span><span class="p">:</span> <span class="c"># create the email</span> <span class="n">msg</span> <span class="o">=</span> <span class="s">'''Subject: </span><span class="si">%s</span><span class="s"> user database maintenance</span> <span class="s"> </span><span class="si">%s</span><span class="s"></span> <span class="s"> '''</span><span class="o">%</span><span class="p">(</span><span class="n">db</span><span class="o">.</span><span class="n">config</span><span class="o">.</span><span class="n">TRACKER_NAME</span><span class="p">,</span> <span class="s">'</span><span class="se">\n</span><span class="s">'</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">msg</span><span class="p">))</span> <span class="c"># send the email</span> <span class="n">smtp</span> <span class="o">=</span> <span class="n">smtplib</span><span class="o">.</span><span class="n">SMTP</span><span class="p">(</span><span class="n">db</span><span class="o">.</span><span class="n">config</span><span class="o">.</span><span class="n">MAILHOST</span><span class="p">)</span> <span class="n">addr</span> <span class="o">=</span> <span class="n">db</span><span class="o">.</span><span class="n">config</span><span class="o">.</span><span class="n">ADMIN_EMAIL</span> <span class="n">smtp</span><span class="o">.</span><span class="n">sendmail</span><span class="p">(</span><span class="n">addr</span><span class="p">,</span> <span class="n">addr</span><span class="p">,</span> <span class="n">msg</span><span class="p">)</span> <span class="c"># now we're done - commit the changes</span> <span class="n">db</span><span class="o">.</span><span class="n">commit</span><span class="p">()</span> <span class="k">finally</span><span class="p">:</span> <span class="c"># always close the database cleanly</span> <span class="n">db</span><span class="o">.</span><span class="n">close</span><span class="p">()</span> </pre></div> </div> <p>And that’s it!</p> </div> <div class="section" id="using-an-ldap-database-for-user-information"> <h4><a class="toc-backref" href="#id55">Using an LDAP database for user information</a></h4> <p>A script that reads users from an LDAP store using <a class="reference external" href="http://python-ldap.sf.net/">http://python-ldap.sf.net/</a> and then compares the list to the users in the roundup user database would be pretty easy to write. You’d then have it run once an hour / day (or on demand if you can work that into your LDAP store workflow). See the example <a class="reference internal" href="#using-a-un-x-passwd-file-as-the-user-database">Using a UN*X passwd file as the user database</a> for more information about doing this.</p> <p>To authenticate off the LDAP store (rather than using the passwords in the Roundup user database) you’d use the same python-ldap module inside an extension to the cgi interface. You’d do this by overriding the method called <tt class="docutils literal"><span class="pre">verifyPassword</span></tt> on the <tt class="docutils literal"><span class="pre">LoginAction</span></tt> class in your tracker’s <tt class="docutils literal"><span class="pre">extensions</span></tt> directory (see <a class="reference internal" href="#using-an-external-password-validation-source">using an external password validation source</a>). The method is implemented by default as:</p> <div class="highlight-python"><div class="highlight"><pre><span class="k">def</span> <span class="nf">verifyPassword</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">userid</span><span class="p">,</span> <span class="n">password</span><span class="p">):</span> <span class="sd">''' Verify the password that the user has supplied</span> <span class="sd"> '''</span> <span class="n">stored</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db</span><span class="o">.</span><span class="n">user</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">userid</span><span class="p">,</span> <span class="s">'password'</span><span class="p">)</span> <span class="k">if</span> <span class="n">password</span> <span class="o">==</span> <span class="n">stored</span><span class="p">:</span> <span class="k">return</span> <span class="mi">1</span> <span class="k">if</span> <span class="ow">not</span> <span class="n">password</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">stored</span><span class="p">:</span> <span class="k">return</span> <span class="mi">1</span> <span class="k">return</span> <span class="mi">0</span> </pre></div> </div> <p>So you could reimplement this as something like:</p> <div class="highlight-python"><div class="highlight"><pre><span class="k">def</span> <span class="nf">verifyPassword</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">userid</span><span class="p">,</span> <span class="n">password</span><span class="p">):</span> <span class="sd">''' Verify the password that the user has supplied</span> <span class="sd"> '''</span> <span class="c"># look up some unique LDAP information about the user</span> <span class="n">username</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db</span><span class="o">.</span><span class="n">user</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">userid</span><span class="p">,</span> <span class="s">'username'</span><span class="p">)</span> <span class="c"># now verify the password supplied against the LDAP store</span> </pre></div> </div> </div> </div> <div class="section" id="changes-to-tracker-behaviour"> <h3><a class="toc-backref" href="#id56">Changes to Tracker Behaviour</a></h3> <div class="section" id="preventing-spam"> <h4><a class="toc-backref" href="#id57">Preventing SPAM</a></h4> <p>The following detector code may be installed in your tracker’s <tt class="docutils literal"><span class="pre">detectors</span></tt> directory. It will block any messages being created that have HTML attachments (a very common vector for spam and phishing) and any messages that have more than 2 HTTP URLs in them. Just copy the following into <tt class="docutils literal"><span class="pre">detectors/anti_spam.py</span></tt> in your tracker:</p> <div class="highlight-python"><pre>from roundup.exceptions import Reject def reject_html(db, cl, nodeid, newvalues): if newvalues['type'] == 'text/html': raise Reject, 'not allowed' def reject_manylinks(db, cl, nodeid, newvalues): content = newvalues['content'] if content.count('http://') > 2: raise Reject, 'not allowed' def init(db): db.file.audit('create', reject_html) db.msg.audit('create', reject_manylinks)</pre> </div> <p>You may also wish to block image attachments if your tracker does not need that ability:</p> <div class="highlight-python"><div class="highlight"><pre><span class="k">if</span> <span class="n">newvalues</span><span class="p">[</span><span class="s">'type'</span><span class="p">]</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s">'image/'</span><span class="p">):</span> <span class="k">raise</span> <span class="n">Reject</span><span class="p">,</span> <span class="s">'not allowed'</span> </pre></div> </div> </div> <div class="section" id="stop-nosy-messages-going-to-people-on-vacation"> <h4><a class="toc-backref" href="#id58">Stop “nosy” messages going to people on vacation</a></h4> <p>When users go on vacation and set up vacation email bouncing, you’ll start to see a lot of messages come back through Roundup “Fred is on vacation”. Not very useful, and relatively easy to stop.</p> <ol class="arabic"> <li><p class="first">add a “vacation” flag to your users:</p> <div class="highlight-python"><div class="highlight"><pre><span class="n">user</span> <span class="o">=</span> <span class="n">Class</span><span class="p">(</span><span class="n">db</span><span class="p">,</span> <span class="s">"user"</span><span class="p">,</span> <span class="n">username</span><span class="o">=</span><span class="n">String</span><span class="p">(),</span> <span class="n">password</span><span class="o">=</span><span class="n">Password</span><span class="p">(),</span> <span class="n">address</span><span class="o">=</span><span class="n">String</span><span class="p">(),</span> <span class="n">realname</span><span class="o">=</span><span class="n">String</span><span class="p">(),</span> <span class="n">phone</span><span class="o">=</span><span class="n">String</span><span class="p">(),</span> <span class="n">organisation</span><span class="o">=</span><span class="n">String</span><span class="p">(),</span> <span class="n">alternate_addresses</span><span class="o">=</span><span class="n">String</span><span class="p">(),</span> <span class="n">roles</span><span class="o">=</span><span class="n">String</span><span class="p">(),</span> <span class="n">queries</span><span class="o">=</span><span class="n">Multilink</span><span class="p">(</span><span class="s">"query"</span><span class="p">),</span> <span class="n">vacation</span><span class="o">=</span><span class="n">Boolean</span><span class="p">())</span> </pre></div> </div> </li> <li><p class="first">So that users may edit the vacation flags, add something like the following to your <tt class="docutils literal"><span class="pre">user.item</span></tt> template:</p> <div class="highlight-python"><pre><tr> <th>On Vacation</th> <td tal:content="structure context/vacation/field">vacation</td> </tr></pre> </div> </li> <li><p class="first">edit your detector <tt class="docutils literal"><span class="pre">nosyreactor.py</span></tt> so that the <tt class="docutils literal"><span class="pre">nosyreaction()</span></tt> consists of:</p> <div class="highlight-python"><div class="highlight"><pre><span class="k">def</span> <span class="nf">nosyreaction</span><span class="p">(</span><span class="n">db</span><span class="p">,</span> <span class="n">cl</span><span class="p">,</span> <span class="n">nodeid</span><span class="p">,</span> <span class="n">oldvalues</span><span class="p">):</span> <span class="n">users</span> <span class="o">=</span> <span class="n">db</span><span class="o">.</span><span class="n">user</span> <span class="n">messages</span> <span class="o">=</span> <span class="n">db</span><span class="o">.</span><span class="n">msg</span> <span class="c"># send a copy of all new messages to the nosy list</span> <span class="k">for</span> <span class="n">msgid</span> <span class="ow">in</span> <span class="n">determineNewMessages</span><span class="p">(</span><span class="n">cl</span><span class="p">,</span> <span class="n">nodeid</span><span class="p">,</span> <span class="n">oldvalues</span><span class="p">):</span> <span class="k">try</span><span class="p">:</span> <span class="c"># figure the recipient ids</span> <span class="n">sendto</span> <span class="o">=</span> <span class="p">[]</span> <span class="n">seen_message</span> <span class="o">=</span> <span class="p">{}</span> <span class="n">recipients</span> <span class="o">=</span> <span class="n">messages</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">msgid</span><span class="p">,</span> <span class="s">'recipients'</span><span class="p">)</span> <span class="k">for</span> <span class="n">recipid</span> <span class="ow">in</span> <span class="n">messages</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">msgid</span><span class="p">,</span> <span class="s">'recipients'</span><span class="p">):</span> <span class="n">seen_message</span><span class="p">[</span><span class="n">recipid</span><span class="p">]</span> <span class="o">=</span> <span class="mi">1</span> <span class="c"># figure the author's id, and indicate they've received</span> <span class="c"># the message</span> <span class="n">authid</span> <span class="o">=</span> <span class="n">messages</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">msgid</span><span class="p">,</span> <span class="s">'author'</span><span class="p">)</span> <span class="c"># possibly send the message to the author, as long as</span> <span class="c"># they aren't anonymous</span> <span class="k">if</span> <span class="p">(</span><span class="n">db</span><span class="o">.</span><span class="n">config</span><span class="o">.</span><span class="n">MESSAGES_TO_AUTHOR</span> <span class="o">==</span> <span class="s">'yes'</span> <span class="ow">and</span> <span class="n">users</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">authid</span><span class="p">,</span> <span class="s">'username'</span><span class="p">)</span> <span class="o">!=</span> <span class="s">'anonymous'</span><span class="p">):</span> <span class="n">sendto</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">authid</span><span class="p">)</span> <span class="n">seen_message</span><span class="p">[</span><span class="n">authid</span><span class="p">]</span> <span class="o">=</span> <span class="mi">1</span> <span class="c"># now figure the nosy people who weren't recipients</span> <span class="n">nosy</span> <span class="o">=</span> <span class="n">cl</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">nodeid</span><span class="p">,</span> <span class="s">'nosy'</span><span class="p">)</span> <span class="k">for</span> <span class="n">nosyid</span> <span class="ow">in</span> <span class="n">nosy</span><span class="p">:</span> <span class="c"># Don't send nosy mail to the anonymous user (that</span> <span class="c"># user shouldn't appear in the nosy list, but just</span> <span class="c"># in case they do...)</span> <span class="k">if</span> <span class="n">users</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">nosyid</span><span class="p">,</span> <span class="s">'username'</span><span class="p">)</span> <span class="o">==</span> <span class="s">'anonymous'</span><span class="p">:</span> <span class="k">continue</span> <span class="c"># make sure they haven't seen the message already</span> <span class="k">if</span> <span class="ow">not</span> <span class="n">seen_message</span><span class="o">.</span><span class="n">has_key</span><span class="p">(</span><span class="n">nosyid</span><span class="p">):</span> <span class="c"># send it to them</span> <span class="n">sendto</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">nosyid</span><span class="p">)</span> <span class="n">recipients</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">nosyid</span><span class="p">)</span> <span class="c"># generate a change note</span> <span class="k">if</span> <span class="n">oldvalues</span><span class="p">:</span> <span class="n">note</span> <span class="o">=</span> <span class="n">cl</span><span class="o">.</span><span class="n">generateChangeNote</span><span class="p">(</span><span class="n">nodeid</span><span class="p">,</span> <span class="n">oldvalues</span><span class="p">)</span> <span class="k">else</span><span class="p">:</span> <span class="n">note</span> <span class="o">=</span> <span class="n">cl</span><span class="o">.</span><span class="n">generateCreateNote</span><span class="p">(</span><span class="n">nodeid</span><span class="p">)</span> <span class="c"># we have new recipients</span> <span class="k">if</span> <span class="n">sendto</span><span class="p">:</span> <span class="c"># filter out the people on vacation</span> <span class="n">sendto</span> <span class="o">=</span> <span class="p">[</span><span class="n">i</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">sendto</span> <span class="k">if</span> <span class="ow">not</span> <span class="n">users</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="s">'vacation'</span><span class="p">,</span> <span class="mi">0</span><span class="p">)]</span> <span class="c"># map userids to addresses</span> <span class="n">sendto</span> <span class="o">=</span> <span class="p">[</span><span class="n">users</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="s">'address'</span><span class="p">)</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">sendto</span><span class="p">]</span> <span class="c"># update the message's recipients list</span> <span class="n">messages</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="n">msgid</span><span class="p">,</span> <span class="n">recipients</span><span class="o">=</span><span class="n">recipients</span><span class="p">)</span> <span class="c"># send the message</span> <span class="n">cl</span><span class="o">.</span><span class="n">send_message</span><span class="p">(</span><span class="n">nodeid</span><span class="p">,</span> <span class="n">msgid</span><span class="p">,</span> <span class="n">note</span><span class="p">,</span> <span class="n">sendto</span><span class="p">)</span> <span class="k">except</span> <span class="n">roundupdb</span><span class="o">.</span><span class="n">MessageSendError</span><span class="p">,</span> <span class="n">message</span><span class="p">:</span> <span class="k">raise</span> <span class="n">roundupdb</span><span class="o">.</span><span class="n">DetectorError</span><span class="p">,</span> <span class="n">message</span> </pre></div> </div> <p>Note that this is the standard nosy reaction code, with the small addition of:</p> <div class="highlight-python"><div class="highlight"><pre><span class="c"># filter out the people on vacation</span> <span class="n">sendto</span> <span class="o">=</span> <span class="p">[</span><span class="n">i</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">sendto</span> <span class="k">if</span> <span class="ow">not</span> <span class="n">users</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="s">'vacation'</span><span class="p">,</span> <span class="mi">0</span><span class="p">)]</span> </pre></div> </div> <p>which filters out the users that have the vacation flag set to true.</p> </li> </ol> </div> <div class="section" id="adding-in-state-transition-control"> <h4><a class="toc-backref" href="#id59">Adding in state transition control</a></h4> <p>Sometimes tracker admins want to control the states to which users may move issues. You can do this by following these steps:</p> <ol class="arabic"> <li><p class="first">make “status” a required variable. This is achieved by adding the following to the top of the form in the <tt class="docutils literal"><span class="pre">issue.item.html</span></tt> template:</p> <div class="highlight-python"><pre><input type="hidden" name="@required" value="status"></pre> </div> <p>This will force users to select a status.</p> </li> <li><p class="first">add a Multilink property to the status class:</p> <div class="highlight-python"><pre>stat = Class(db, "status", ... , transitions=Multilink('status'), ...)</pre> </div> <p>and then edit the statuses already created, either:</p> <ol class="loweralpha simple"> <li>through the web using the class list -> status class editor, or</li> <li>using the <tt class="docutils literal"><span class="pre">roundup-admin</span></tt> “set” command.</li> </ol> </li> <li><p class="first">add an auditor module <tt class="docutils literal"><span class="pre">checktransition.py</span></tt> in your tracker’s <tt class="docutils literal"><span class="pre">detectors</span></tt> directory, for example:</p> <div class="highlight-python"><div class="highlight"><pre><span class="k">def</span> <span class="nf">checktransition</span><span class="p">(</span><span class="n">db</span><span class="p">,</span> <span class="n">cl</span><span class="p">,</span> <span class="n">nodeid</span><span class="p">,</span> <span class="n">newvalues</span><span class="p">):</span> <span class="sd">''' Check that the desired transition is valid for the "status"</span> <span class="sd"> property.</span> <span class="sd"> '''</span> <span class="k">if</span> <span class="ow">not</span> <span class="n">newvalues</span><span class="o">.</span><span class="n">has_key</span><span class="p">(</span><span class="s">'status'</span><span class="p">):</span> <span class="k">return</span> <span class="n">current</span> <span class="o">=</span> <span class="n">cl</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">nodeid</span><span class="p">,</span> <span class="s">'status'</span><span class="p">)</span> <span class="n">new</span> <span class="o">=</span> <span class="n">newvalues</span><span class="p">[</span><span class="s">'status'</span><span class="p">]</span> <span class="k">if</span> <span class="n">new</span> <span class="o">==</span> <span class="n">current</span><span class="p">:</span> <span class="k">return</span> <span class="n">ok</span> <span class="o">=</span> <span class="n">db</span><span class="o">.</span><span class="n">status</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">current</span><span class="p">,</span> <span class="s">'transitions'</span><span class="p">)</span> <span class="k">if</span> <span class="n">new</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">ok</span><span class="p">:</span> <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">,</span> <span class="s">'Status not allowed to move from "</span><span class="si">%s</span><span class="s">" to "</span><span class="si">%s</span><span class="s">"'</span><span class="o">%</span><span class="p">(</span> <span class="n">db</span><span class="o">.</span><span class="n">status</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">current</span><span class="p">,</span> <span class="s">'name'</span><span class="p">),</span> <span class="n">db</span><span class="o">.</span><span class="n">status</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">new</span><span class="p">,</span> <span class="s">'name'</span><span class="p">))</span> <span class="k">def</span> <span class="nf">init</span><span class="p">(</span><span class="n">db</span><span class="p">):</span> <span class="n">db</span><span class="o">.</span><span class="n">issue</span><span class="o">.</span><span class="n">audit</span><span class="p">(</span><span class="s">'set'</span><span class="p">,</span> <span class="n">checktransition</span><span class="p">)</span> </pre></div> </div> </li> <li><p class="first">in the <tt class="docutils literal"><span class="pre">issue.item.html</span></tt> template, change the status editing bit from:</p> <div class="highlight-python"><pre><th>Status</th> <td tal:content="structure context/status/menu">status</td></pre> </div> <p>to:</p> <div class="highlight-python"><pre><th>Status</th> <td> <select tal:condition="context/id" name="status"> <tal:block tal:define="ok context/status/transitions" tal:repeat="state db/status/list"> <option tal:condition="python:state.id in ok" tal:attributes=" value state/id; selected python:state.id == context.status.id" tal:content="state/name"></option> </tal:block> </select> <tal:block tal:condition="not:context/id" tal:replace="structure context/status/menu" /> </td></pre> </div> <p>which displays only the allowed status to transition to.</p> </li> </ol> </div> <div class="section" id="blocking-issues-that-depend-on-other-issues"> <h4><a class="toc-backref" href="#id60">Blocking issues that depend on other issues</a></h4> <p>We needed the ability to mark certain issues as “blockers” - that is, they can’t be resolved until another issue (the blocker) they rely on is resolved. To achieve this:</p> <ol class="arabic"> <li><p class="first">Create a new property on the <tt class="docutils literal"><span class="pre">issue</span></tt> class: <tt class="docutils literal"><span class="pre">blockers=Multilink("issue")</span></tt>. To do this, edit the definition of this class in your tracker’s <tt class="docutils literal"><span class="pre">schema.py</span></tt> file. Change this:</p> <div class="highlight-python"><div class="highlight"><pre><span class="n">issue</span> <span class="o">=</span> <span class="n">IssueClass</span><span class="p">(</span><span class="n">db</span><span class="p">,</span> <span class="s">"issue"</span><span class="p">,</span> <span class="n">assignedto</span><span class="o">=</span><span class="n">Link</span><span class="p">(</span><span class="s">"user"</span><span class="p">),</span> <span class="n">keyword</span><span class="o">=</span><span class="n">Multilink</span><span class="p">(</span><span class="s">"keyword"</span><span class="p">),</span> <span class="n">priority</span><span class="o">=</span><span class="n">Link</span><span class="p">(</span><span class="s">"priority"</span><span class="p">),</span> <span class="n">status</span><span class="o">=</span><span class="n">Link</span><span class="p">(</span><span class="s">"status"</span><span class="p">))</span> </pre></div> </div> <p>to this, adding the blockers entry:</p> <div class="highlight-python"><div class="highlight"><pre><span class="n">issue</span> <span class="o">=</span> <span class="n">IssueClass</span><span class="p">(</span><span class="n">db</span><span class="p">,</span> <span class="s">"issue"</span><span class="p">,</span> <span class="n">blockers</span><span class="o">=</span><span class="n">Multilink</span><span class="p">(</span><span class="s">"issue"</span><span class="p">),</span> <span class="n">assignedto</span><span class="o">=</span><span class="n">Link</span><span class="p">(</span><span class="s">"user"</span><span class="p">),</span> <span class="n">keyword</span><span class="o">=</span><span class="n">Multilink</span><span class="p">(</span><span class="s">"keyword"</span><span class="p">),</span> <span class="n">priority</span><span class="o">=</span><span class="n">Link</span><span class="p">(</span><span class="s">"priority"</span><span class="p">),</span> <span class="n">status</span><span class="o">=</span><span class="n">Link</span><span class="p">(</span><span class="s">"status"</span><span class="p">))</span> </pre></div> </div> </li> <li><p class="first">Add the new <tt class="docutils literal"><span class="pre">blockers</span></tt> property to the <tt class="docutils literal"><span class="pre">issue.item.html</span></tt> edit page, using something like:</p> <div class="highlight-python"><pre><th>Waiting On</th> <td> <span tal:replace="structure python:context.blockers.field(showid=1, size=20)" /> <span tal:replace="structure python:db.issue.classhelp('id,title', property='blockers')" /> <span tal:condition="context/blockers" tal:repeat="blk context/blockers"> <br>View: <a tal:attributes="href string:issue${blk/id}" tal:content="blk/id"></a> </span> </td></pre> </div> <p>You’ll need to fiddle with your item page layout to find an appropriate place to put it - I’ll leave that fun part up to you. Just make sure it appears in the first table, possibly somewhere near the “superseders” field.</p> </li> <li><p class="first">Create a new detector module (see below) which enforces the rules:</p> <ul class="simple"> <li>issues may not be resolved if they have blockers</li> <li>when a blocker is resolved, it’s removed from issues it blocks</li> </ul> <p>The contents of the detector should be something like this:</p> <div class="highlight-python"><div class="highlight"><pre><span class="k">def</span> <span class="nf">blockresolution</span><span class="p">(</span><span class="n">db</span><span class="p">,</span> <span class="n">cl</span><span class="p">,</span> <span class="n">nodeid</span><span class="p">,</span> <span class="n">newvalues</span><span class="p">):</span> <span class="sd">''' If the issue has blockers, don't allow it to be resolved.</span> <span class="sd"> '''</span> <span class="k">if</span> <span class="n">nodeid</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span> <span class="n">blockers</span> <span class="o">=</span> <span class="p">[]</span> <span class="k">else</span><span class="p">:</span> <span class="n">blockers</span> <span class="o">=</span> <span class="n">cl</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">nodeid</span><span class="p">,</span> <span class="s">'blockers'</span><span class="p">)</span> <span class="n">blockers</span> <span class="o">=</span> <span class="n">newvalues</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">'blockers'</span><span class="p">,</span> <span class="n">blockers</span><span class="p">)</span> <span class="c"># don't do anything if there's no blockers or the status hasn't</span> <span class="c"># changed</span> <span class="k">if</span> <span class="ow">not</span> <span class="n">blockers</span> <span class="ow">or</span> <span class="ow">not</span> <span class="n">newvalues</span><span class="o">.</span><span class="n">has_key</span><span class="p">(</span><span class="s">'status'</span><span class="p">):</span> <span class="k">return</span> <span class="c"># get the resolved state ID</span> <span class="n">resolved_id</span> <span class="o">=</span> <span class="n">db</span><span class="o">.</span><span class="n">status</span><span class="o">.</span><span class="n">lookup</span><span class="p">(</span><span class="s">'resolved'</span><span class="p">)</span> <span class="c"># format the info</span> <span class="n">u</span> <span class="o">=</span> <span class="n">db</span><span class="o">.</span><span class="n">config</span><span class="o">.</span><span class="n">TRACKER_WEB</span> <span class="n">s</span> <span class="o">=</span> <span class="s">', '</span><span class="o">.</span><span class="n">join</span><span class="p">([</span><span class="s">'<a href="</span><span class="si">%s</span><span class="s">issue</span><span class="si">%s</span><span class="s">"></span><span class="si">%s</span><span class="s"></a>'</span><span class="o">%</span><span class="p">(</span> <span class="n">u</span><span class="p">,</span><span class="nb">id</span><span class="p">,</span><span class="nb">id</span><span class="p">)</span> <span class="k">for</span> <span class="nb">id</span> <span class="ow">in</span> <span class="n">blockers</span><span class="p">])</span> <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">blockers</span><span class="p">)</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span> <span class="n">s</span> <span class="o">=</span> <span class="s">'issue </span><span class="si">%s</span><span class="s"> is'</span><span class="o">%</span><span class="n">s</span> <span class="k">else</span><span class="p">:</span> <span class="n">s</span> <span class="o">=</span> <span class="s">'issues </span><span class="si">%s</span><span class="s"> are'</span><span class="o">%</span><span class="n">s</span> <span class="c"># ok, see if we're trying to resolve</span> <span class="k">if</span> <span class="n">newvalues</span><span class="p">[</span><span class="s">'status'</span><span class="p">]</span> <span class="o">==</span> <span class="n">resolved_id</span><span class="p">:</span> <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">,</span> <span class="s">"This issue can't be resolved until </span><span class="si">%s</span><span class="s"> resolved."</span><span class="o">%</span><span class="n">s</span> <span class="k">def</span> <span class="nf">resolveblockers</span><span class="p">(</span><span class="n">db</span><span class="p">,</span> <span class="n">cl</span><span class="p">,</span> <span class="n">nodeid</span><span class="p">,</span> <span class="n">oldvalues</span><span class="p">):</span> <span class="sd">''' When we resolve an issue that's a blocker, remove it from the</span> <span class="sd"> blockers list of the issue(s) it blocks.</span> <span class="sd"> '''</span> <span class="n">newstatus</span> <span class="o">=</span> <span class="n">cl</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">nodeid</span><span class="p">,</span><span class="s">'status'</span><span class="p">)</span> <span class="c"># no change?</span> <span class="k">if</span> <span class="n">oldvalues</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">'status'</span><span class="p">,</span> <span class="bp">None</span><span class="p">)</span> <span class="o">==</span> <span class="n">newstatus</span><span class="p">:</span> <span class="k">return</span> <span class="n">resolved_id</span> <span class="o">=</span> <span class="n">db</span><span class="o">.</span><span class="n">status</span><span class="o">.</span><span class="n">lookup</span><span class="p">(</span><span class="s">'resolved'</span><span class="p">)</span> <span class="c"># interesting?</span> <span class="k">if</span> <span class="n">newstatus</span> <span class="o">!=</span> <span class="n">resolved_id</span><span class="p">:</span> <span class="k">return</span> <span class="c"># yes - find all the blocked issues, if any, and remove me from</span> <span class="c"># their blockers list</span> <span class="n">issues</span> <span class="o">=</span> <span class="n">cl</span><span class="o">.</span><span class="n">find</span><span class="p">(</span><span class="n">blockers</span><span class="o">=</span><span class="n">nodeid</span><span class="p">)</span> <span class="k">for</span> <span class="n">issueid</span> <span class="ow">in</span> <span class="n">issues</span><span class="p">:</span> <span class="n">blockers</span> <span class="o">=</span> <span class="n">cl</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">issueid</span><span class="p">,</span> <span class="s">'blockers'</span><span class="p">)</span> <span class="k">if</span> <span class="n">nodeid</span> <span class="ow">in</span> <span class="n">blockers</span><span class="p">:</span> <span class="n">blockers</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="n">nodeid</span><span class="p">)</span> <span class="n">cl</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="n">issueid</span><span class="p">,</span> <span class="n">blockers</span><span class="o">=</span><span class="n">blockers</span><span class="p">)</span> <span class="k">def</span> <span class="nf">init</span><span class="p">(</span><span class="n">db</span><span class="p">):</span> <span class="c"># might, in an obscure situation, happen in a create</span> <span class="n">db</span><span class="o">.</span><span class="n">issue</span><span class="o">.</span><span class="n">audit</span><span class="p">(</span><span class="s">'create'</span><span class="p">,</span> <span class="n">blockresolution</span><span class="p">)</span> <span class="n">db</span><span class="o">.</span><span class="n">issue</span><span class="o">.</span><span class="n">audit</span><span class="p">(</span><span class="s">'set'</span><span class="p">,</span> <span class="n">blockresolution</span><span class="p">)</span> <span class="c"># can only happen on a set</span> <span class="n">db</span><span class="o">.</span><span class="n">issue</span><span class="o">.</span><span class="n">react</span><span class="p">(</span><span class="s">'set'</span><span class="p">,</span> <span class="n">resolveblockers</span><span class="p">)</span> </pre></div> </div> <p>Put the above code in a file called “blockers.py” in your tracker’s “detectors” directory.</p> </li> <li><p class="first">Finally, and this is an optional step, modify the tracker web page URLs so they filter out issues with any blockers. You do this by adding an additional filter on “blockers” for the value “-1”. For example, the existing “Show All” link in the “page” template (in the tracker’s “html” directory) looks like this:</p> <div class="highlight-python"><pre><a href="#" tal:attributes="href python:request.indexargs_url('issue', { '@sort': '-activity', '@group': 'priority', '@filter': 'status', '@columns': columns_showall, '@search_text': '', 'status': status_notresolved, '@dispname': i18n.gettext('Show All'), })" i18n:translate="">Show All</a><br></pre> </div> <p>modify it to add the “blockers” info to the URL (note, both the “@filter” <em>and</em> “blockers” values must be specified):</p> <div class="highlight-python"><pre><a href="#" tal:attributes="href python:request.indexargs_url('issue', { '@sort': '-activity', '@group': 'priority', '@filter': 'status,blockers', '@columns': columns_showall, '@search_text': '', 'status': status_notresolved, 'blockers': '-1', '@dispname': i18n.gettext('Show All'), })" i18n:translate="">Show All</a><br></pre> </div> <p>The above examples are line-wrapped on the trailing & and should be unwrapped.</p> </li> </ol> <p>That’s it. You should now be able to set blockers on your issues. Note that if you want to know whether an issue has any other issues dependent on it (i.e. it’s in their blockers list) you can look at the journal history at the bottom of the issue page - look for a “link” event to another issue’s “blockers” property.</p> </div> <div class="section" id="add-users-to-the-nosy-list-based-on-the-keyword"> <h4><a class="toc-backref" href="#id61">Add users to the nosy list based on the keyword</a></h4> <p>Let’s say we need the ability to automatically add users to the nosy list based on the occurance of a keyword. Every user should be allowed to edit their own list of keywords for which they want to be added to the nosy list.</p> <p>Below, we’ll show that this change can be done with minimal understanding of the Roundup system, using only copy and paste.</p> <p>This requires three changes to the tracker: a change in the database to allow per-user recording of the lists of keywords for which he wants to be put on the nosy list, a change in the user view allowing them to edit this list of keywords, and addition of an auditor which updates the nosy list when a keyword is set.</p> <div class="section" id="adding-the-nosy-keyword-list"> <h5>Adding the nosy keyword list</h5> <p>The change to make in the database, is that for any user there should be a list of keywords for which he wants to be put on the nosy list. Adding a <tt class="docutils literal"><span class="pre">Multilink</span></tt> of <tt class="docutils literal"><span class="pre">keyword</span></tt> seems to fullfill this. As such, all that has to be done is to add a new field to the definition of <tt class="docutils literal"><span class="pre">user</span></tt> within the file <tt class="docutils literal"><span class="pre">schema.py</span></tt>. We will call this new field <tt class="docutils literal"><span class="pre">nosy_keywords</span></tt>, and the updated definition of user will be:</p> <div class="highlight-python"><div class="highlight"><pre><span class="n">user</span> <span class="o">=</span> <span class="n">Class</span><span class="p">(</span><span class="n">db</span><span class="p">,</span> <span class="s">"user"</span><span class="p">,</span> <span class="n">username</span><span class="o">=</span><span class="n">String</span><span class="p">(),</span> <span class="n">password</span><span class="o">=</span><span class="n">Password</span><span class="p">(),</span> <span class="n">address</span><span class="o">=</span><span class="n">String</span><span class="p">(),</span> <span class="n">realname</span><span class="o">=</span><span class="n">String</span><span class="p">(),</span> <span class="n">phone</span><span class="o">=</span><span class="n">String</span><span class="p">(),</span> <span class="n">organisation</span><span class="o">=</span><span class="n">String</span><span class="p">(),</span> <span class="n">alternate_addresses</span><span class="o">=</span><span class="n">String</span><span class="p">(),</span> <span class="n">queries</span><span class="o">=</span><span class="n">Multilink</span><span class="p">(</span><span class="s">'query'</span><span class="p">),</span> <span class="n">roles</span><span class="o">=</span><span class="n">String</span><span class="p">(),</span> <span class="n">timezone</span><span class="o">=</span><span class="n">String</span><span class="p">(),</span> <span class="n">nosy_keywords</span><span class="o">=</span><span class="n">Multilink</span><span class="p">(</span><span class="s">'keyword'</span><span class="p">))</span> </pre></div> </div> </div> <div class="section" id="changing-the-user-view-to-allow-changing-the-nosy-keyword-list"> <h5>Changing the user view to allow changing the nosy keyword list</h5> <p>We want any user to be able to change the list of keywords for which he will by default be added to the nosy list. We choose to add this to the user view, as is generated by the file <tt class="docutils literal"><span class="pre">html/user.item.html</span></tt>. We can easily see that the keyword field in the issue view has very similar editing requirements as our nosy keywords, both being lists of keywords. As such, we look for Keywords in <tt class="docutils literal"><span class="pre">issue.item.html</span></tt>, and extract the associated parts from there. We add this to <tt class="docutils literal"><span class="pre">user.item.html</span></tt> at the bottom of the list of viewed items (i.e. just below the ‘Alternate E-mail addresses’ in the classic template):</p> <div class="highlight-python"><pre><tr> <th>Nosy Keywords</th> <td> <span tal:replace="structure context/nosy_keywords/field" /> <span tal:replace="structure python:db.keyword.classhelp(property='nosy_keywords')" /> </td> </tr></pre> </div> </div> <div class="section" id="addition-of-an-auditor-to-update-the-nosy-list"> <h5>Addition of an auditor to update the nosy list</h5> <p>The more difficult part is the logic to add the users to the nosy list when required. We choose to perform this action whenever the keywords on an item are set (this includes the creation of items). Here we choose to start out with a copy of the <tt class="docutils literal"><span class="pre">detectors/nosyreaction.py</span></tt> detector, which we copy to the file <tt class="docutils literal"><span class="pre">detectors/nosy_keyword_reaction.py</span></tt>. This looks like a good start as it also adds users to the nosy list. A look through the code reveals that the <tt class="docutils literal"><span class="pre">nosyreaction</span></tt> function actually sends the e-mail. We don’t need this. Therefore, we can change the <tt class="docutils literal"><span class="pre">init</span></tt> function to:</p> <div class="highlight-python"><div class="highlight"><pre><span class="k">def</span> <span class="nf">init</span><span class="p">(</span><span class="n">db</span><span class="p">):</span> <span class="n">db</span><span class="o">.</span><span class="n">issue</span><span class="o">.</span><span class="n">audit</span><span class="p">(</span><span class="s">'create'</span><span class="p">,</span> <span class="n">update_kw_nosy</span><span class="p">)</span> <span class="n">db</span><span class="o">.</span><span class="n">issue</span><span class="o">.</span><span class="n">audit</span><span class="p">(</span><span class="s">'set'</span><span class="p">,</span> <span class="n">update_kw_nosy</span><span class="p">)</span> </pre></div> </div> <p>After that, we rename the <tt class="docutils literal"><span class="pre">updatenosy</span></tt> function to <tt class="docutils literal"><span class="pre">update_kw_nosy</span></tt>. The first two blocks of code in that function relate to setting <tt class="docutils literal"><span class="pre">current</span></tt> to a combination of the old and new nosy lists. This functionality is left in the new auditor. The following block of code, which handled adding the assignedto user(s) to the nosy list in <tt class="docutils literal"><span class="pre">updatenosy</span></tt>, should be replaced by a block of code to add the interested users to the nosy list. We choose here to loop over all new keywords, than looping over all users, and assign the user to the nosy list when the keyword occurs in the user’s <tt class="docutils literal"><span class="pre">nosy_keywords</span></tt>. The next part in <tt class="docutils literal"><span class="pre">updatenosy</span></tt> – adding the author and/or recipients of a message to the nosy list – is obviously not relevant here and is thus deleted from the new auditor. The last part, copying the new nosy list to <tt class="docutils literal"><span class="pre">newvalues</span></tt>, can stay as is. This results in the following function:</p> <div class="highlight-python"><div class="highlight"><pre><span class="k">def</span> <span class="nf">update_kw_nosy</span><span class="p">(</span><span class="n">db</span><span class="p">,</span> <span class="n">cl</span><span class="p">,</span> <span class="n">nodeid</span><span class="p">,</span> <span class="n">newvalues</span><span class="p">):</span> <span class="sd">'''Update the nosy list for changes to the keywords</span> <span class="sd"> '''</span> <span class="c"># nodeid will be None if this is a new node</span> <span class="n">current</span> <span class="o">=</span> <span class="p">{}</span> <span class="k">if</span> <span class="n">nodeid</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span> <span class="n">ok</span> <span class="o">=</span> <span class="p">(</span><span class="s">'new'</span><span class="p">,</span> <span class="s">'yes'</span><span class="p">)</span> <span class="k">else</span><span class="p">:</span> <span class="n">ok</span> <span class="o">=</span> <span class="p">(</span><span class="s">'yes'</span><span class="p">,)</span> <span class="c"># old node, get the current values from the node if they haven't</span> <span class="c"># changed</span> <span class="k">if</span> <span class="ow">not</span> <span class="n">newvalues</span><span class="o">.</span><span class="n">has_key</span><span class="p">(</span><span class="s">'nosy'</span><span class="p">):</span> <span class="n">nosy</span> <span class="o">=</span> <span class="n">cl</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">nodeid</span><span class="p">,</span> <span class="s">'nosy'</span><span class="p">)</span> <span class="k">for</span> <span class="n">value</span> <span class="ow">in</span> <span class="n">nosy</span><span class="p">:</span> <span class="k">if</span> <span class="ow">not</span> <span class="n">current</span><span class="o">.</span><span class="n">has_key</span><span class="p">(</span><span class="n">value</span><span class="p">):</span> <span class="n">current</span><span class="p">[</span><span class="n">value</span><span class="p">]</span> <span class="o">=</span> <span class="mi">1</span> <span class="c"># if the nosy list changed in this transaction, init from the new value</span> <span class="k">if</span> <span class="n">newvalues</span><span class="o">.</span><span class="n">has_key</span><span class="p">(</span><span class="s">'nosy'</span><span class="p">):</span> <span class="n">nosy</span> <span class="o">=</span> <span class="n">newvalues</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">'nosy'</span><span class="p">,</span> <span class="p">[])</span> <span class="k">for</span> <span class="n">value</span> <span class="ow">in</span> <span class="n">nosy</span><span class="p">:</span> <span class="k">if</span> <span class="ow">not</span> <span class="n">db</span><span class="o">.</span><span class="n">hasnode</span><span class="p">(</span><span class="s">'user'</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span> <span class="k">continue</span> <span class="k">if</span> <span class="ow">not</span> <span class="n">current</span><span class="o">.</span><span class="n">has_key</span><span class="p">(</span><span class="n">value</span><span class="p">):</span> <span class="n">current</span><span class="p">[</span><span class="n">value</span><span class="p">]</span> <span class="o">=</span> <span class="mi">1</span> <span class="c"># add users with keyword in nosy_keywords to the nosy list</span> <span class="k">if</span> <span class="n">newvalues</span><span class="o">.</span><span class="n">has_key</span><span class="p">(</span><span class="s">'keyword'</span><span class="p">)</span> <span class="ow">and</span> <span class="n">newvalues</span><span class="p">[</span><span class="s">'keyword'</span><span class="p">]</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span> <span class="n">keyword_ids</span> <span class="o">=</span> <span class="n">newvalues</span><span class="p">[</span><span class="s">'keyword'</span><span class="p">]</span> <span class="k">for</span> <span class="n">keyword</span> <span class="ow">in</span> <span class="n">keyword_ids</span><span class="p">:</span> <span class="c"># loop over all users,</span> <span class="c"># and assign user to nosy when keyword in nosy_keywords</span> <span class="k">for</span> <span class="n">user_id</span> <span class="ow">in</span> <span class="n">db</span><span class="o">.</span><span class="n">user</span><span class="o">.</span><span class="n">list</span><span class="p">():</span> <span class="n">nosy_kw</span> <span class="o">=</span> <span class="n">db</span><span class="o">.</span><span class="n">user</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">user_id</span><span class="p">,</span> <span class="s">"nosy_keywords"</span><span class="p">)</span> <span class="n">found</span> <span class="o">=</span> <span class="mi">0</span> <span class="k">for</span> <span class="n">kw</span> <span class="ow">in</span> <span class="n">nosy_kw</span><span class="p">:</span> <span class="k">if</span> <span class="n">kw</span> <span class="o">==</span> <span class="n">keyword</span><span class="p">:</span> <span class="n">found</span> <span class="o">=</span> <span class="mi">1</span> <span class="k">if</span> <span class="n">found</span><span class="p">:</span> <span class="n">current</span><span class="p">[</span><span class="n">user_id</span><span class="p">]</span> <span class="o">=</span> <span class="mi">1</span> <span class="c"># that's it, save off the new nosy list</span> <span class="n">newvalues</span><span class="p">[</span><span class="s">'nosy'</span><span class="p">]</span> <span class="o">=</span> <span class="n">current</span><span class="o">.</span><span class="n">keys</span><span class="p">()</span> </pre></div> </div> <p>These two function are the only ones needed in the file.</p> <p>TODO: update this example to use the <tt class="docutils literal"><span class="pre">find()</span></tt> Class method.</p> </div> <div class="section" id="caveats"> <h5>Caveats</h5> <p>A few problems with the design here can be noted:</p> <dl class="docutils"> <dt>Multiple additions</dt> <dd><p class="first">When a user, after automatic selection, is manually removed from the nosy list, he is added to the nosy list again when the keyword list of the issue is updated. A better design might be to only check which keywords are new compared to the old list of keywords, and only add users when they have indicated interest on a new keyword.</p> <p class="last">The code could also be changed to only trigger on the <tt class="docutils literal"><span class="pre">create()</span></tt> event, rather than also on the <tt class="docutils literal"><span class="pre">set()</span></tt> event, thus only setting the nosy list when the issue is created.</p> </dd> <dt>Scalability</dt> <dd>In the auditor, there is a loop over all users. For a site with only few users this will pose no serious problem; however, with many users this will be a serious performance bottleneck. A way out would be to link from the keywords to the users who selected these keywords as nosy keywords. This will eliminate the loop over all users.</dd> </dl> </div> </div> </div> <div class="section" id="changes-to-security-and-permissions"> <h3><a class="toc-backref" href="#id62">Changes to Security and Permissions</a></h3> <div class="section" id="restricting-the-list-of-users-that-are-assignable-to-a-task"> <h4><a class="toc-backref" href="#id63">Restricting the list of users that are assignable to a task</a></h4> <ol class="arabic"> <li><p class="first">In your tracker’s <tt class="docutils literal"><span class="pre">schema.py</span></tt>, create a new Role, say “Developer”:</p> <div class="highlight-python"><div class="highlight"><pre><span class="n">db</span><span class="o">.</span><span class="n">security</span><span class="o">.</span><span class="n">addRole</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s">'Developer'</span><span class="p">,</span> <span class="n">description</span><span class="o">=</span><span class="s">'A developer'</span><span class="p">)</span> </pre></div> </div> </li> <li><p class="first">Just after that, create a new Permission, say “Fixer”, specific to “issue”:</p> <div class="highlight-python"><div class="highlight"><pre><span class="n">p</span> <span class="o">=</span> <span class="n">db</span><span class="o">.</span><span class="n">security</span><span class="o">.</span><span class="n">addPermission</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s">'Fixer'</span><span class="p">,</span> <span class="n">klass</span><span class="o">=</span><span class="s">'issue'</span><span class="p">,</span> <span class="n">description</span><span class="o">=</span><span class="s">'User is allowed to be assigned to fix issues'</span><span class="p">)</span> </pre></div> </div> </li> <li><p class="first">Then assign the new Permission to your “Developer” Role:</p> <div class="highlight-python"><div class="highlight"><pre><span class="n">db</span><span class="o">.</span><span class="n">security</span><span class="o">.</span><span class="n">addPermissionToRole</span><span class="p">(</span><span class="s">'Developer'</span><span class="p">,</span> <span class="n">p</span><span class="p">)</span> </pre></div> </div> </li> <li><p class="first">In the issue item edit page (<tt class="docutils literal"><span class="pre">html/issue.item.html</span></tt> in your tracker directory), use the new Permission in restricting the “assignedto” list:</p> <div class="highlight-python"><pre><select name="assignedto"> <option value="-1">- no selection -</option> <tal:block tal:repeat="user db/user/list"> <option tal:condition="python:user.hasPermission( 'Fixer', context._classname)" tal:attributes=" value user/id; selected python:user.id == context.assignedto" tal:content="user/realname"></option> </tal:block> </select></pre> </div> </li> </ol> <p>For extra security, you may wish to setup an auditor to enforce the Permission requirement (install this as <tt class="docutils literal"><span class="pre">assignedtoFixer.py</span></tt> in your tracker <tt class="docutils literal"><span class="pre">detectors</span></tt> directory):</p> <div class="highlight-python"><div class="highlight"><pre><span class="k">def</span> <span class="nf">assignedtoMustBeFixer</span><span class="p">(</span><span class="n">db</span><span class="p">,</span> <span class="n">cl</span><span class="p">,</span> <span class="n">nodeid</span><span class="p">,</span> <span class="n">newvalues</span><span class="p">):</span> <span class="sd">''' Ensure the assignedto value in newvalues is used with the</span> <span class="sd"> Fixer Permission</span> <span class="sd"> '''</span> <span class="k">if</span> <span class="ow">not</span> <span class="n">newvalues</span><span class="o">.</span><span class="n">has_key</span><span class="p">(</span><span class="s">'assignedto'</span><span class="p">):</span> <span class="c"># don't care</span> <span class="k">return</span> <span class="c"># get the userid</span> <span class="n">userid</span> <span class="o">=</span> <span class="n">newvalues</span><span class="p">[</span><span class="s">'assignedto'</span><span class="p">]</span> <span class="k">if</span> <span class="ow">not</span> <span class="n">db</span><span class="o">.</span><span class="n">security</span><span class="o">.</span><span class="n">hasPermission</span><span class="p">(</span><span class="s">'Fixer'</span><span class="p">,</span> <span class="n">userid</span><span class="p">,</span> <span class="n">cl</span><span class="o">.</span><span class="n">classname</span><span class="p">):</span> <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">,</span> <span class="s">'You do not have permission to edit </span><span class="si">%s</span><span class="s">'</span><span class="o">%</span><span class="n">cl</span><span class="o">.</span><span class="n">classname</span> <span class="k">def</span> <span class="nf">init</span><span class="p">(</span><span class="n">db</span><span class="p">):</span> <span class="n">db</span><span class="o">.</span><span class="n">issue</span><span class="o">.</span><span class="n">audit</span><span class="p">(</span><span class="s">'set'</span><span class="p">,</span> <span class="n">assignedtoMustBeFixer</span><span class="p">)</span> <span class="n">db</span><span class="o">.</span><span class="n">issue</span><span class="o">.</span><span class="n">audit</span><span class="p">(</span><span class="s">'create'</span><span class="p">,</span> <span class="n">assignedtoMustBeFixer</span><span class="p">)</span> </pre></div> </div> <p>So now, if an edit action attempts to set “assignedto” to a user that doesn’t have the “Fixer” Permission, the error will be raised.</p> </div> <div class="section" id="users-may-only-edit-their-issues"> <h4><a class="toc-backref" href="#id64">Users may only edit their issues</a></h4> <p>In this case, users registering themselves are granted Provisional access, meaning they have access to edit the issues they submit, but not others. We create a new Role called “Provisional User” which is granted to newly-registered users, and has limited access. One of the Permissions they have is the new “Edit Own” on issues (regular users have “Edit”.)</p> <p>First up, we create the new Role and Permission structure in <tt class="docutils literal"><span class="pre">schema.py</span></tt>:</p> <div class="highlight-python"><div class="highlight"><pre><span class="c">#</span> <span class="c"># New users not approved by the admin</span> <span class="c">#</span> <span class="n">db</span><span class="o">.</span><span class="n">security</span><span class="o">.</span><span class="n">addRole</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s">'Provisional User'</span><span class="p">,</span> <span class="n">description</span><span class="o">=</span><span class="s">'New user registered via web or email'</span><span class="p">)</span> <span class="c"># These users need to be able to view and create issues but only edit</span> <span class="c"># and view their own</span> <span class="n">db</span><span class="o">.</span><span class="n">security</span><span class="o">.</span><span class="n">addPermissionToRole</span><span class="p">(</span><span class="s">'Provisional User'</span><span class="p">,</span> <span class="s">'Create'</span><span class="p">,</span> <span class="s">'issue'</span><span class="p">)</span> <span class="k">def</span> <span class="nf">own_issue</span><span class="p">(</span><span class="n">db</span><span class="p">,</span> <span class="n">userid</span><span class="p">,</span> <span class="n">itemid</span><span class="p">):</span> <span class="sd">'''Determine whether the userid matches the creator of the issue.'''</span> <span class="k">return</span> <span class="n">userid</span> <span class="o">==</span> <span class="n">db</span><span class="o">.</span><span class="n">issue</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">itemid</span><span class="p">,</span> <span class="s">'creator'</span><span class="p">)</span> <span class="n">p</span> <span class="o">=</span> <span class="n">db</span><span class="o">.</span><span class="n">security</span><span class="o">.</span><span class="n">addPermission</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s">'Edit'</span><span class="p">,</span> <span class="n">klass</span><span class="o">=</span><span class="s">'issue'</span><span class="p">,</span> <span class="n">check</span><span class="o">=</span><span class="n">own_issue</span><span class="p">,</span> <span class="n">description</span><span class="o">=</span><span class="s">'Can only edit own issues'</span><span class="p">)</span> <span class="n">db</span><span class="o">.</span><span class="n">security</span><span class="o">.</span><span class="n">addPermissionToRole</span><span class="p">(</span><span class="s">'Provisional User'</span><span class="p">,</span> <span class="n">p</span><span class="p">)</span> <span class="n">p</span> <span class="o">=</span> <span class="n">db</span><span class="o">.</span><span class="n">security</span><span class="o">.</span><span class="n">addPermission</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s">'View'</span><span class="p">,</span> <span class="n">klass</span><span class="o">=</span><span class="s">'issue'</span><span class="p">,</span> <span class="n">check</span><span class="o">=</span><span class="n">own_issue</span><span class="p">,</span> <span class="n">description</span><span class="o">=</span><span class="s">'Can only view own issues'</span><span class="p">)</span> <span class="n">db</span><span class="o">.</span><span class="n">security</span><span class="o">.</span><span class="n">addPermissionToRole</span><span class="p">(</span><span class="s">'Provisional User'</span><span class="p">,</span> <span class="n">p</span><span class="p">)</span> <span class="c"># Assign the Permissions for issue-related classes</span> <span class="k">for</span> <span class="n">cl</span> <span class="ow">in</span> <span class="s">'file'</span><span class="p">,</span> <span class="s">'msg'</span><span class="p">,</span> <span class="s">'query'</span><span class="p">,</span> <span class="s">'keyword'</span><span class="p">:</span> <span class="n">db</span><span class="o">.</span><span class="n">security</span><span class="o">.</span><span class="n">addPermissionToRole</span><span class="p">(</span><span class="s">'Provisional User'</span><span class="p">,</span> <span class="s">'View'</span><span class="p">,</span> <span class="n">cl</span><span class="p">)</span> <span class="n">db</span><span class="o">.</span><span class="n">security</span><span class="o">.</span><span class="n">addPermissionToRole</span><span class="p">(</span><span class="s">'Provisional User'</span><span class="p">,</span> <span class="s">'Edit'</span><span class="p">,</span> <span class="n">cl</span><span class="p">)</span> <span class="n">db</span><span class="o">.</span><span class="n">security</span><span class="o">.</span><span class="n">addPermissionToRole</span><span class="p">(</span><span class="s">'Provisional User'</span><span class="p">,</span> <span class="s">'Create'</span><span class="p">,</span> <span class="n">cl</span><span class="p">)</span> <span class="k">for</span> <span class="n">cl</span> <span class="ow">in</span> <span class="s">'priority'</span><span class="p">,</span> <span class="s">'status'</span><span class="p">:</span> <span class="n">db</span><span class="o">.</span><span class="n">security</span><span class="o">.</span><span class="n">addPermissionToRole</span><span class="p">(</span><span class="s">'Provisional User'</span><span class="p">,</span> <span class="s">'View'</span><span class="p">,</span> <span class="n">cl</span><span class="p">)</span> <span class="c"># and give the new users access to the web and email interface</span> <span class="n">db</span><span class="o">.</span><span class="n">security</span><span class="o">.</span><span class="n">addPermissionToRole</span><span class="p">(</span><span class="s">'Provisional User'</span><span class="p">,</span> <span class="s">'Web Access'</span><span class="p">)</span> <span class="n">db</span><span class="o">.</span><span class="n">security</span><span class="o">.</span><span class="n">addPermissionToRole</span><span class="p">(</span><span class="s">'Provisional User'</span><span class="p">,</span> <span class="s">'Email Access'</span><span class="p">)</span> <span class="c"># make sure they can view & edit their own user record</span> <span class="k">def</span> <span class="nf">own_record</span><span class="p">(</span><span class="n">db</span><span class="p">,</span> <span class="n">userid</span><span class="p">,</span> <span class="n">itemid</span><span class="p">):</span> <span class="sd">'''Determine whether the userid matches the item being accessed.'''</span> <span class="k">return</span> <span class="n">userid</span> <span class="o">==</span> <span class="n">itemid</span> <span class="n">p</span> <span class="o">=</span> <span class="n">db</span><span class="o">.</span><span class="n">security</span><span class="o">.</span><span class="n">addPermission</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s">'View'</span><span class="p">,</span> <span class="n">klass</span><span class="o">=</span><span class="s">'user'</span><span class="p">,</span> <span class="n">check</span><span class="o">=</span><span class="n">own_record</span><span class="p">,</span> <span class="n">description</span><span class="o">=</span><span class="s">"User is allowed to view their own user details"</span><span class="p">)</span> <span class="n">db</span><span class="o">.</span><span class="n">security</span><span class="o">.</span><span class="n">addPermissionToRole</span><span class="p">(</span><span class="s">'Provisional User'</span><span class="p">,</span> <span class="n">p</span><span class="p">)</span> <span class="n">p</span> <span class="o">=</span> <span class="n">db</span><span class="o">.</span><span class="n">security</span><span class="o">.</span><span class="n">addPermission</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s">'Edit'</span><span class="p">,</span> <span class="n">klass</span><span class="o">=</span><span class="s">'user'</span><span class="p">,</span> <span class="n">check</span><span class="o">=</span><span class="n">own_record</span><span class="p">,</span> <span class="n">description</span><span class="o">=</span><span class="s">"User is allowed to edit their own user details"</span><span class="p">)</span> <span class="n">db</span><span class="o">.</span><span class="n">security</span><span class="o">.</span><span class="n">addPermissionToRole</span><span class="p">(</span><span class="s">'Provisional User'</span><span class="p">,</span> <span class="n">p</span><span class="p">)</span> </pre></div> </div> <p>Then, in <tt class="docutils literal"><span class="pre">config.ini</span></tt>, we change the Role assigned to newly-registered users, replacing the existing <tt class="docutils literal"><span class="pre">'User'</span></tt> values:</p> <div class="highlight-python"><div class="highlight"><pre><span class="p">[</span><span class="n">main</span><span class="p">]</span> <span class="o">...</span> <span class="n">new_web_user_roles</span> <span class="o">=</span> <span class="s">'Provisional User'</span> <span class="n">new_email_user_roles</span> <span class="o">=</span> <span class="s">'Provisional User'</span> </pre></div> </div> </div> <div class="section" id="all-users-may-only-view-and-edit-issues-files-and-messages-they-create"> <h4><a class="toc-backref" href="#id65">All users may only view and edit issues, files and messages they create</a></h4> <p>Replace the standard “classic” tracker View and Edit Permission assignments for the “issue”, “file” and “msg” classes with the following:</p> <div class="highlight-python"><div class="highlight"><pre><span class="k">def</span> <span class="nf">checker</span><span class="p">(</span><span class="n">klass</span><span class="p">):</span> <span class="k">def</span> <span class="nf">check</span><span class="p">(</span><span class="n">db</span><span class="p">,</span> <span class="n">userid</span><span class="p">,</span> <span class="n">itemid</span><span class="p">,</span> <span class="n">klass</span><span class="o">=</span><span class="n">klass</span><span class="p">):</span> <span class="k">return</span> <span class="n">db</span><span class="o">.</span><span class="n">getclass</span><span class="p">(</span><span class="n">klass</span><span class="p">)</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">itemid</span><span class="p">,</span> <span class="s">'creator'</span><span class="p">)</span> <span class="o">==</span> <span class="n">userid</span> <span class="k">return</span> <span class="n">check</span> <span class="k">for</span> <span class="n">cl</span> <span class="ow">in</span> <span class="s">'issue'</span><span class="p">,</span> <span class="s">'file'</span><span class="p">,</span> <span class="s">'msg'</span><span class="p">:</span> <span class="n">p</span> <span class="o">=</span> <span class="n">db</span><span class="o">.</span><span class="n">security</span><span class="o">.</span><span class="n">addPermission</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s">'View'</span><span class="p">,</span> <span class="n">klass</span><span class="o">=</span><span class="n">cl</span><span class="p">,</span> <span class="n">check</span><span class="o">=</span><span class="n">checker</span><span class="p">(</span><span class="n">cl</span><span class="p">))</span> <span class="n">db</span><span class="o">.</span><span class="n">security</span><span class="o">.</span><span class="n">addPermissionToRole</span><span class="p">(</span><span class="s">'User'</span><span class="p">,</span> <span class="n">p</span><span class="p">)</span> <span class="n">p</span> <span class="o">=</span> <span class="n">db</span><span class="o">.</span><span class="n">security</span><span class="o">.</span><span class="n">addPermission</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s">'Edit'</span><span class="p">,</span> <span class="n">klass</span><span class="o">=</span><span class="n">cl</span><span class="p">,</span> <span class="n">check</span><span class="o">=</span><span class="n">checker</span><span class="p">(</span><span class="n">cl</span><span class="p">))</span> <span class="n">db</span><span class="o">.</span><span class="n">security</span><span class="o">.</span><span class="n">addPermissionToRole</span><span class="p">(</span><span class="s">'User'</span><span class="p">,</span> <span class="n">p</span><span class="p">)</span> <span class="n">db</span><span class="o">.</span><span class="n">security</span><span class="o">.</span><span class="n">addPermissionToRole</span><span class="p">(</span><span class="s">'User'</span><span class="p">,</span> <span class="s">'Create'</span><span class="p">,</span> <span class="n">cl</span><span class="p">)</span> </pre></div> </div> </div> <div class="section" id="moderating-user-registration"> <h4><a class="toc-backref" href="#id66">Moderating user registration</a></h4> <p>You could set up new-user moderation in a public tracker by:</p> <ol class="arabic simple"> <li>creating a new highly-restricted user role “Pending”,</li> <li>set the config new_web_user_roles and/or new_email_user_roles to that role,</li> <li>have an auditor that emails you when new users are created with that role using roundup.mailer</li> <li>edit the role to “User” for valid users.</li> </ol> <p>Some simple javascript might help in the last step. If you have high volume you could search for all currently-Pending users and do a bulk edit of all their roles at once (again probably with some simple javascript help).</p> </div> </div> <div class="section" id="changes-to-the-web-user-interface"> <h3><a class="toc-backref" href="#id67">Changes to the Web User Interface</a></h3> <div class="section" id="adding-action-links-to-the-index-page"> <h4><a class="toc-backref" href="#id68">Adding action links to the index page</a></h4> <p>Add a column to the <tt class="docutils literal"><span class="pre">item.index.html</span></tt> template.</p> <p>Resolving the issue:</p> <div class="highlight-python"><pre><a tal:attributes="href string:issue${i/id}?:status=resolved&:action=edit">resolve</a></pre> </div> <p>“Take” the issue:</p> <div class="highlight-python"><pre><a tal:attributes="href string:issue${i/id}?:assignedto=${request/user/id}&:action=edit">take</a></pre> </div> <p>... and so on.</p> </div> <div class="section" id="colouring-the-rows-in-the-issue-index-according-to-priority"> <h4><a class="toc-backref" href="#id69">Colouring the rows in the issue index according to priority</a></h4> <p>A simple <tt class="docutils literal"><span class="pre">tal:attributes</span></tt> statement will do the bulk of the work here. In the <tt class="docutils literal"><span class="pre">issue.index.html</span></tt> template, add this to the <tt class="docutils literal"><span class="pre"><tr></span></tt> that displays the rows of data:</p> <div class="highlight-python"><pre><tr tal:attributes="class string:priority-${i/priority/plain}"></pre> </div> <p>and then in your stylesheet (<tt class="docutils literal"><span class="pre">style.css</span></tt>) specify the colouring for the different priorities, as follows:</p> <div class="highlight-python"><pre>tr.priority-critical td { background-color: red; } tr.priority-urgent td { background-color: orange; }</pre> </div> <p>and so on, with far less offensive colours :)</p> </div> <div class="section" id="editing-multiple-items-in-an-index-view"> <h4><a class="toc-backref" href="#id70">Editing multiple items in an index view</a></h4> <p>To edit the status of all items in the item index view, edit the <tt class="docutils literal"><span class="pre">issue.item.html</span></tt>:</p> <ol class="arabic"> <li><p class="first">add a form around the listing table (separate from the existing index-page form), so at the top it reads:</p> <div class="highlight-python"><pre><form method="POST" tal:attributes="action request/classname"> <table class="list"></pre> </div> <p>and at the bottom of that table:</p> <div class="highlight-python"><pre> </table> </form</pre> </div> <p>making sure you match the <tt class="docutils literal"><span class="pre"></table></span></tt> from the list table, not the navigation table or the subsequent form table.</p> </li> <li><p class="first">in the display for the issue property, change:</p> <div class="highlight-python"><pre><td tal:condition="request/show/status" tal:content="python:i.status.plain() or default">&nbsp;</td></pre> </div> <p>to:</p> <div class="highlight-python"><pre><td tal:condition="request/show/status" tal:content="structure i/status/field">&nbsp;</td></pre> </div> <p>this will result in an edit field for the status property.</p> </li> <li><p class="first">after the <tt class="docutils literal"><span class="pre">tal:block</span></tt> which lists the index items (marked by <tt class="docutils literal"><span class="pre">tal:repeat="i</span> <span class="pre">batch"</span></tt>) add a new table row:</p> <div class="highlight-python"><pre><tr> <td tal:attributes="colspan python:len(request.columns)"> <input type="submit" value=" Save Changes "> <input type="hidden" name="@action" value="edit"> <tal:block replace="structure request/indexargs_form" /> </td> </tr></pre> </div> <p>which gives us a submit button, indicates that we are performing an edit on any changed statuses. The final <tt class="docutils literal"><span class="pre">tal:block</span></tt> will make sure that the current index view parameters (filtering, columns, etc) will be used in rendering the next page (the results of the editing).</p> </li> </ol> </div> <div class="section" id="displaying-only-message-summaries-in-the-issue-display"> <h4><a class="toc-backref" href="#id71">Displaying only message summaries in the issue display</a></h4> <p>Alter the <tt class="docutils literal"><span class="pre">issue.item</span></tt> template section for messages to:</p> <div class="highlight-python"><pre><table class="messages" tal:condition="context/messages"> <tr><th colspan="5" class="header">Messages</th></tr> <tr tal:repeat="msg context/messages"> <td><a tal:attributes="href string:msg${msg/id}" tal:content="string:msg${msg/id}"></a></td> <td tal:content="msg/author">author</td> <td class="date" tal:content="msg/date/pretty">date</td> <td tal:content="msg/summary">summary</td> <td> <a tal:attributes="href string:?@remove@messages=${msg/id}&@action=edit"> remove</a> </td> </tr> </table></pre> </div> </div> <div class="section" id="enabling-display-of-either-message-summaries-or-the-entire-messages"> <h4><a class="toc-backref" href="#id72">Enabling display of either message summaries or the entire messages</a></h4> <p>This is pretty simple - all we need to do is copy the code from the example <a class="reference internal" href="#displaying-only-message-summaries-in-the-issue-display">displaying only message summaries in the issue display</a> into our template alongside the summary display, and then introduce a switch that shows either the one or the other. We’ll use a new form variable, <tt class="docutils literal"><span class="pre">@whole_messages</span></tt> to achieve this:</p> <div class="highlight-python"><pre><table class="messages" tal:condition="context/messages"> <tal:block tal:condition="not:request/form/@whole_messages/value | python:0"> <tr><th colspan="3" class="header">Messages</th> <th colspan="2" class="header"> <a href="?@whole_messages=yes">show entire messages</a> </th> </tr> <tr tal:repeat="msg context/messages"> <td><a tal:attributes="href string:msg${msg/id}" tal:content="string:msg${msg/id}"></a></td> <td tal:content="msg/author">author</td> <td class="date" tal:content="msg/date/pretty">date</td> <td tal:content="msg/summary">summary</td> <td> <a tal:attributes="href string:?@remove@messages=${msg/id}&@action=edit">remove</a> </td> </tr> </tal:block> <tal:block tal:condition="request/form/@whole_messages/value | python:0"> <tr><th colspan="2" class="header">Messages</th> <th class="header"> <a href="?@whole_messages=">show only summaries</a> </th> </tr> <tal:block tal:repeat="msg context/messages"> <tr> <th tal:content="msg/author">author</th> <th class="date" tal:content="msg/date/pretty">date</th> <th style="text-align: right"> (<a tal:attributes="href string:?@remove@messages=${msg/id}&@action=edit">remove</a>) </th> </tr> <tr><td colspan="3" tal:content="msg/content"></td></tr> </tal:block> </tal:block> </table></pre> </div> </div> <div class="section" id="setting-up-a-wizard-or-druid-for-controlled-adding-of-issues"> <h4><a class="toc-backref" href="#id73">Setting up a “wizard” (or “druid”) for controlled adding of issues</a></h4> <ol class="arabic"> <li><p class="first">Set up the page templates you wish to use for data input. My wizard is going to be a two-step process: first figuring out what category of issue the user is submitting, and then getting details specific to that category. The first page includes a table of help, explaining what the category names mean, and then the core of the form:</p> <div class="highlight-python"><pre><form method="POST" onSubmit="return submit_once()" enctype="multipart/form-data"> <input type="hidden" name="@template" value="add_page1"> <input type="hidden" name="@action" value="page1_submit"> <strong>Category:</strong> <tal:block tal:replace="structure context/category/menu" /> <input type="submit" value="Continue"> </form></pre> </div> <p>The next page has the usual issue entry information, with the addition of the following form fragments:</p> <div class="highlight-python"><pre><form method="POST" onSubmit="return submit_once()" enctype="multipart/form-data" tal:condition="context/is_edit_ok" tal:define="cat request/form/category/value"> <input type="hidden" name="@template" value="add_page2"> <input type="hidden" name="@required" value="title"> <input type="hidden" name="category" tal:attributes="value cat"> . . . </form></pre> </div> <p>Note that later in the form, I use the value of “cat” to decide which form elements should be displayed. For example:</p> <div class="highlight-python"><pre><tal:block tal:condition="python:cat in '6 10 13 14 15 16 17'.split()"> <tr> <th>Operating System</th> <td tal:content="structure context/os/field"></td> </tr> <tr> <th>Web Browser</th> <td tal:content="structure context/browser/field"></td> </tr> </tal:block></pre> </div> <p>... the above section will only be displayed if the category is one of 6, 10, 13, 14, 15, 16 or 17.</p> </li> </ol> <ol class="arabic" start="3"> <li><p class="first">Determine what actions need to be taken between the pages - these are usually to validate user choices and determine what page is next. Now encode those actions in a new <tt class="docutils literal"><span class="pre">Action</span></tt> class (see <a class="reference internal" href="#defining-new-web-actions">defining new web actions</a>):</p> <div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">roundup.cgi.actions</span> <span class="kn">import</span> <span class="n">Action</span> <span class="k">class</span> <span class="nc">Page1SubmitAction</span><span class="p">(</span><span class="n">Action</span><span class="p">):</span> <span class="k">def</span> <span class="nf">handle</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> <span class="sd">''' Verify that the user has selected a category, and then move</span> <span class="sd"> on to page 2.</span> <span class="sd"> '''</span> <span class="n">category</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">form</span><span class="p">[</span><span class="s">'category'</span><span class="p">]</span><span class="o">.</span><span class="n">value</span> <span class="k">if</span> <span class="n">category</span> <span class="o">==</span> <span class="s">'-1'</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">client</span><span class="o">.</span><span class="n">error_message</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s">'You must select a category of report'</span><span class="p">)</span> <span class="k">return</span> <span class="c"># everything's ok, move on to the next page</span> <span class="bp">self</span><span class="o">.</span><span class="n">client</span><span class="o">.</span><span class="n">template</span> <span class="o">=</span> <span class="s">'add_page2'</span> <span class="k">def</span> <span class="nf">init</span><span class="p">(</span><span class="n">instance</span><span class="p">):</span> <span class="n">instance</span><span class="o">.</span><span class="n">registerAction</span><span class="p">(</span><span class="s">'page1_submit'</span><span class="p">,</span> <span class="n">Page1SubmitAction</span><span class="p">)</span> </pre></div> </div> </li> <li><p class="first">Use the usual “new” action as the <tt class="docutils literal"><span class="pre">@action</span></tt> on the final page, and you’re done (the standard context/submit method can do this for you).</p> </li> </ol> </div> </div> </div> <div class="section" id="debugging-trackers"> <h2>Debugging Trackers</h2> <p>There are three switches in tracker configs that turn on debugging in Roundup:</p> <ol class="arabic simple"> <li>web :: debug</li> <li>mail :: debug</li> <li>logging :: level</li> </ol> <p>See the config.ini file or the <a class="reference internal" href="#tracker-configuration">tracker configuration</a> section above for more information.</p> <p>Additionally, the <tt class="docutils literal"><span class="pre">roundup-server.py</span></tt> script has its own debugging mode in which it reloads edited templates immediately when they are changed, rather than requiring a web server restart.</p> </div> </div> <div class="related related-bottom"> <ul> <li class="right" style="margin-right: 10px"> <a href="genindex.html" title="General Index" accesskey="I">index</a></li> <li class="right" > <a href="admin_guide.html" title="Administration Guide" accesskey="N">next</a></li> <li class="right" > <a href="user_guide.html" title="User Guide" accesskey="P">previous</a></li> <li><a href="index.html">Roundup v1.4 documentation</a></li> </ul> </div> </div> <div class="footer"> © Copyright 2009, Richard Jones. <p class="source"><a href="_sources/customizing.txt" rel="nofollow">source</a></p> </div> </body> </html>