===================
Customising Roundup
===================
:Version: $Revision: 1.58 $
.. This document borrows from the ZopeBook section on ZPT. The original is at:
http://www.zope.org/Documentation/Books/ZopeBook/current/ZPT.stx
.. contents::
:depth: 1
What You Can Do
===============
Before you get too far, it's probably worth having a quick read of the Roundup
`design documentation`_.
Customisation of Roundup can take one of five forms:
1. `tracker configuration`_ file changes
2. database, or `tracker schema`_ changes
3. "definition" class `database content`_ changes
4. behavioural changes, through detectors_
5. `access controls`_
6. change the `web interface`_
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.
Trackers in a Nutshell
======================
Trackers have the following structure:
=================== ========================================================
Tracker File Description
=================== ========================================================
config.py Holds the basic `tracker configuration`_
dbinit.py Holds the `tracker schema`_
interfaces.py Defines the Web and E-Mail interfaces for the tracker
select_db.py Selects the database back-end for the tracker
db/ Holds the tracker's database
db/files/ Holds the tracker's upload files and messages
detectors/ Auditors and reactors for this tracker
html/ Web interface templates, images and style sheets
=================== ========================================================
Tracker Configuration
=====================
The config.py located in your tracker home contains the basic configuration
for the web and e-mail components of roundup's interfaces. As the name
suggests, this file is a Python module. This means that any valid python
expression may be used in the file. Mostly though, you'll be setting the
configuration variables to string values. Python string values must be quoted
with either single or double quotes::
'this is a string'
"this is also a string - use it when you have a 'single quote' in the value"
this is not a string - it's not quoted
Python strings may use formatting that's almost identical to C string
formatting. The ``%`` operator is used to perform the formatting, like so::
'roundup-admin@%s'%MAIL_DOMAIN
this will create a string ``'roundup-admin@tracker.domain.example'`` if
MAIL_DOMAIN is set to ``'tracker.domain.example'``.
You'll also note some values are set to::
os.path.join(TRACKER_HOME, 'db')
or similar. This creates a new string which holds the path to the "db"
directory in the TRACKER_HOME directory. This is just a convenience so if the
TRACKER_HOME changes you don't have to edit multiple valoues.
The configuration variables available are:
**TRACKER_HOME** - ``os.path.split(__file__)[0]``
The tracker home directory. The above default code will automatically
determine the tracker home for you, so you can just leave it alone.
**MAILHOST** - ``'localhost'``
The SMTP mail host that roundup will use to send e-mail.
**MAIL_DOMAIN** - ``'tracker.domain.example'``
The domain name used for email addresses.
**DATABASE** - ``os.path.join(TRACKER_HOME, 'db')``
This is the directory that the database is going to be stored in. By default
it is in the tracker home.
**TEMPLATES** - ``os.path.join(TRACKER_HOME, 'html')``
This is the directory that the HTML templates reside in. By default they are
in the tracker home.
**TRACKER_NAME** - ``'Roundup issue tracker'``
A descriptive name for your roundup tracker. This is sent out in e-mails and
appears in the heading of CGI pages.
**TRACKER_EMAIL** - ``'issue_tracker@%s'%MAIL_DOMAIN``
The email address that e-mail sent to roundup should go to. Think of it as the
tracker's personal e-mail address.
**TRACKER_WEB** - ``'http://your.tracker.url.example/'``
The web address that the tracker is viewable at. This will be included in
information sent to users of the tracker.
**ADMIN_EMAIL** - ``'roundup-admin@%s'%MAIL_DOMAIN``
The email address that roundup will complain to if it runs into trouble.
**MESSAGES_TO_AUTHOR** - ``'yes'`` or``'no'``
Send nosy messages to the author of the message.
**ADD_AUTHOR_TO_NOSY** - ``'new'``, ``'yes'`` or ``'no'``
Does the author of a message get placed on the nosy list automatically?
If ``'new'`` is used, then the author will only be added when a message
creates a new issue. If ``'yes'``, then the author will be added on followups
too. If ``'no'``, they're never added to the nosy.
**ADD_RECIPIENTS_TO_NOSY** - ``'new'``, ``'yes'`` or ``'no'``
Do the recipients (To:, Cc:) of a message get placed on the nosy list?
If ``'new'`` is used, then the recipients will only be added when a message
creates a new issue. If ``'yes'``, then the recipients will be added on
followups too. If ``'no'``, they're never added to the nosy.
**EMAIL_SIGNATURE_POSITION** - ``'top'``, ``'bottom'`` or ``'none'``
Where to place the email signature in messages that Roundup generates.
**EMAIL_KEEP_QUOTED_TEXT** - ``'yes'`` or ``'no'``
Keep email citations. Citations are the part of e-mail which the sender has
quoted in their reply to previous e-mail.
**EMAIL_LEAVE_BODY_UNCHANGED** - ``'no'``
Preserve the email body as is. Enabiling this will cause the entire message
body to be stored, including all citations and signatures. It should be
either ``'yes'`` or ``'no'``.
**MAIL_DEFAULT_CLASS** - ``'issue'`` or ``''``
Default class to use in the mailgw if one isn't supplied in email
subjects. To disable, comment out the variable below or leave it blank.
The default config.py is given below - as you
can see, the MAIL_DOMAIN must be edited before any interaction with the
tracker is attempted.::
# roundup home is this package's directory
TRACKER_HOME=os.path.split(__file__)[0]
# The SMTP mail host that roundup will use to send mail
MAILHOST = 'localhost'
# The domain name used for email addresses.
MAIL_DOMAIN = 'your.tracker.email.domain.example'
# This is the directory that the database is going to be stored in
DATABASE = os.path.join(TRACKER_HOME, 'db')
# This is the directory that the HTML templates reside in
TEMPLATES = os.path.join(TRACKER_HOME, 'html')
# A descriptive name for your roundup tracker
TRACKER_NAME = 'Roundup issue tracker'
# The email address that mail to roundup should go to
TRACKER_EMAIL = 'issue_tracker@%s'%MAIL_DOMAIN
# The web address that the tracker is viewable at
TRACKER_WEB = 'http://your.tracker.url.example/'
# The email address that roundup will complain to if it runs into trouble
ADMIN_EMAIL = 'roundup-admin@%s'%MAIL_DOMAIN
# Send nosy messages to the author of the message
MESSAGES_TO_AUTHOR = 'no' # either 'yes' or 'no'
# Does the author of a message get placed on the nosy list automatically?
# If 'new' is used, then the author will only be added when a message
# creates a new issue. If 'yes', then the author will be added on followups
# too. If 'no', they're never added to the nosy.
ADD_AUTHOR_TO_NOSY = 'new' # one of 'yes', 'no', 'new'
# Do the recipients (To:, Cc:) of a message get placed on the nosy list?
# If 'new' is used, then the recipients will only be added when a message
# creates a new issue. If 'yes', then the recipients will be added on followups
# too. If 'no', they're never added to the nosy.
ADD_RECIPIENTS_TO_NOSY = 'new' # either 'yes', 'no', 'new'
# Where to place the email signature
EMAIL_SIGNATURE_POSITION = 'bottom' # one of 'top', 'bottom', 'none'
# Keep email citations
EMAIL_KEEP_QUOTED_TEXT = 'no' # either 'yes' or 'no'
# Preserve the email body as is
EMAIL_LEAVE_BODY_UNCHANGED = 'no' # either 'yes' or 'no'
# Default class to use in the mailgw if one isn't supplied in email
# subjects. To disable, comment out the variable below or leave it blank.
# Examples:
MAIL_DEFAULT_CLASS = 'issue' # use "issue" class by default
#MAIL_DEFAULT_CLASS = '' # disable (or just comment the var out)
Tracker Schema
==============
Note: if you modify the schema, you'll most likely need to edit the
`web interface`_ HTML template files and `detectors`_ to reflect
your changes.
A tracker schema defines what data is stored in the tracker's database.
Schemas are defined using Python code in the ``dbinit.py`` module of your
tracker. The "classic" schema looks like this::
pri = Class(db, "priority", name=String(), order=String())
pri.setkey("name")
stat = Class(db, "status", name=String(), order=String())
stat.setkey("name")
keyword = Class(db, "keyword", name=String())
keyword.setkey("name")
user = Class(db, "user", username=String(), organisation=String(),
password=String(), address=String(), realname=String(), phone=String())
user.setkey("username")
msg = FileClass(db, "msg", author=Link("user"), summary=String(),
date=Date(), recipients=Multilink("user"), files=Multilink("file"))
file = FileClass(db, "file", name=String(), type=String())
issue = IssueClass(db, "issue", topic=Multilink("keyword"),
status=Link("status"), assignedto=Link("user"),
priority=Link("priority"))
issue.setkey('title')
Classes and Properties - creating a new information store
---------------------------------------------------------
In the tracker above, we've defined 7 classes of information:
priority
Defines the possible levels of urgency for issues.
status
Defines the possible states of processing the issue may be in.
keyword
Initially empty, will hold keywords useful for searching issues.
user
Initially holding the "admin" user, will eventually have an entry for all
users using roundup.
msg
Initially empty, will all e-mail messages sent to or generated by
roundup.
file
Initially empty, will all files attached to issues.
issue
Initially empty, this is where the issue information is stored.
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.
Class and Items
~~~~~~~~~~~~~~~
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 given the information
about the class items.
The actual data entered into the database, using class.create() are called
items. They have a special immutable property called id. We sometimes refer to
this as the itemid.
Properties
~~~~~~~~~~
A Class is comprised of one or more properties of the following types:
* String properties are for storing arbitrary-length strings.
* Password properties are for storing encoded arbitrary-length strings. The
default encoding is defined on the roundup.password.Password class.
* Date properties store date-and-time stamps. Their values are Timestamp
objects.
* Number properties store numeric values.
* Boolean properties store on/off, yes/no, true/false values.
* 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.
* A Multilink property refers to possibly many items in a specified class.
The value is a list of integers.
FileClass
~~~~~~~~~
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 db directory in your tracker.
IssueClass
~~~~~~~~~~
IssueClasses automatically include the "messages", "files", "nosy", and
"superseder" properties.
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 detectors
directory) handles this action. The superceder link indicates an issue which
has superceded this one.
They also have the dynamically generated "creation", "activity" and "creator"
properties.
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.
setkey(property)
~~~~~~~~~~~~~~~~
Select a String property of the class to be the key property. The key property
muse 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, e.g.
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::
roundup-admin set issue assignedto=2
or::
roundup-admin set issue assignedto=richard
Note, the same thing can be done in the web and e-mail interfaces.
create(information)
~~~~~~~~~~~~~~~~~~~
Create an item in the database. This is generally used to create items in the
"definitional" classes like "priority" and "status".
Examples of adding to your schema
---------------------------------
TODO
Detectors - adding behaviour to your tracker
============================================
.. _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 initliased
via the "roundup-admin initalise" command.
The detectors in your tracker fire before (*auditors*) and after (*reactors*)
changes to the contents of your database. They are Python modules that sit in
your tracker's ``detectors`` 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:
**nosyreaction.py**
This provides the automatic nosy list maintenance and email sending. The nosy
reactor (``nosyreaction``) fires when new messages are added to issues.
The nosy auditor (``updatenosy``) fires when issues are changed and figures
what changes need to be made to the nosy list (like adding new authors etc)
**statusauditor.py**
This provides the ``chatty`` auditor which changes the issue status from
``unread`` or ``closed`` to ``chatting`` if new messages appear. It also
provides the ``presetunread`` auditor which pre-sets the status to
``unread`` on new items if the status isn't explicitly defined.
See the detectors section in the `design document`__ for details of the
interface for detectors.
__ design.html
Sample additional detectors that have been found useful will appear in the
``detectors`` directory of the Roundup distribution:
**newissuecopy.py**
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 'team@team.host') or you'll get email errors!
The detector code::
from roundup import roundupdb
def newissuecopy(db, cl, nodeid, oldvalues):
''' Copy a message about new issues to a team address.
'''
# so use all the messages in the create
change_note = cl.generateCreateNote(nodeid)
# send a copy to the nosy list
for msgid in cl.get(nodeid, 'messages'):
try:
# note: last arg must be a list
cl.send_message(nodeid, msgid, change_note, ['team@team.host'])
except roundupdb.MessageSendError, message:
raise roundupdb.DetectorError, message
def init(db):
db.issue.react('create', newissuecopy)
Database Content
================
Note: if you modify the content of definitional classes, you'll most likely
need to edit the tracker `detectors`_ to reflect your changes.
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.
**Changing content before tracker initialisation**
Edit the dbinit module in your tracker to alter the items created in using
the create() methods.
**Changing content after tracker initialisation**
Use the roundup-admin interface's create, set and retire methods to add,
alter or remove items from the classes in question.
See "`adding a new field to the classic schema`_" for an example that requires
database content changes.
Access Controls
===============
A set of Permissions are built in to the security module by default:
- Edit (everything)
- View (everything)
The default interfaces define:
- Web Registration
- Web Access
- Web Roles
- Email Registration
- Email Access
These are hooked into the default Roles:
- Admin (Edit everything, View everything, Web Roles)
- User (Web Access, Email Access)
- Anonymous (Web Registration, Email Registration)
And finally, the "admin" user gets the "Admin" Role, and the "anonymous" user
gets the "Anonymous" assigned when the database is initialised on installation.
The two default schemas then define:
- Edit issue, View issue (both)
- Edit file, View file (both)
- Edit msg, View msg (both)
- Edit support, View support (extended only)
and assign those Permissions to the "User" Role. Put together, these settings
appear in the ``open()`` function of the tracker ``dbinit.py`` (the following
is taken from the "minimal" template ``dbinit.py``)::
#
# SECURITY SETTINGS
#
# new permissions for this schema
for cl in ('user', ):
db.security.addPermission(name="Edit", klass=cl,
description="User is allowed to edit "+cl)
db.security.addPermission(name="View", klass=cl,
description="User is allowed to access "+cl)
# and give the regular users access to the web and email interface
p = db.security.getPermission('Web Access')
db.security.addPermissionToRole('User', p)
p = db.security.getPermission('Email Access')
db.security.addPermissionToRole('User', p)
# May users view other user information? Comment these lines out
# if you don't want them to
p = db.security.getPermission('View', 'user')
db.security.addPermissionToRole('User', p)
# Assign the appropriate permissions to the anonymous user's Anonymous
# Role. Choices here are:
# - Allow anonymous users to register through the web
p = db.security.getPermission('Web Registration')
db.security.addPermissionToRole('Anonymous', p)
# - Allow anonymous (new) users to register through the email gateway
p = db.security.getPermission('Email Registration')
db.security.addPermissionToRole('Anonymous', p)
New User Roles
--------------
New users are assigned the Roles defined in the config file as:
- NEW_WEB_USER_ROLES
- NEW_EMAIL_USER_ROLES
Changing Access Controls
------------------------
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.
You may use the ``roundup-admin`` "``security``" command to display the
current Role and Permission configuration in your tracker.
Adding a new Permission
~~~~~~~~~~~~~~~~~~~~~~~
When adding a new Permission, you will need to:
1. add it to your tracker's dbinit so it is created
2. enable it for the Roles that should have it (verify with
"``roundup-admin security``")
3. add it to the relevant HTML interface templates
4. add it to the appropriate xxxPermission methods on in your tracker
interfaces module
Example Scenarios
~~~~~~~~~~~~~~~~~
**automatic registration of users in the e-mail gateway**
By giving the "anonymous" user the "Email Registration" Role, 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 them a password). Note: this is the default behaviour in the tracker
templates that ship with Roundup.
**anonymous access through the e-mail gateway**
Give the "anonymous" user the "Email Access" and ("Edit", "issue") Roles
but not giving them the "Email Registration" Role. 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 "Email Registration" Role, 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
*anonymous*.
**only developers may be assigned issues**
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 `restricting the list of users that are assignable to a task`_.
**only managers may sign off issues as complete**
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::
**don't give users who register through email web access**
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.
Web Interface
=============
.. contents::
:local:
:depth: 1
The web is provided by the roundup.cgi.client module and is used by
roundup.cgi, roundup-server and ZRoundup.
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 tracker interfaces.Client class - which uses the Client class
from roundup.cgi.client - which handles the rest of
the access through its main() method. This means that you can do pretty much
anything you want as a web interface to your tracker.
Repurcussions of changing the tracker schema
---------------------------------------------
If you choose to change the `tracker schema`_ you will need to ensure the web
interface knows about it:
1. Index, item and search pages for the relevant classes may need to have
properties added or removed,
2. The "page" template may require links to be changed, as might the "home"
page's content arguments.
How requests are processed
--------------------------
The basic processing of a web request proceeds as follows:
1. figure out who we are, defaulting to the "anonymous" user
2. figure out what the request is for - we call this the "context"
3. handle any requested action (item edit, search, ...)
4. render the template requested by the context, resulting in HTML output
In some situations, exceptions occur:
- HTTP Redirect (generally raised by an action)
- SendFile (generally raised by determine_context)
here we serve up a FileClass "content" property
- SendStaticFile (generally raised by determine_context)
here we serve up a file from the tracker "html" directory
- Unauthorised (generally raised by an action)
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
- NotFound (raised wherever it needs to be)
this exception percolates up to the CGI interface that called the client
Determining web context
-----------------------
To determine the "context" of a request, we look at the URL and the special
request variable ``:template``. The URL path after the tracker identifier
is examined. Typical URL paths look like:
1. ``/tracker/issue``
2. ``/tracker/issue1``
3. ``/tracker/_file/style.css``
4. ``/cgi-bin/roundup.cgi/tracker/file1``
5. ``/cgi-bin/roundup.cgi/tracker/file1/kitten.png``
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.
a. if there is no path, then we are in the "home" context.
b. 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 "html" directory. Raises a SendStaticFile
exception.
c. if there is something in the path (as in example 1, "issue"), it identifies
the tracker class we're to display.
d. if the path is an item designator (as in examples 2 and 4, "issue1" and
"file1"), then we're to display a specific item.
e. 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
FileClass, and the extra path information gives the filename
that the client is going to label the download with (ie
"file1/kitten.png" is nicer to download than "file1"). This
raises a SendFile exception.
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.
The template used is specified by the ``:template`` CGI variable,
which defaults to:
- only classname suplied: "index"
- full item designator supplied: "item"
Performing actions in web requests
----------------------------------
When a user requests a web page, they may optionally also request for an
action to take place. As described in `how requests are processed`_, the
action is performed before the requested page is generated. Actions are
triggered by using a ``:action`` CGI variable, where the value is one of:
**login**
Attempt to log a user in.
**logout**
Log the user out - make them "anonymous".
**register**
Attempt to create a new user based on the contents of the form and then log
them in.
**edit**
Perform an edit of an item in the database. There are some special form
elements you may use:
:link=designator:property and :multilink=designator:property
The value specifies an item designator and the property on that
item to add *this* item to as a link or multilink.
:note
Create a message and attach it to the current item's
"messages" property.
:file
Create a file and attach it to the current item's
"files" property. Attach the file to the message created from
the :note if it's supplied.
:required=property,property,...
The named properties are required to be filled in the form.
**new**
Add a new item to the database. You may use the same special form elements
as in the "edit" action.
**retire**
Retire the item in the database.
**editCSV**
Performs an edit of all of a class' items in one go. See also the
*class*.csv templating method which generates the CSV data to be edited, and
the "_generic.index" template which uses both of these features.
**search**
Mangle some of the form variables.
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.
Also handle the ":queryname" variable and save off the query to
the user's query list.
Each of the actions is implemented by a corresponding *actionAction* (where
"action" is the name of the action) method on
the roundup.cgi.Client class, which also happens to be in your tracker as
interfaces.Client. So if you need to define new actions, you may add them
there (see `defining new web actions`_).
Each action also has a corresponding *actionPermission* (where
"action" is the name of the action) method which determines
whether the action is permissible given the current user. The base permission
checks are:
**login**
Determine whether the user has permission to log in.
Base behaviour is to check the user has "Web Access".
**logout**
No permission checks are made.
**register**
Determine whether the user has permission to register
Base behaviour is to check the user has "Web Registration".
**edit**
Determine whether the user has permission to edit this item.
Base behaviour is to check the user can edit this class. If we're
editing the "user" class, users are allowed to edit their own
details. Unless it's the "roles" property, which requires the
special Permission "Web Roles".
**new**
Determine whether the user has permission to create (edit) this item.
Base behaviour is to check the user can edit this class. No
additional property checks are made. Additionally, new user items
may be created if the user has the "Web Registration" Permission.
**editCSV**
Determine whether the user has permission to edit this class.
Base behaviour is to check the user can edit this class.
**search**
Determine whether the user has permission to search this class.
Base behaviour is to check the user can view this class.
Default templates
-----------------
Most customisation of the web view can be done by modifying the templates in
the tracker **html** directory. There are several types of files in there:
**page**
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 will also define the "head_title"
and "body_title" slots to allow setting of the page title.
**home**
the default page displayed when no other page is indicated by the user
**home.classlist**
a special version of the default page that lists the classes in the tracker
**classname.item**
displays an item of the *classname* class
**classname.index**
displays a list of *classname* items
**classname.search**
displays a search page for *classname* items
**_generic.index**
used to display a list of items where there is no *classname*.index available
**_generic.help**
used to display a "class help" page where there is no *classname*.help
**user.register**
a special page just for the user class that renders the registration page
**style.css**
a static file that is served up as-is
Note: 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::
http://your.tracker.example/tracker/issue?:template=test
and it won't affect your users using the "issue.item" template.
How the templates work
----------------------
Basic Templating Actions
~~~~~~~~~~~~~~~~~~~~~~~~
Roundup's templates consist of special attributes on your template tags.
These attributes form the Template Attribute Language, or TAL. The basic tag
commands are:
**tal:define="variable expression; variable expression; ..."**
Define a new variable that is local to this tag and its contents. For
example::
In the example, the variable "title" is defined as being the result of the
expression "request/description". The tal:content command inside the
tag may then use the "title" variable.
**tal:condition="expression"**
Only keep this tag and its contents if the expression is true. For example::
Display some issue information.
In the example, the
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!).
**tal:repeat="variable expression"**
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::
... which will produce a table with four columns containing the items of the
"keyword" class (well, their "name" anyway).
Displaying Properties
---------------------
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.
Index Views
-----------
This is one of the class context views. It is also the default view for
classes. The template used is "*classname*.index".
Index View Specifiers
~~~~~~~~~~~~~~~~~~~~~
An index view specifier (URL fragment) looks like this (whitespace has been
added for clarity)::
/issue?status=unread,in-progress,resolved&
topic=security,ui&
:group=+priority&
:sort==activity&
:filters=status,topic&
:columns=title,status,fixer
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.
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.
The example specifies an index of "issue" items. Only items with a "status" of
either "unread" or "in-progres" or "resolved" are displayed, and only items
with "topic" values including both "security" and "ui" are displayed. The items
are grouped by priority, arranged in ascending order; and within groups, sorted
by activity, arranged in descending order. The filter section shows filters for
the "status" and "topic" properties, and the table includes columns for the
"title", "status", and "fixer" properties.
Searching Views
---------------
This is one of the class context views. The template used is typically
"*classname*.search". The form on this page should have "search" as its
``:action`` variable. The "search" action:
- sets up additional filtering, as well as performing indexed text searching
- sets the ``:filter`` variable correctly
- saves the query off if ``:query_name`` is set.
The searching page should lay out any fields that you wish to allow the user
to search one. 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.
The two special form values on search pages which are handled by the "search"
action are:
:search_text
Text to perform a search of the text index with. Results from that search
will be used to limit the results of other filters (using an intersection
operation)
:query_name
If supplied, the search parameters (including :search_text) will be saved
off as a the query item and registered against the user's queries property.
Note that the *classic* template schema has this ability, but the *minimal*
template schema does not.
Item Views
----------
The basic view of a hyperdb item is provided by the "*classname*.item"
template. It generally has three sections; an "editor", a "spool" and a
"history" section.
Editor Section
~~~~~~~~~~~~~~
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.
Here's an example of a basic editor template (this is the default "classic"
template issue item edit form - from the "issue.item" template)::
Title
title
Priority
priority
Status
status
Superseder
View:
Nosy List
Assigned To
assignedto menu
Change Note
File
submit button will go here
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 change note message generated by Roundup.
Spool Section
~~~~~~~~~~~~~
The spool section lists related information like the messages and files of
an issue.
TODO
History Section
~~~~~~~~~~~~~~~
The final section displayed is the history of the item - its database journal.
This is generally generated with the template::
*To be done:*
*The actual history entries of the item may be accessed for manual templating
through the "journal" method of the item*::
a journal entry
*where each journal entry is an HTMLJournalEntry.*
Defining new web actions
------------------------
You may define new actions to be triggered by the ``:action`` form variable.
These are added to the tracker ``interfaces.py`` as methods on the ``Client``
class.
Adding action methods takes three steps; first you `define the new action
method`_, then you `register the action method`_ with the cgi interface so
it may be triggered by the ``:action`` form variable. Finally you actually
`use the new action`_ in your HTML form.
See "`setting up a "wizard" (or "druid") for controlled adding of issues`_"
for an example.
Define the new action method
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The action methods have the following interface::
def myActionMethod(self):
''' Perform some action. No return value is required.
'''
The *self* argument is an instance of your tracker ``instance.Client`` class -
thus it's mostly implemented by ``roundup.cgi.Client``. See the docstring of
that class for details of what it can do.
The method will typically check the ``self.form`` variable's contents. It
may then:
- add information to ``self.ok_message`` or ``self.error_message``
- change the ``self.template`` variable to alter what the user will see next
- raise Unauthorised, SendStaticFile, SendFile, NotFound or Redirect
exceptions
Register the action method
~~~~~~~~~~~~~~~~~~~~~~~~~~
The method is now written, but isn't available to the user until you add it to
the `instance.Client`` class ``actions`` variable, like so::
actions = client.Class.actions + (
('myaction', 'myActionMethod'),
)
This maps the action name "myaction" to the action method we defined.
Use the new action
~~~~~~~~~~~~~~~~~~
In your HTML form, add a hidden form element like so::
where "myaction" is the name you registered in the previous step.
Examples
========
.. contents::
:local:
:depth: 1
Adding a new field to the classic schema
----------------------------------------
This example shows how to add a new constrained property (ie. a selection of
distinct values) to your tracker.
Introduction
~~~~~~~~~~~~
To make the classic schema of roundup useful as a todo tracking system
for a group of systems administrators, it needed an extra data field
per issue: a category.
This would let sysads 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 sysads (a losing
proposition at best).
Adding a field to the database
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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 ``open()`` function in ``dbinit.py`` under the comment::
# add any additional database schema configuration here
add::
category = Class(db, "category", name=String())
category.setkey("name")
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. 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.
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 the ``open()`` function in ``dbinit.py`` which
set up the "issue" class, and then add a link to the category::
issue = IssueClass(db, "issue", ... , category=Multilink("category"), ... )
The Multilink() means that each issue can have many categories. If you were
adding something with a more one to one relationship use Link() instead.
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.
Populating the new category class
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
If you haven't initialised the database with the roundup-admin "initialise"
command, then you can add the following to the tracker ``dbinit.py`` in the
``init()`` function under the comment::
# add any additional database create steps here - but only if you
# haven't initialised the database with the admin "initialise" command
add::
category = db.getclass('category')
category.create(name="scipy", order="1")
category.create(name="chaco", order="2")
category.create(name="weave", order="3")
If the database is initalised, the you need to use the roundup-admin tool::
% roundup-admin -i
Roundup ready for input.
Type "help" for help.
roundup> create category name=scipy order=1
1
roundup> create category name=chaco order=1
2
roundup> create category name=weave order=1
3
roundup> exit...
There are unsaved changes. Commit them (y/N)? y
Setting up security on the new objects
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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.
We therefore need to change the security of the category objects. This is
also done in the ``open()`` function of ``dbinit.py``.
There are currently two loops which set up permissions and then assign them
to various roles. Simply add the new "category" to both lists::
# new permissions for this schema
for cl in 'issue', 'file', 'msg', 'user', 'category':
db.security.addPermission(name="Edit", klass=cl,
description="User is allowed to edit "+cl)
db.security.addPermission(name="View", klass=cl,
description="User is allowed to access "+cl)
# Assign the access and edit permissions for issue, file and message
# to regular users now
for cl in 'issue', 'file', 'msg', 'category':
p = db.security.getPermission('View', cl)
db.security.addPermissionToRole('User', p)
p = db.security.getPermission('Edit', cl)
db.security.addPermissionToRole('User', p)
So you are in effect doing the following::
db.security.addPermission(name="Edit", klass='category',
description="User is allowed to edit "+'category')
db.security.addPermission(name="View", klass='category',
description="User is allowed to access "+'category')
which is creating two permission types; that of editing and viewing
"category" objects respectively. Then the following lines assign those new
permissions to the "User" role, so that normal users can view and edit
"category" objects::
p = db.security.getPermission('View', 'category')
db.security.addPermissionToRole('User', p)
p = db.security.getPermission('Edit', 'category')
db.security.addPermissionToRole('User', 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.
Changing the web left hand frame
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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
``html/page``, which is what we are going to be editing next.
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. Under
the end of the classblock for issue is where we are going to add the
category code::
The first two lines is the classblock definition, which sets up a condition
that only users who have "View" permission to 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.
Next comes the link to the editing area of categories. This link will only
appear if the condition is matched: that condition being that the user has
"Edit" permissions for the "category" objects. If they do have permission
then they will get a link to another page which will let the user add new
categories.
Note that if you have permission to view but not edit 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.
Setting up a page to edit categories
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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.
The link was for the item template for the category object. This translates
into the system looking for a file called ``category.item`` in the ``html``
tracker directory. This is the file that we are going to write now.
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::
Next we need to add in the METAL macro stuff so we get the normal page
trappings::
Category editing
Category editing
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::