| Version: | 1.135.2.1 |
|---|
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 six forms:
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 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 |
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 the value has 'single quotes'" 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:
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:
"Foo Bar" <issue_tracker@tracker.example>
The EMAIL_FROM_TAG goes inside the "Foo Bar" quotes like so:
"Foo Bar EMAIL_FROM_TAG" <issue_tracker@tracker.example>
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') # Optional: the directory that static files are served from (files with # the URL /@@file/<filename>). If this is not defined, then static files # are served from the TEMPLATES directory. # STATIC_FILES = os.path.join(TRACKER_HOME, 'files') # 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. 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. TRACKER_WEB = 'http://tracker.example/cgi-bin/roundup.cgi/bugs/' # The email address that roundup will complain to if it runs into # trouble ADMIN_EMAIL = 'roundup-admin@%s'%MAIL_DOMAIN # 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: "Foo Bar" <issue_tracker@tracker.example> # the EMAIL_FROM_TAG goes inside the "Foo Bar" quotes like so: # "Foo Bar EMAIL_FROM_TAG" <issue_tracker@tracker.example> EMAIL_FROM_TAG = "" # 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) # HTML version to generate. The templates are html4 by default. If you # wish to make them xhtml, then you'll need to change this var to 'xhtml' # too so all auto-generated HTML is compliant. HTML_VERSION = 'html4' # either 'html4' or 'xhtml' # 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'. EMAIL_CHARSET = 'utf-8' #EMAIL_CHARSET = 'iso-8859-1' # use this instead for Eudora users # You may specify a different default timezone, for use when users do not # choose their own in their settings. DEFAULT_TIMEZONE = 0 # specify as numeric hour offest # # SECURITY DEFINITIONS # # define the Roles that a user gets when they register with the # tracker these are a comma-separated string of role names (e.g. # 'Admin,User') NEW_WEB_USER_ROLES = 'User' NEW_EMAIL_USER_ROLES = 'User'
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 dbinit.py module contains two functions:
The "classic" schema looks like this (see below for the meaning of 'setkey'):
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')
You must never:
Your schema may be changed at any time before or after the tracker has been initialised (or used). You may:
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 hold all e-mail messages sent to or generated by roundup.
- file
- Initially empty, will hold 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.
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.
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.
A Class is comprised of one or more properties of the following types:
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.
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 superseder link indicates an issue which has superseded 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.
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:
roundup-admin set issue23 assignedto=2
or:
roundup-admin set issue23 assignedto=richard
The same thing can be done in the web and e-mail interfaces.
If a class does not have an "order" property, the key is also used to sort instances of the class when it is rendered in the user interface. (If a class has no "order" property, sorting is by the labelproperty of the class. This is computed, in order of precedence, as the key, the "name", the "title", or the first property alphabetically.)
Create an item in the database. This is generally used to create items in the "definitional" classes like "priority" and "status".
When we sort items in the hyperdb, we use one of a number of methods, depending on the properties being sorted on:
Note that if an "order" property is defined on a Class that is used for sorting, all items of that Class must have a value against the "order" property, or sorting will result in random ordering.
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 "roundup-admin initialise" 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:
If you don't want this default behaviour, you're completely free to change or remove these detectors.
See the detectors section in the design document for details of the interface for detectors.
Auditors are called with the arguments:
audit(db, cl, itemid, newdata)
where db is the database, cl is an instance of Class or IssueClass within the database, and newdata is a dictionary mapping property names to values.
For a create() operation, the itemid argument is None and newdata contains all of the initial property values with which the item is about to be created.
For a set() operation, newdata contains only the names and values of properties that are about to be changed.
For a retire() or restore() operation, newdata is None.
Reactors are called with the arguments:
react(db, cl, itemid, olddata)
where db is the database, cl is an instance of Class or IssueClass within the database, and olddata is a dictionary mapping property names to values.
For a create() operation, the itemid argument is the id of the newly-created item and olddata is None.
For a set() operation, olddata contains the names and previous values of properties that were changed.
For a retire() or restore() operation, itemid is the id of the retired or restored item and olddata is None.
Sample additional detectors that have been found useful will appear in the 'detectors' directory of the Roundup distribution. If you want to use one, copy it to the 'detectors' of your tracker instance:
Generally speaking, the following rules should be observed:
Auditors may raise the Reject 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 Reject exception. It'll also not create users if that creation is Reject'ed too.
To use, simply add at the top of your auditor:
from roundup.exceptions import Reject
And then when your rejection criteria have been detected, simply:
raise Reject
The module roundup.mailer contains most of the nuts-n-bolts required to generate email messages from Roundup.
In addition, the IssueClass methods nosymessage() and send_message() 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).
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.
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.
You may also 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.
A set of Permissions is built into the security module by default:
Every Class you define in your tracker's schema also gets an Edit and View Permission of its own.
The default interfaces define:
These are hooked into the default Roles:
And finally, the "admin" user gets the "Admin" Role, and the "anonymous" user gets "Anonymous" assigned when the database is initialised on installation. The two default schemas then define:
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's dbinit.py):
#
# SECURITY SETTINGS
#
# 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 users are assigned the Roles defined in the config file as:
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.
When adding a new Permission, you will need to:
add it to your tracker's dbinit so it is created, using security.addPermission, for example:
self.security.addPermission(name="View", klass='frozzle',
description="User is allowed to access frozzles")
will set up a new "View" permission on the Class "frozzle".
enable it for the Roles that should have it (verify with "roundup-admin security")
add it to the relevant HTML interface templates
add it to the appropriate xxxPermission methods on in your tracker interfaces module
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:
<option tal:condition="python:request.user.hasPermission('Closer')"
value="resolved">Resolved</option>
Create a new Role called "User Admin" which has the Permission for editing users:
db.security.addRole(name='User Admin', description='Managing users')
p = db.security.getPermission('Edit', 'user')
db.security.addPermissionToRole('User Admin', p)
and assign the Role to the users who need the permission.
The web interface is provided by the roundup.cgi.client module and is used by roundup.cgi, roundup-server and ZRoundup (ZRoundup 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 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.
If you choose to change the tracker schema you will need to ensure the web interface knows about it:
The basic processing of a web request proceeds as follows:
In some situations, exceptions occur:
HTTP Redirect (generally raised by an action)
here we serve up a FileClass "content" property
here we serve up a file from the tracker "html" directory
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
this exception percolates up to the CGI interface that called the client
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:
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.
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:
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).
Let's say you wish to add frames to control the layout of your tracker's interface. You'd probably have:
A top-level frameset page. This page probably wouldn't be templated, so it could be served as a static file (see serving static content)
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:
<tracker url>/home?@template=navigation
See the previous section determining web context where it describes @file paths.
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:
Mangle some of the form variables:
Each of the actions is implemented by a corresponding *XxxAction* (where "Xxx" is the name of the action) class in the roundup.cgi.actions module. These classes are registered with roundup.cgi.client.Client which also happens to be available in your tracker instance as interfaces.Client. So if you need to define new actions, you may add them there (see defining new web actions).
Each action class also has a *permission* method which determines whether the action is permissible given the current user. The base permission checks are:
Item properties and their values are edited with html FORM variables and their values. You can:
In the following, <bracketed> values are variable, "@" may be either ":" or "@", and other text "required" is fixed.
Most properties are specified as form variables:
Designators name a specific item of a class.
Once we have determined the "propname", we look at it to see if it's special:
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.
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>.
The "@required" specifier must come before any of the properties it refers to are assigned in the form.
The value of the form variable is converted appropriately, depending on the type of the property.
For a Link('klass') property, the form value is a single key for 'klass', where the key field is specified in dbinit.py.
For a Multilink('klass') property, the form value is a comma-separated list of keys for 'klass', where the key field is specified in dbinit.py.
Note that for simple-form-variables specifiying Link and Multilink properties, the linked-to class must have a key field.
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.
For Date(), Interval(), Boolean(), and Number() properties, the form value is converted to the appropriate
Any of the form variables may be prefixed with a classname or designator.
Two special form values are supported for backwards compatibility:
This is equivalent to:
@link@messages=msg-1 msg-1@content=value
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.
This is equivalent to:
@link@files=file-1 file-1@content=value
The String content value is handled as described above for file uploads.
If both the "@note" and "@file" form variables are specified, the action:
@link@msg-1@files=file-1
is also performed.
We also check that FileClass items have a "content" property with actual content, otherwise we remove them from all_props before returning.
The default templates are html4 compliant. If you wish to change them to be xhtml compliant, you'll need to change the HTML_VERSION configuration variable in config.py to 'xhtml' instead of 'html4'.
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. The minimal template includes:
The classic template has a number of additional templates.
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.
Roundup's templates consist of special attributes on the HTML tags. These attributes form the Template Attribute Language, or TAL. The basic TAL commands are:
Define a new variable that is local to this tag and its contents. For example:
<html tal:define="title request/description"> <head><title tal:content="title"></title></head> </html>
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.
Only keep this tag and its contents if the expression is true. For example:
<p tal:condition="python:request.user.hasPermission('View', 'issue')">
Display some issue information.
</p>
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!).
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:
<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>
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 the repeat variable.
Replace this tag with the result of the expression. For example:
<span tal:replace="request/user/realname" />
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".
Replace the contents of this tag with the result of the expression. For example:
<span tal:content="request/user/realname">user's name appears here </span>
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>".
Set attributes on this tag to the results of expressions. For example:
<a tal:attributes="href string:user${request/user/id}">My Details</a>
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".
Remove this tag (but not its contents) if the expression is true. For example:
<span tal:omit-tag="python:1">Hello, world!</span>
would result in output of:
Hello, world!
The commands on a given tag are evaulated in the order above, so define comes before condition, and so on.
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).
The expressions you may use in the attribute values may be one of the following forms:
These are object attribute / item accesses. Roughly speaking, the path item/status/checklist is broken into parts item, status and checklist. The item part is the root of the expression. We then look for a status attribute on item, or failing that, a status item (as in item['status']). 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 path: prefix, but they are the default expression type, so it's not necessary.
If an expression evaluates to default, then the expression is "cancelled" - whatever HTML already exists in the template will remain (tag content in the case of tal:content, attributes in the case of tal:attributes).
If an expression evaluates to nothing then the target of the expression is removed (tag content in the case of tal:content, attributes in the case of tal:attributes and the tag itself in the case of tal:replace).
If an element in the path may not exist, then you can use the | operator in the expression to provide an alternative. So, the expression request/form/foo/value | default would simply leave the current HTML in place if the "foo" form variable doesn't exist.
You may use the python function path, as in path("item/status"), to embed path expressions in Python expressions.
Modifiers:
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.
Macros are generated and used inside your templates using special attributes similar to the basic templating actions. In this case, though, the attributes belong to the Macro Expansion Template Attribute Language, or METAL. The macro commands are:
Define that the tag and its contents are now a macro that may be inserted into other templates using the use-macro command. For example:
<html metal:define-macro="page"> ... </html>
defines a macro called "page" using the <html> tag and its contents. Once defined, macros are stored on the template they're defined on in the macros attribute. You can access them later on through the templates variable, eg. the most common templates/page/macros/icing to access the "page" macro of the "page" template.
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:
<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.
To define dynamic parts of the macro, you define "slots" which may be filled when the macro is used with a use-macro command. For example, the templates/page/macros/icing macro defines a slot like so:
<title metal:define-slot="head_title">title goes here</title>
In your use-macro command, you may now use a fill-slot command like this:
<title metal:fill-slot="head_title">My Title</title>
where the tag that fills the slot completely replaces the one defined as the slot in the macro.
You may not mix METAL and TAL commands on the same tag, but TAL commands may be used freely inside METAL-using tags (so your fill-slots tags may have all manner of TAL inside them).
The following behaviour is implemented by roundup.cgi.templating.RoundupPageTemplate
The following variables are available to templates.
This is a special variable - if an expression evaluates to this, then the tag (in the case of a tal:replace), its contents (in the case of tal:content) or some attributes (in the case of tal:attributes) will not appear in the the output. So, for example:
<span tal:attributes="class nothing">Hello, World!</span>
would result in:
<span>Hello, World!</span>
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:
<span tal:replace="default">Hello, World!</span>
would result in:
<span>Hello, World!</span>
The context variable is one of three things based on the current context (see determining web context for how we figure this out):
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:
This is implemented by the roundup.cgi.templating.HTMLClass class.
This wrapper object provides access to a hyperb 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.
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.
There are several methods available on these wrapper objects:
| Method | Description |
|---|---|
| properties | return a hyperdb property wrapper for all of this class's properties. |
| list | lists all of the active (not retired) items in the class. |
| csv | return the items of this class as a chunk of CSV text. |
| propnames | lists the names of the properties of this class. |
| filter | lists of items from this class, filtered and sorted. Two options are avaible for sorting:
eg. issue.filter(filterspec={"priority": "1"}, sort=('activity', '+')) |
| classhelp | display a link to a javascript popup containing this class' "help" template. |
| submit | generate a submit button (and action hidden element) |
| renderWith | render this class with the given template. |
| history | returns 'New node - no history' :) |
| is_edit_ok | is the user allowed to Edit the current class? |
| is_view_ok | is the user allowed to View the current class? |
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:
python:context['list']
will access the "list" property, rather than the list method.
This is implemented by the roundup.cgi.templating.HTMLItem class.
This wrapper object provides access to a hyperb item.
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.
There are several methods available on these wrapper objects:
| Method | Description |
|---|---|
| submit | generate a submit button (and action hidden element) |
| journal | return the journal of the current item (not implemented) |
| history | render the journal of the current item as HTML |
| renderQueryForm | specific to the "query" class - render the search form for the query |
| hasPermission | specific to the "user" class - determine whether the user has a Permission |
| is_edit_ok | is the user allowed to Edit the current item? |
| is_view_ok | is the user allowed to View the current item? |
| is_retired | is the item retired? |
| download_url | generates a url-quoted link for download of FileClass item contents (ie. file<id>/<name>) |
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:
python:context['journal']
will access the "journal" property, rather than the journal method.
This is implemented by subclasses of the roundup.cgi.templating.HTMLProperty class (HTMLStringProperty, HTMLNumberProperty, and so on).
This wrapper object provides access to a single property of a class. Its value may be either:
The property wrapper has some useful attributes:
| Attribute | Description |
|---|---|
| _name | the name of the property |
| _value | the value of the property if any - this is the actual value retrieved from the hyperdb for this property |
There are several methods available on these wrapper objects:
| Method | Description |
|---|---|
| plain | render a "plain" representation of the property. This method may take two arguments:
|
| hyperlinked | The same as msg.content.plain(hyperlink=1), but nicer: "structure msg/content/hyperlinked" |
| field | 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:
|
| stext | only on String properties - render the value of the property as StructuredText (requires the StructureText module to be installed separately) |
| multiline | only on String properties - render a multiline form edit field for the property |
| only on String properties - render the value of the property as an obscured email address | |
| confirm | 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". |
| now | only on Date properties - return the current date as a new property |
| reldate | only on Date properties - render the interval between the date and now |
| local | only on Date properties - return this date as a new property with some timezone offset, for example: python:context.creation.local(10) will render the date with a +10 hour offset. |
| pretty | Date properties - render the date as "dd Mon YYYY" (eg. "19 Mar 2004"). Takes an optional format argument, for example:
python:context.activity.pretty('%Y-%m-%d')
Will format as "2004-03-19" instead. Interval properties - render the interval in a pretty format (eg. "yesterday"). The format arguments are those used in the standard strftime call (see the Python Library Reference: time module) |
| menu | only on Link and Multilink properties - render a form select list for this property |
| reverse | only on Multilink properties - produce a list of the linked items in reverse order |
| isset | returns True if the property has been set to a value |
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:
context/title/field
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.
This is implemented by the roundup.cgi.templating.HTMLRequest class.
The request variable is packed with information about the current request.
| Variable | Holds |
|---|---|
| form | the CGI form as a cgi.FieldStorage |
| env | the CGI environment variables |
| base | the base URL for this tracker |
| user | a HTMLUser instance for this user |
| classname | the current classname (possibly None) |
| template | the current template (suffix, also possibly None) |
| form | the current CGI form variables in a FieldStorage |
Index page specific variables (indexing arguments)
| Variable | Holds |
|---|---|
| columns | dictionary of the columns to display in an index page |
| show | a convenience access to columns - request/show/colname will be true if the columns should be displayed, false otherwise |
| sort | index sort column (direction, column name) |
| group | index grouping property (direction, column name) |
| filter | properties to filter the index on |
| filterspec | values to filter the index on |
| search_text | text to perform a full-text search on for an index |
There are several methods available on the request variable:
| Method | Description |
|---|---|
| description | render a description of the request - handle for the page title |
| indexargs_form | render the current index args as form elements |
| indexargs_url | render the current index args as a URL |
| base_javascript | render some javascript that is used by other components of the templating |
| batch | run the current index args through a filter and return a list of items (see hyperdb item wrapper, and batching) |
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:
request/form/name/value
or the python expression:
python:request.form['name'].value
We use the "item" access used in the python case with an 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 request/form/name is actually a list of MiniFieldStorages. So it's best to know beforehand what you're dealing with.
This is implemented by the roundup.cgi.templating.HTMLDatabase class.
Allows access to all hyperdb classes as attributes of this variable. If you want access to the "user" class, for example, you would use:
db/user python:db.user
Also, the current id of the current user is available as db.getuid(). This isn't so useful in templates (where you have request/user), but it can be useful in detectors or interfaces.
The access results in a hyperdb class wrapper.
This is implemented by the roundup.cgi.templating.Templates class.
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:
templates/name
or the python expression:
templates[name]
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:
templates/name/macros/macro_name
or the python expression:
templates[name].macros[macro_name]
The repeat variable holds an entry for each active iteration. That is, if you have a tal:repeat="user db/users" command, then there will be a repeat variable entry called "user". This may be accessed as either:
repeat/user python:repeat['user']
The "user" entry has a number of methods available for information:
| Method | Description |
|---|---|
| first | True if the current item is the first in the sequence. |
| last | True if the current item is the last in the sequence. |
| even | True if the current item is an even item in the sequence. |
| odd | True if the current item is an odd item in the sequence. |
| number | Current position in the sequence, starting from 1. |
| letter | Current position in the sequence as a letter, a through z, then aa through zz, and so on. |
| Letter | Same as letter(), except uppercase. |
| roman | Current position in the sequence as lowercase roman numerals. |
| Roman | Same as roman(), except uppercase. |
This is implemented by the roundup.cgi.templating.TemplatingUtils class, but it may be extended as described below.
| Method | Description |
|---|---|
| Batch | return a batch object using the supplied list |
| url_quote | quote some text as safe for a URL (ie. space, %, ...) |
| html_quote | quote some text as safe in HTML (ie. <, >, ...) |
You may add additional utility methods by writing them in your tracker interfaces.py module's TemplatingUtils class. See adding a time log to your issues for an example. The TemplatingUtils class itself will have a single attribute, client, which may be used to access the client.db when you need to perform arbitrary database queries.
Use Batch to turn a list of items, or item ids of a given class, into a series of batches. Its usage is:
python:utils.Batch(sequence, size, start, end=0, orphan=0, overlap=0)
or, to get the current index batch:
request/batch
The parameters are:
| Parameter | Usage |
|---|---|
| sequence | a list of HTMLItems |
| size | how big to make the sequence. |
| start | where to start (0-indexed) in the sequence. |
| end | where to end (0-indexed) in the sequence. |
| orphan | if the next batch would contain less items than this value, then it is combined with this batch |
| overlap | the number of items shared between adjacent batches |
All of the parameters are assigned as attributes on the batch object. In addition, it has several more attributes:
| Attribute | Description |
|---|---|
| start | indicates the start index of the batch. unlike the argument, is a 1-based index (I know, lame) |
| first | indicates the start index of the batch as a 0-based index |
| length | the actual number of elements in the batch |
| sequence_length | the length of the original, unbatched, sequence. |
And several methods:
| Method | Description |
|---|---|
| previous | returns a new Batch with the previous batch settings |
| next | returns a new Batch with the next batch settings |
| propchanged | detect if the named property changed on the current item when compared to the last item |
An example of batching:
<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>
... which will produce a table with four columns containing the items of the "keyword" class (well, their "name" anyway).
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.
This is one of the class context views. It is also the default view for classes. The template used is "classname.index".
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-progress" 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.
| Argument | Description |
|---|---|
| @sort | sort by prop name, optionally preceeded with '-' to give descending or nothing for ascending sorting. |
| @group | group by prop name, optionally preceeded with '-' or to sort in descending or nothing for ascending order. |
| @columns | selects the columns that should be displayed. Default is all. |
| @filter | indicates which properties are being used in filtering. Default is none. |
| propname | selects the values the item properties given by propname must have (very basic search/filter). |
| @search_text | if supplied, performs a full-text search (message bodies, issue titles, etc) |
Note
If you add a new column to the @columns form variable potentials then you will need to add the column to the appropriate index views template so that it is actually displayed.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:
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.
If the search view does specify the "search" @action, then it may also provide an additional argument:
| Argument | Description |
|---|---|
| @query_name | 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 classic template schema has this ability, but the minimal template schema does not. |
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.
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.html" template):
<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> </td>
<td> </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> </td>
<td colspan="3" tal:content="structure context/submit">
submit button will go here
</td>
</tr>
</table>
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.
We have a number of ways to pull properties out of the form in order to meet the various needs of:
In the following, <bracketed> values are variable, ":" may be one of ":" or "@", and other text ("required") is fixed.
Properties are specified as form variables:
Once we have determined the "propname", we check to see if it is one of the special form values:
Any of the form variables may be prefixed with a classname or designator.
Two special form values are supported for backwards compatibility: