Code

Fix (re)indexing & find in back_metakit.
[roundup.git] / doc / customizing.txt
1 ===================
2 Customising Roundup
3 ===================
5 :Version: $Revision: 1.50 $
7 .. This document borrows from the ZopeBook section on ZPT. The original is at:
8    http://www.zope.org/Documentation/Books/ZopeBook/current/ZPT.stx
10 .. contents::
11    :depth: 1
13 What You Can Do
14 ===============
16 Customisation of Roundup can take one of five forms:
18 1. `tracker configuration`_ file changes
19 2. database, or `tracker schema`_ changes
20 3. "definition" class `database content`_ changes
21 4. behavioural changes, through detectors_
22 5. `access controls`_
24 The third case is special because it takes two distinctly different forms
25 depending upon whether the tracker has been initialised or not. The other two
26 may be done at any time, before or after tracker initialisation. Yes, this
27 includes adding or removing properties from classes.
30 Trackers in a Nutshell
31 ======================
33 Trackers have the following structure:
35 =================== ========================================================
36 Tracker File        Description
37 =================== ========================================================
38 config.py           Holds the basic `tracker configuration`_                 
39 dbinit.py           Holds the `tracker schema`_                              
40 interfaces.py       Defines the Web and E-Mail interfaces for the tracker    
41 select_db.py        Selects the database back-end for the tracker            
42 db/                 Holds the tracker's database                             
43 db/files/           Holds the tracker's upload files and messages            
44 detectors/          Auditors and reactors for this tracker                   
45 html/               Web interface templates, images and style sheets         
46 =================== ======================================================== 
48 Tracker Configuration
49 =====================
51 The config.py located in your tracker home contains the basic
52 configuration for the web and e-mail components of roundup's interfaces. This
53 file is a Python module. The configuration variables available are:
55 **TRACKER_HOME** - ``os.path.split(__file__)[0]``
56  The tracker home directory. The above default code will automatically
57  determine the tracker home for you.
59 **MAILHOST** - ``'localhost'``
60  The SMTP mail host that roundup will use to send e-mail.
62 **MAIL_DOMAIN** - ``'your.tracker.email.domain.example'``
63  The domain name used for email addresses.
65 **DATABASE** - ``os.path.join(TRACKER_HOME, 'db')``
66  This is the directory that the database is going to be stored in. By default
67  it is in the tracker home.
69 **TEMPLATES** - ``os.path.join(TRACKER_HOME, 'html')``
70  This is the directory that the HTML templates reside in. By default they are
71  in the tracker home.
73 **TRACKER_NAME** - ``'Roundup issue tracker'``
74  A descriptive name for your roundup tracker. This is sent out in e-mails and
75  appears in the heading of CGI pages.
77 **TRACKER_EMAIL** - ``'issue_tracker@%s'%MAIL_DOMAIN``
78  The email address that e-mail sent to roundup should go to. Think of it as the
79  tracker's personal e-mail address.
81 **TRACKER_WEB** - ``'http://your.tracker.url.example/'``
82  The web address that the tracker is viewable at. This will be included in
83  information sent to users of the tracker.
85 **ADMIN_EMAIL** - ``'roundup-admin@%s'%MAIL_DOMAIN``
86  The email address that roundup will complain to if it runs into trouble.
88 **MESSAGES_TO_AUTHOR** - ``'yes'`` or``'no'``
89  Send nosy messages to the author of the message.
91 **ADD_AUTHOR_TO_NOSY** - ``'new'``, ``'yes'`` or ``'no'``
92  Does the author of a message get placed on the nosy list automatically?
93  If ``'new'`` is used, then the author will only be added when a message
94  creates a new issue. If ``'yes'``, then the author will be added on followups
95  too. If ``'no'``, they're never added to the nosy.
97 **ADD_RECIPIENTS_TO_NOSY** - ``'new'``, ``'yes'`` or ``'no'``
98  Do the recipients (To:, Cc:) of a message get placed on the nosy list?
99  If ``'new'`` is used, then the recipients will only be added when a message
100  creates a new issue. If ``'yes'``, then the recipients will be added on
101  followups too. If ``'no'``, they're never added to the nosy.
103 **EMAIL_SIGNATURE_POSITION** - ``'top'``, ``'bottom'`` or ``'none'``
104  Where to place the email signature in messages that Roundup generates.
106 **EMAIL_KEEP_QUOTED_TEXT** - ``'yes'`` or ``'no'``
107  Keep email citations. Citations are the part of e-mail which the sender has
108  quoted in their reply to previous e-mail.
110 **EMAIL_LEAVE_BODY_UNCHANGED** - ``'no'``
111  Preserve the email body as is. Enabiling this will cause the entire message
112  body to be stored, including all citations and signatures. It should be
113  either ``'yes'`` or ``'no'``.
115 **MAIL_DEFAULT_CLASS** - ``'issue'`` or ``''``
116  Default class to use in the mailgw if one isn't supplied in email
117  subjects. To disable, comment out the variable below or leave it blank.
119 The default config.py is given below - as you
120 can see, the MAIL_DOMAIN must be edited before any interaction with the
121 tracker is attempted.::
123     # roundup home is this package's directory
124     TRACKER_HOME=os.path.split(__file__)[0]
126     # The SMTP mail host that roundup will use to send mail
127     MAILHOST = 'localhost'
129     # The domain name used for email addresses.
130     MAIL_DOMAIN = 'your.tracker.email.domain.example'
132     # This is the directory that the database is going to be stored in
133     DATABASE = os.path.join(TRACKER_HOME, 'db')
135     # This is the directory that the HTML templates reside in
136     TEMPLATES = os.path.join(TRACKER_HOME, 'html')
138     # A descriptive name for your roundup tracker
139     TRACKER_NAME = 'Roundup issue tracker'
141     # The email address that mail to roundup should go to
142     TRACKER_EMAIL = 'issue_tracker@%s'%MAIL_DOMAIN
144     # The web address that the tracker is viewable at
145     TRACKER_WEB = 'http://your.tracker.url.example/'
147     # The email address that roundup will complain to if it runs into trouble
148     ADMIN_EMAIL = 'roundup-admin@%s'%MAIL_DOMAIN
150     # Send nosy messages to the author of the message
151     MESSAGES_TO_AUTHOR = 'no'           # either 'yes' or 'no'
153     # Does the author of a message get placed on the nosy list automatically?
154     # If 'new' is used, then the author will only be added when a message
155     # creates a new issue. If 'yes', then the author will be added on followups
156     # too. If 'no', they're never added to the nosy.
157     ADD_AUTHOR_TO_NOSY = 'new'          # one of 'yes', 'no', 'new'
159     # Do the recipients (To:, Cc:) of a message get placed on the nosy list?
160     # If 'new' is used, then the recipients will only be added when a message
161     # creates a new issue. If 'yes', then the recipients will be added on followups
162     # too. If 'no', they're never added to the nosy.
163     ADD_RECIPIENTS_TO_NOSY = 'new'      # either 'yes', 'no', 'new'
165     # Where to place the email signature
166     EMAIL_SIGNATURE_POSITION = 'bottom' # one of 'top', 'bottom', 'none'
168     # Keep email citations
169     EMAIL_KEEP_QUOTED_TEXT = 'no'       # either 'yes' or 'no'
171     # Preserve the email body as is
172     EMAIL_LEAVE_BODY_UNCHANGED = 'no'   # either 'yes' or 'no'
174     # Default class to use in the mailgw if one isn't supplied in email
175     # subjects. To disable, comment out the variable below or leave it blank.
176     # Examples:
177     MAIL_DEFAULT_CLASS = 'issue'   # use "issue" class by default
178     #MAIL_DEFAULT_CLASS = ''        # disable (or just comment the var out)
180 Tracker Schema
181 ==============
183 Note: if you modify the schema, you'll most likely need to edit the
184       `web interface`_ HTML template files and `detectors`_ to reflect
185       your changes.
187 A tracker schema defines what data is stored in the tracker's database.
188 Schemas are defined using Python code in the ``dbinit.py`` module of your
189 tracker. The "classic" schema looks like this::
191     pri = Class(db, "priority", name=String(), order=String())
192     pri.setkey("name")
193     pri.create(name="critical", order="1")
194     pri.create(name="urgent", order="2")
195     pri.create(name="bug", order="3")
196     pri.create(name="feature", order="4")
197     pri.create(name="wish", order="5")
199     stat = Class(db, "status", name=String(), order=String())
200     stat.setkey("name")
201     stat.create(name="unread", order="1")
202     stat.create(name="deferred", order="2")
203     stat.create(name="chatting", order="3")
204     stat.create(name="need-eg", order="4")
205     stat.create(name="in-progress", order="5")
206     stat.create(name="testing", order="6")
207     stat.create(name="done-cbb", order="7")
208     stat.create(name="resolved", order="8")
210     keyword = Class(db, "keyword", name=String())
211     keyword.setkey("name")
213     user = Class(db, "user", username=String(), password=String(),
214         address=String(), realname=String(), phone=String(),
215         organisation=String())
216     user.setkey("username")
217     user.create(username="admin", password=adminpw,
218         address=config.ADMIN_EMAIL)
220     msg = FileClass(db, "msg", author=Link("user"), recipients=Multilink
221         ("user"), date=Date(), summary=String(), files=Multilink("file"))
223     file = FileClass(db, "file", name=String(), type=String())
225     issue = IssueClass(db, "issue", assignedto=Link("user"),
226         topic=Multilink("keyword"), priority=Link("priority"), status=Link
227         ("status"))
228     issue.setkey('title')
230 XXX security definitions
232 Classes and Properties - creating a new information store
233 ---------------------------------------------------------
235 In the tracker above, we've defined 7 classes of information:
237   priority
238       Defines the possible levels of urgency for issues.
240   status
241       Defines the possible states of processing the issue may be in.
243   keyword
244       Initially empty, will hold keywords useful for searching issues.
246   user
247       Initially holding the "admin" user, will eventually have an entry for all
248       users using roundup.
250   msg
251       Initially empty, will all e-mail messages sent to or generated by
252       roundup.
254   file
255       Initially empty, will all files attached to issues.
257   issue
258       Initially empty, this is where the issue information is stored.
260 We define the "priority" and "status" classes to allow two things: reduction in
261 the amount of information stored on the issue and more powerful, accurate
262 searching of issues by priority and status. By only requiring a link on the
263 issue (which is stored as a single number) we reduce the chance that someone
264 mis-types a priority or status - or simply makes a new one up.
266 Class and Items
267 ~~~~~~~~~~~~~~~
269 A Class defines a particular class (or type) of data that will be stored in the
270 database. A class comprises one or more properties, which given the information
271 about the class items.
272 The actual data entered into the database, using class.create() are called
273 items. They have a special immutable property called id. We sometimes refer to
274 this as the itemid.
276 Properties
277 ~~~~~~~~~~
279 A Class is comprised of one or more properties of the following types:
281 * String properties are for storing arbitrary-length strings.
282 * Password properties are for storing encoded arbitrary-length strings. The
283   default encoding is defined on the roundup.password.Password class.
284 * Date properties store date-and-time stamps. Their values are Timestamp
285   objects.
286 * Number properties store numeric values.
287 * Boolean properties store on/off, yes/no, true/false values.
288 * A Link property refers to a single other item selected from a specified
289   class. The class is part of the property; the value is an integer, the id
290   of the chosen item.
291 * A Multilink property refers to possibly many items in a specified class.
292   The value is a list of integers.
294 FileClass
295 ~~~~~~~~~
297 FileClasses save their "content" attribute off in a separate file from the rest
298 of the database. This reduces the number of large entries in the database,
299 which generally makes databases more efficient, and also allows us to use
300 command-line tools to operate on the files. They are stored in the files sub-
301 directory of the db directory in your tracker.
303 IssueClass
304 ~~~~~~~~~~
306 IssueClasses automatically include the "messages", "files", "nosy", and
307 "superseder" properties.
308 The messages and files properties list the links to the messages and files
309 related to the issue. The nosy property is a list of links to users who wish to
310 be informed of changes to the issue - they get "CC'ed" e-mails when messages
311 are sent to or generated by the issue. The nosy reactor (in the detectors
312 directory) handles this action. The superceder link indicates an issue which
313 has superceded this one.
314 They also have the dynamically generated "creation", "activity" and "creator"
315 properties.
316 The value of the "creation" property is the date when an item was created, and
317 the value of the "activity" property is the date when any property on the item
318 was last edited (equivalently, these are the dates on the first and last
319 records in the item's journal). The "creator" property holds a link to the user
320 that created the issue.
322 setkey(property)
323 ~~~~~~~~~~~~~~~~
325 Select a String property of the class to be the key property. The key property
326 muse be unique, and allows references to the items in the class by the content
327 of the key property. That is, we can refer to users by their username, e.g.
328 let's say that there's an issue in roundup, issue 23. There's also a user,
329 richard who happens to be user 2. To assign an issue to him, we could do either
330 of::
332      roundup-admin set issue assignedto=2
334 or::
336      roundup-admin set issue assignedto=richard
338 Note, the same thing can be done in the web and e-mail interfaces.
340 create(information)
341 ~~~~~~~~~~~~~~~~~~~
343 Create an item in the database. This is generally used to create items in the
344 "definitional" classes like "priority" and "status".
347 Examples of adding to your schema
348 ---------------------------------
350 TODO
353 Detectors - adding behaviour to your tracker
354 ============================================
355 .. _detectors:
357 Detectors are initialised every time you open your tracker database, so you're
358 free to add and remove them any time, even after the database is initliased
359 via the "roundup-admin initalise" command.
361 The detectors in your tracker fire before (*auditors*) and after (*reactors*)
362 changes to the contents of your database. They are Python modules that sit in
363 your tracker's ``detectors`` directory. You will have some installed by
364 default - have a look. You can write new detectors or modify the existing
365 ones. The existing detectors installed for you are:
367 **nosyreaction.py**
368   This provides the automatic nosy list maintenance and email sending. The nosy
369   reactor (``nosyreaction``) fires when new messages are added to issues.
370   The nosy auditor (``updatenosy``) fires when issues are changed and figures
371   what changes need to be made to the nosy list (like adding new authors etc)
372 **statusauditor.py**
373   This provides the ``chatty`` auditor which changes the issue status from
374   ``unread`` or ``closed`` to ``chatting`` if new messages appear. It also
375   provides the ``presetunread`` auditor which pre-sets the status to
376   ``unread`` on new items if the status isn't explicitly defined.
378 See the detectors section in the `design document`__ for details of the
379 interface for detectors.
381 __ design.html
383 Sample additional detectors that have been found useful will appear in the
384 ``detectors`` directory of the Roundup distribution:
386 **newissuecopy.py**
387   This detector sends an email to a team address whenever a new issue is
388   created. The address is hard-coded into the detector, so edit it before you
389   use it (look for the text 'team@team.host') or you'll get email errors!
391   The detector code::
393     from roundup import roundupdb
395     def newissuecopy(db, cl, nodeid, oldvalues):
396         ''' Copy a message about new issues to a team address.
397         '''
398         # so use all the messages in the create
399         change_note = cl.generateCreateNote(nodeid)
401         # send a copy to the nosy list
402         for msgid in cl.get(nodeid, 'messages'):
403             try:
404                 # note: last arg must be a list
405                 cl.send_message(nodeid, msgid, change_note, ['team@team.host'])
406             except roundupdb.MessageSendError, message:
407                 raise roundupdb.DetectorError, message
409     def init(db):
410         db.issue.react('create', newissuecopy)
413 Database Content
414 ================
416 Note: if you modify the content of definitional classes, you'll most likely
417        need to edit the tracker `detectors`_ to reflect your changes.
419 Customisation of the special "definitional" classes (eg. status, priority,
420 resolution, ...) may be done either before or after the tracker is
421 initialised. The actual method of doing so is completely different in each
422 case though, so be careful to use the right one.
424 **Changing content before tracker initialisation**
425     Edit the dbinit module in your tracker to alter the items created in using
426     the create() methods.
428 **Changing content after tracker initialisation**
429     Use the roundup-admin interface's create, set and retire methods to add,
430     alter or remove items from the classes in question.
433 See "`adding a new field to the classic schema`_" for an example that requires
434 database content changes.
437 Web Interface
438 =============
440 .. contents::
441    :local:
442    :depth: 1
444 The web is provided by the roundup.cgi.client module and is used by
445 roundup.cgi, roundup-server and ZRoundup.
446 In all cases, we determine which tracker is being accessed
447 (the first part of the URL path inside the scope of the CGI handler) and pass
448 control on to the tracker interfaces.Client class - which uses the Client class
449 from roundup.cgi.client - which handles the rest of
450 the access through its main() method. This means that you can do pretty much
451 anything you want as a web interface to your tracker.
453 Repurcussions of changing the tracker schema
454 ---------------------------------------------
456 If you choose to change the `tracker schema`_ you will need to ensure the web
457 interface knows about it:
459 1. Index, item and search pages for the relevant classes may need to have
460    properties added or removed,
461 2. The "page" template may require links to be changed, as might the "home"
462    page's content arguments.
464 How requests are processed
465 --------------------------
467 The basic processing of a web request proceeds as follows:
469 1. figure out who we are, defaulting to the "anonymous" user
470 2. figure out what the request is for - we call this the "context"
471 3. handle any requested action (item edit, search, ...)
472 4. render the template requested by the context, resulting in HTML output
474 In some situations, exceptions occur:
476 - HTTP Redirect  (generally raised by an action)
477 - SendFile       (generally raised by determine_context)
478   here we serve up a FileClass "content" property
479 - SendStaticFile (generally raised by determine_context)
480   here we serve up a file from the tracker "html" directory
481 - Unauthorised   (generally raised by an action)
482   here the action is cancelled, the request is rendered and an error
483   message is displayed indicating that permission was not
484   granted for the action to take place
485 - NotFound       (raised wherever it needs to be)
486   this exception percolates up to the CGI interface that called the client
488 Determining web context
489 -----------------------
491 To determine the "context" of a request, we look at the URL and the special
492 request variable ``:template``. The URL path after the tracker identifier
493 is examined. Typical URL paths look like:
495 1.  ``/tracker/issue``
496 2.  ``/tracker/issue1``
497 3.  ``/tracker/_file/style.css``
498 4.  ``/cgi-bin/roundup.cgi/tracker/file1``
499 5.  ``/cgi-bin/roundup.cgi/tracker/file1/kitten.png``
501 where the "tracker identifier" is "tracker" in the above cases. That means
502 we're looking at "issue", "issue1", "_file/style.css", "file1" and
503 "file1/kitten.png" in the cases above. The path is generally only one
504 entry long - longer paths are handled differently.
506 a. if there is no path, then we are in the "home" context.
507 b. if the path starts with "_file" (as in example 3,
508    "/tracker/_file/style.css"), then the additional path entry,
509    "style.css" specifies the filename of a static file we're to serve up
510    from the tracker "html" directory. Raises a SendStaticFile
511    exception.
512 c. if there is something in the path (as in example 1, "issue"), it identifies
513    the tracker class we're to display.
514 d. if the path is an item designator (as in examples 2 and 4, "issue1" and
515    "file1"), then we're to display a specific item.
516 e. if the path starts with an item designator and is longer than
517    one entry (as in example 5, "file1/kitten.png"), then we're assumed
518    to be handling an item of a
519    FileClass, and the extra path information gives the filename
520    that the client is going to label the download with (ie
521    "file1/kitten.png" is nicer to download than "file1"). This
522    raises a SendFile exception.
524 Both b. and e. stop before we bother to
525 determine the template we're going to use. That's because they
526 don't actually use templates.
528 The template used is specified by the ``:template`` CGI variable,
529 which defaults to:
531 - only classname suplied:          "index"
532 - full item designator supplied:   "item"
535 Performing actions in web requests
536 ----------------------------------
538 When a user requests a web page, they may optionally also request for an
539 action to take place. As described in `how requests are processed`_, the
540 action is performed before the requested page is generated. Actions are
541 triggered by using a ``:action`` CGI variable, where the value is one of:
543 **login**
544  Attempt to log a user in.
545 **logout**
546  Log the user out - make them "anonymous".
547 **register**
548  Attempt to create a new user based on the contents of the form and then log
549  them in.
550 **edit**
551  Perform an edit of an item in the database. There are some special form
552  elements you may use:
554  :link=designator:property and :multilink=designator:property
555   The value specifies an item designator and the property on that
556   item to add _this_ item to as a link or multilink.
557  :note
558   Create a message and attach it to the current item's
559   "messages" property.
560  :file
561   Create a file and attach it to the current item's
562   "files" property. Attach the file to the message created from
563   the :note if it's supplied.
564  :required=property,property,...
565   The named properties are required to be filled in the form.
567 **new**
568  Add a new item to the database. You may use the same special form elements
569  as in the "edit" action.
571 **editCSV**
572  Performs an edit of all of a class' items in one go. See also the
573  *class*.csv templating method which generates the CSV data to be edited, and
574  the "_generic.index" template which uses both of these features.
576 **search**
577  Mangle some of the form variables.
579  Set the form ":filter" variable based on the values of the
580  filter variables - if they're set to anything other than
581  "dontcare" then add them to :filter.
583  Also handle the ":queryname" variable and save off the query to
584  the user's query list.
586 Each of the actions is implemented by a corresponding *actionAction* (where
587 "action" is the name of the action) method on
588 the roundup.cgi.Client class, which also happens to be in your tracker as
589 interfaces.Client. So if you need to define new actions, you may add them
590 there (see `defining new web actions`_).
592 Each action also has a corresponding *actionPermission* (where
593 "action" is the name of the action) method which determines
594 whether the action is permissible given the current user. The base permission
595 checks are:
597 **login**
598  Determine whether the user has permission to log in.
599  Base behaviour is to check the user has "Web Access".
600 **logout**
601  No permission checks are made.
602 **register**
603  Determine whether the user has permission to register
604  Base behaviour is to check the user has "Web Registration".
605 **edit**
606  Determine whether the user has permission to edit this item.
607  Base behaviour is to check the user can edit this class. If we're
608  editing the "user" class, users are allowed to edit their own
609  details. Unless it's the "roles" property, which requires the
610  special Permission "Web Roles".
611 **new**
612  Determine whether the user has permission to create (edit) this item.
613  Base behaviour is to check the user can edit this class. No
614  additional property checks are made. Additionally, new user items
615  may be created if the user has the "Web Registration" Permission.
616 **editCSV**
617  Determine whether the user has permission to edit this class.
618  Base behaviour is to check the user can edit this class.
619 **search**
620  Determine whether the user has permission to search this class.
621  Base behaviour is to check the user can view this class.
624 Default templates
625 -----------------
627 Most customisation of the web view can be done by modifying the templates in
628 the tracker **html** directory. There are several types of files in there:
630 **page**
631   This template usually defines the overall look of your tracker. When you
632   view an issue, it appears inside this template. When you view an index, it
633   also appears inside this template. This template defines a macro called
634   "icing" which is used by almost all other templates as a coating for their
635   content, using its "content" slot. It will also define the "head_title"
636   and "body_title" slots to allow setting of the page title.
637 **home**
638   the default page displayed when no other page is indicated by the user
639 **home.classlist**
640   a special version of the default page that lists the classes in the tracker
641 **classname.item**
642   displays an item of the *classname* class
643 **classname.index**
644   displays a list of *classname* items
645 **classname.search**
646   displays a search page for *classname* items
647 **_generic.index**
648   used to display a list of items where there is no *classname*.index available
649 **_generic.help**
650   used to display a "class help" page where there is no *classname*.help
651 **user.register**
652   a special page just for the user class that renders the registration page
653 **style.css**
654   a static file that is served up as-is
656 Note: Remember that you can create any template extension you want to, so 
657 if you just want to play around with the templating for new issues, you can
658 copy the current "issue.item" template to "issue.test", and then access the
659 test template using the ":template" URL argument::
661    http://your.tracker.example/tracker/issue?:template=test
663 and it won't affect your users using the "issue.item" template.
666 How the templates work
667 ----------------------
669 Basic Templating Actions
670 ~~~~~~~~~~~~~~~~~~~~~~~~
672 Roundup's templates consist of special attributes on your template tags.
673 These attributes form the Template Attribute Language, or TAL. The basic tag
674 commands are:
676 **tal:define="variable expression; variable expression; ..."**
677    Define a new variable that is local to this tag and its contents. For
678    example::
680       <html tal:define="title request/description">
681        <head><title tal:content="title"></title></head>
682       </html>
684    In the example, the variable "title" is defined as being the result of the
685    expression "request/description". The tal:content command inside the <html>
686    tag may then use the "title" variable.
688 **tal:condition="expression"**
689    Only keep this tag and its contents if the expression is true. For example::
691      <p tal:condition="python:request.user.hasPermission('View', 'issue')">
692       Display some issue information.
693      </p>
695    In the example, the <p> tag and its contents are only displayed if the
696    user has the View permission for issues. We consider the number zero, a
697    blank string, an empty list, and the built-in variable nothing to be false
698    values. Nearly every other value is true, including non-zero numbers, and
699    strings with anything in them (even spaces!).
701 **tal:repeat="variable expression"**
702    Repeat this tag and its contents for each element of the sequence that the
703    expression returns, defining a new local variable and a special "repeat"
704    variable for each element. For example::
706      <tr tal:repeat="u user/list">
707       <td tal:content="u/id"></td>
708       <td tal:content="u/username"></td>
709       <td tal:content="u/realname"></td>
710      </tr>
712    The example would iterate over the sequence of users returned by
713    "user/list" and define the local variable "u" for each entry.
715 **tal:replace="expression"**
716    Replace this tag with the result of the expression. For example::
718     <span tal:replace="request/user/realname"></span>
720    The example would replace the <span> tag and its contents with the user's
721    realname. If the user's realname was "Bruce" then the resultant output
722    would be "Bruce".
724 **tal:content="expression"**
725    Replace the contents of this tag with the result of the expression. For
726    example::
728     <span tal:content="request/user/realname">user's name appears here</span>
730    The example would replace the contents of the <span> tag with the user's
731    realname. If the user's realname was "Bruce" then the resultant output
732    would be "<span>Bruce</span>".
734 **tal:attributes="attribute expression; attribute expression; ..."**
735    Set attributes on this tag to the results of expressions. For example::
737      <a tal:attributes="href string:user${request/user/id}">My Details</a>
739    In the example, the "href" attribute of the <a> tag is set to the value of
740    the "string:user${request/user/id}" expression, which will be something
741    like "user123".
743 **tal:omit-tag="expression"**
744    Remove this tag (but not its contents) if the expression is true. For
745    example::
747       <span tal:omit-tag="python:1">Hello, world!</span>
749    would result in output of::
751       Hello, world!
753 Note that the commands on a given tag are evaulated in the order above, so
754 *define* comes before *condition*, and so on.
756 Additionally, a tag is defined, tal:block, which is removed from output. Its
757 content is not, but the tag itself is (so don't go using any tal:attributes
758 commands on it). This is useful for making arbitrary blocks of HTML
759 conditional or repeatable (very handy for repeating multiple table rows,
760 which would othewise require an illegal tag placement to effect the repeat).
763 Templating Expressions
764 ~~~~~~~~~~~~~~~~~~~~~~
766 The expressions you may use in the attibute values may be one of the following
767 forms:
769 **Path Expressions** - eg. ``item/status/checklist``
770    These are object attribute / item accesses. Roughly speaking, the path
771    ``item/status/checklist`` is broken into parts ``item``, ``status``
772    and ``checklist``. The ``item`` part is the root of the expression.
773    We then look for a ``status`` attribute on ``item``, or failing that, a
774    ``status`` item (as in ``item['status']``). If that
775    fails, the path expression fails. When we get to the end, the object we're
776    left with is evaluated to get a string - methods are called, objects are
777    stringified. Path expressions may have an optional ``path:`` prefix, though
778    they are the default expression type, so it's not necessary.
780    XXX | components of expressions
782    XXX "nothing" and "default"
784 **String Expressions** - eg. ``string:hello ${user/name}``
785    These expressions are simple string interpolations (though they can be just
786    plain strings with no interpolation if you want. The expression in the
787    ``${ ... }`` is just a path expression as above.
789 **Python Expressions** - eg. ``python: 1+1``
790    These expressions give the full power of Python. All the "root level"
791    variables are available, so ``python:item.status.checklist()`` would be
792    equivalent to ``item/status/checklist``, assuming that ``checklist`` is
793    a method.
795 Template Macros
796 ~~~~~~~~~~~~~~~
798 Macros are used in Roundup to save us from repeating the same common page
799 stuctures over and over. The most common (and probably only) macro you'll use
800 is the "icing" macro defined in the "page" template.
802 Macros are generated and used inside your templates using special attributes
803 similar to the `basic templating actions`_. In this case though, the
804 attributes belong to the Macro Expansion Template Attribute Language, or
805 METAL. The macro commands are:
807 **metal:define-macro="macro name"**
808   Define that the tag and its contents are now a macro that may be inserted
809   into other templates using the *use-macro* command. For example::
811     <html metal:define-macro="page">
812      ...
813     </html>
815   defines a macro called "page" using the ``<html>`` tag and its contents.
816   Once defined, macros are stored on the template they're defined on in the
817   ``macros`` attribute. You can access them later on through the ``templates``
818   variable, eg. the most common ``templates/page/macros/icing`` to access the
819   "page" macro of the "page" template.
821 **metal:use-macro="path expression"**
822   Use a macro, which is identified by the path expression (see above). This
823   will replace the current tag with the identified macro contents. For
824   example::
826    <tal:block metal:use-macro="templates/page/macros/icing">
827     ...
828    </tal:block>
830    will replace the tag and its contents with the "page" macro of the "page"
831    template.
833 **metal:define-slot="slot name"** and **metal:fill-slot="slot name"**
834   To define *dynamic* parts of the macro, you define "slots" which may be 
835   filled when the macro is used with a *use-macro* command. For example, the
836   ``templates/page/macros/icing`` macro defines a slot like so::
838     <title metal:define-slot="head_title">title goes here</title>
840   In your *use-macro* command, you may now use a *fill-slot* command like
841   this::
843     <title metal:fill-slot="head_title">My Title</title>
845   where the tag that fills the slot completely replaces the one defined as
846   the slot in the macro.
848 Note that you may not mix METAL and TAL commands on the same tag, but TAL
849 commands may be used freely inside METAL-using tags (so your *fill-slots*
850 tags may have all manner of TAL inside them).
853 Information available to templates
854 ----------------------------------
856 Note: this is implemented by roundup.cgi.templating.RoundupPageTemplate
858 The following variables are available to templates.
860 **context**
861   The current context. This is either None, a
862   `hyperdb class wrapper`_ or a `hyperdb item wrapper`_
863 **request**
864   Includes information about the current request, including:
865    - the url
866    - the current index information (``filterspec``, ``filter`` args,
867      ``properties``, etc) parsed out of the form. 
868    - methods for easy filterspec link generation
869    - *user*, the current user item as an HTMLItem instance
870    - *form*
871      The current CGI form information as a mapping of form argument
872      name to value
873 **tracker**
874   The current tracker
875 **db**
876   The current database, through which db.config may be reached.
877 **templates**
878   Access to all the tracker templates by name. Used mainly in *use-macro*
879   commands.
880 **utils**
881   This variable makes available some utility functions like batching.
882 **nothing**
883   This is a special variable - if an expression evaluates to this, then the
884   tag (in the case of a tal:replace), its contents (in the case of
885   tal:content) or some attributes (in the case of tal:attributes) will not
886   appear in the the output. So for example::
888     <span tal:attributes="class nothing">Hello, World!</span>
890   would result in::
892     <span>Hello, World!</span>
894 **default**
895   Also a special variable - if an expression evaluates to this, then the
896   existing HTML in the template will not be replaced or removed, it will
897   remain. So::
899     <span tal:replace="default">Hello, World!</span>
901   would result in::
903     <span>Hello, World!</span>
905 The context variable
906 ~~~~~~~~~~~~~~~~~~~~
908 The *context* variable is one of three things based on the current context
909 (see `determining web context`_ for how we figure this out):
911 1. if we're looking at a "home" page, then it's None
912 2. if we're looking at a specific hyperdb class, it's a
913    `hyperdb class wrapper`_.
914 3. if we're looking at a specific hyperdb item, it's a
915    `hyperdb item wrapper`_.
917 If the context is not None, we can access the properties of the class or item.
918 The only real difference between cases 2 and 3 above are:
920 1. the properties may have a real value behind them, and this will appear if
921    the property is displayed through ``context/property`` or
922    ``context/property/field``.
923 2. the context's "id" property will be a false value in the second case, but
924    a real, or true value in the third. Thus we can determine whether we're
925    looking at a real item from the hyperdb by testing "context/id".
927 Hyperdb class wrapper
928 :::::::::::::::::::::
930 Note: this is implemented by the roundup.cgi.templating.HTMLClass class.
932 This wrapper object provides access to a hyperb class. It is used primarily
933 in both index view and new item views, but it's also usable anywhere else that
934 you wish to access information about a class, or the items of a class, when
935 you don't have a specific item of that class in mind.
937 We allow access to properties. There will be no "id" property. The value
938 accessed through the property will be the current value of the same name from
939 the CGI form.
941 There are several methods available on these wrapper objects:
943 =========== =============================================================
944 Method      Description
945 =========== =============================================================
946 properties  return a `hyperdb property wrapper`_ for all of this class'
947             properties.
948 list        lists all of the active (not retired) items in the class.
949 csv         return the items of this class as a chunk of CSV text.
950 propnames   lists the names of the properties of this class.
951 filter      lists of items from this class, filtered and sorted
952             by the current *request* filterspec/filter/sort/group args
953 classhelp   display a link to a javascript popup containing this class'
954             "help" template.
955 submit      generate a submit button (and action hidden element)
956 renderWith  render this class with the given template.
957 history     returns 'New node - no history' :)
958 is_edit_ok  is the user allowed to Edit the current class?
959 is_view_ok  is the user allowed to View the current class?
960 =========== =============================================================
962 Note that if you have a property of the same name as one of the above methods,
963 you'll need to access it using a python "item access" expression. For example::
965    python:context['list']
967 will access the "list" property, rather than the list method.
970 Hyperdb item wrapper
971 ::::::::::::::::::::
973 Note: this is implemented by the roundup.cgi.templating.HTMLItem class.
975 This wrapper object provides access to a hyperb item.
977 We allow access to properties. There will be no "id" property. The value
978 accessed through the property will be the current value of the same name from
979 the CGI form.
981 There are several methods available on these wrapper objects:
983 =============== =============================================================
984 Method          Description
985 =============== =============================================================
986 submit          generate a submit button (and action hidden element)
987 journal         return the journal of the current item (**not implemented**)
988 history         render the journal of the current item as HTML
989 renderQueryForm specific to the "query" class - render the search form for
990                 the query
991 hasPermission   specific to the "user" class - determine whether the user
992                 has a Permission
993 is_edit_ok      is the user allowed to Edit the current item?
994 is_view_ok      is the user allowed to View the current item?
995 =============== =============================================================
998 Note that if you have a property of the same name as one of the above methods,
999 you'll need to access it using a python "item access" expression. For example::
1001    python:context['journal']
1003 will access the "journal" property, rather than the journal method.
1006 Hyperdb property wrapper
1007 ::::::::::::::::::::::::
1009 Note: this is implemented by subclasses roundup.cgi.templating.HTMLProperty
1010 class (HTMLStringProperty, HTMLNumberProperty, and so on).
1012 This wrapper object provides access to a single property of a class. Its
1013 value may be either:
1015 1. if accessed through a `hyperdb item wrapper`_, then it's a value from the
1016    hyperdb
1017 2. if access through a `hyperdb class wrapper`_, then it's a value from the
1018    CGI form
1021 The property wrapper has some useful attributes:
1023 =============== =============================================================
1024 Attribute       Description
1025 =============== =============================================================
1026 _name           the name of the property
1027 _value          the value of the property if any
1028 =============== =============================================================
1030 There are several methods available on these wrapper objects:
1032 =========== =================================================================
1033 Method      Description
1034 =========== =================================================================
1035 plain       render a "plain" representation of the property
1036 field       render a form edit field for the property
1037 stext       only on String properties - render the value of the
1038             property as StructuredText (requires the StructureText module
1039             to be installed separately)
1040 multiline   only on String properties - render a multiline form edit
1041             field for the property
1042 email       only on String properties - render the value of the 
1043             property as an obscured email address
1044 confirm     only on Password properties - render a second form edit field for
1045             the property, used for confirmation that the user typed the
1046             password correctly. Generates a field with name "name:confirm".
1047 reldate     only on Date properties - render the interval between the
1048             date and now
1049 pretty      only on Interval properties - render the interval in a
1050             pretty format (eg. "yesterday")
1051 menu        only on Link and Multilink properties - render a form select
1052             list for this property
1053 reverse     only on Multilink properties - produce a list of the linked
1054             items in reverse order
1055 =========== =================================================================
1057 The request variable
1058 ~~~~~~~~~~~~~~~~~~~~
1060 Note: this is implemented by the roundup.cgi.templating.HTMLRequest class.
1062 The request variable is packed with information about the current request.
1064 .. taken from roundup.cgi.templating.HTMLRequest docstring
1066 =========== =================================================================
1067 Variable    Holds
1068 =========== =================================================================
1069 form        the CGI form as a cgi.FieldStorage
1070 env         the CGI environment variables
1071 url         the current URL path for this request
1072 base        the base URL for this tracker
1073 user        a HTMLUser instance for this user
1074 classname   the current classname (possibly None)
1075 template    the current template (suffix, also possibly None)
1076 form        the current CGI form variables in a FieldStorage
1077 =========== =================================================================
1079 **Index page specific variables (indexing arguments)**
1081 =========== =================================================================
1082 Variable    Holds
1083 =========== =================================================================
1084 columns     dictionary of the columns to display in an index page
1085 show        a convenience access to columns - request/show/colname will
1086             be true if the columns should be displayed, false otherwise
1087 sort        index sort column (direction, column name)
1088 group       index grouping property (direction, column name)
1089 filter      properties to filter the index on
1090 filterspec  values to filter the index on
1091 search_text text to perform a full-text search on for an index
1092 =========== =================================================================
1094 There are several methods available on the request variable:
1096 =============== =============================================================
1097 Method          Description
1098 =============== =============================================================
1099 description     render a description of the request - handle for the page
1100                 title
1101 indexargs_form  render the current index args as form elements
1102 indexargs_url   render the current index args as a URL
1103 base_javascript render some javascript that is used by other components of
1104                 the templating
1105 batch           run the current index args through a filter and return a
1106                 list of items (see `hyperdb item wrapper`_, and
1107                 `batching`_)
1108 =============== =============================================================
1110 The form variable
1111 :::::::::::::::::
1113 The form variable is a little special because it's actually a python
1114 FieldStorage object. That means that you have two ways to access its
1115 contents. For example, to look up the CGI form value for the variable
1116 "name", use the path expression::
1118    request/form/name/value
1120 or the python expression::
1122    python:request.form['name'].value
1124 Note the "item" access used in the python case, and also note the explicit
1125 "value" attribute we have to access. That's because the form variables are
1126 stored as MiniFieldStorages. If there's more than one "name" value in
1127 the form, then the above will break since ``request/form/name`` is actually a
1128 *list* of MiniFieldStorages. So it's best to know beforehand what you're
1129 dealing with.
1132 The db variable
1133 ~~~~~~~~~~~~~~~
1135 Note: this is implemented by the roundup.cgi.templating.HTMLDatabase class.
1137 Allows access to all hyperdb classes as attributes of this variable. If you
1138 want access to the "user" class, for example, you would use::
1140   db/user
1141   python:db.user
1143 The access results in a `hyperdb class wrapper`_.
1145 The templates variable
1146 ~~~~~~~~~~~~~~~~~~~~~~
1148 Note: this is implemented by the roundup.cgi.templating.Templates class.
1150 This variable doesn't have any useful methods defined. It supports being
1151 used in expressions to access the templates, and subsequently the template
1152 macros. You may access the templates using the following path expression::
1154    templates/name
1156 or the python expression::
1158    templates[name]
1160 where "name" is the name of the template you wish to access. The template you
1161 get access to has one useful attribute, "macros". To access a specific macro
1162 (called "macro_name"), use the path expression::
1164    templates/name/macros/macro_name
1166 or the python expression::
1168    templates[name].macros[macro_name]
1171 The utils variable
1172 ~~~~~~~~~~~~~~~~~~
1174 Note: this is implemented by the roundup.cgi.templating.TemplatingUtils class.
1176 =============== =============================================================
1177 Method          Description
1178 =============== =============================================================
1179 Batch           return a batch object using the supplied list
1180 =============== =============================================================
1182 Batching
1183 ::::::::
1185 Use Batch to turn a list of items, or item ids of a given class, into a series
1186 of batches. Its usage is::
1188     python:util.Batch(sequence, size, start, end=0, orphan=0, overlap=0)
1190 or, to get the current index batch::
1192     request/batch
1194 The parameters are:
1196 ========= ==================================================================
1197 Parameter  Usage
1198 ========= ==================================================================
1199 sequence  a list of HTMLItems
1200 size      how big to make the sequence.
1201 start     where to start (0-indexed) in the sequence.
1202 end       where to end (0-indexed) in the sequence.
1203 orphan    if the next batch would contain less items than this
1204           value, then it is combined with this batch
1205 overlap   the number of items shared between adjacent batches
1206 ========= ==================================================================
1208 All of the parameters are assigned as attributes on the batch object. In
1209 addition, it has several more attributes:
1211 =============== ============================================================
1212 Attribute       Description
1213 =============== ============================================================
1214 start           indicates the start index of the batch. *Note: unlike the
1215                 argument, is a 1-based index (I know, lame)*
1216 first           indicates the start index of the batch *as a 0-based
1217                 index*
1218 length          the actual number of elements in the batch
1219 sequence_length the length of the original, unbatched, sequence.
1220 =============== ============================================================
1222 And several methods:
1224 =============== ============================================================
1225 Method          Description
1226 =============== ============================================================
1227 previous        returns a new Batch with the previous batch settings
1228 next            returns a new Batch with the next batch settings
1229 propchanged     detect if the named property changed on the current item
1230                 when compared to the last item
1231 =============== ============================================================
1233 An example of batching::
1235  <table class="otherinfo">
1236   <tr><th colspan="4" class="header">Existing Keywords</th></tr>
1237   <tr tal:define="keywords db/keyword/list"
1238       tal:repeat="start python:range(0, len(keywords), 4)">
1239    <td tal:define="batch python:utils.Batch(keywords, 4, start)"
1240        tal:repeat="keyword batch" tal:content="keyword/name">keyword here</td>
1241   </tr>
1242  </table>
1244 ... which will produce a table with four columns containing the items of the
1245 "keyword" class (well, their "name" anyway).
1247 Displaying Properties
1248 ---------------------
1250 Properties appear in the user interface in three contexts: in indices, in
1251 editors, and as search arguments.
1252 For each type of property, there are several display possibilities.
1253 For example, in an index view, a string property may just be
1254 printed as a plain string, but in an editor view, that property may be
1255 displayed in an editable field.
1258 Index Views
1259 -----------
1261 This is one of the class context views. It is also the default view for
1262 classes. The template used is "*classname*.index".
1264 Index View Specifiers
1265 ~~~~~~~~~~~~~~~~~~~~~
1267 An index view specifier (URL fragment) looks like this (whitespace has been
1268 added for clarity)::
1270      /issue?status=unread,in-progress,resolved&
1271             topic=security,ui&
1272             :group=+priority&
1273             :sort==activity&
1274             :filters=status,topic&
1275             :columns=title,status,fixer
1277 The index view is determined by two parts of the specifier: the layout part and
1278 the filter part. The layout part consists of the query parameters that begin
1279 with colons, and it determines the way that the properties of selected items
1280 are displayed. The filter part consists of all the other query parameters, and
1281 it determines the criteria by which items are selected for display.
1282 The filter part is interactively manipulated with the form widgets displayed in
1283 the filter section. The layout part is interactively manipulated by clicking on
1284 the column headings in the table.
1286 The filter part selects the union of the sets of items with values matching any
1287 specified Link properties and the intersection of the sets of items with values
1288 matching any specified Multilink properties.
1290 The example specifies an index of "issue" items. Only items with a "status" of
1291 either "unread" or "in-progres" or "resolved" are displayed, and only items
1292 with "topic" values including both "security" and "ui" are displayed. The items
1293 are grouped by priority, arranged in ascending order; and within groups, sorted
1294 by activity, arranged in descending order. The filter section shows filters for
1295 the "status" and "topic" properties, and the table includes columns for the
1296 "title", "status", and "fixer" properties.
1298 Filtering of indexes
1299 ~~~~~~~~~~~~~~~~~~~~
1301 TODO
1303 Searching Views
1304 ---------------
1306 This is one of the class context views. The template used is typically
1307 "*classname*.search".
1309 TODO
1311 Item Views
1312 ----------
1314 The basic view of a hyperdb item is provided by the "*classname*.item"
1315 template. It generally has three sections; an "editor", a "spool" and a
1316 "history" section.
1320 Editor Section
1321 ~~~~~~~~~~~~~~
1323 The editor section is used to manipulate the item - it may be a
1324 static display if the user doesn't have permission to edit the item.
1326 Here's an example of a basic editor template (this is the default "classic"
1327 template issue item edit form - from the "issue.item" template)::
1329  <table class="form">
1330  <tr>
1331   <th nowrap>Title</th>
1332   <td colspan=3 tal:content="structure python:context.title.field(size=60)">title</td>
1333  </tr>
1334  
1335  <tr>
1336   <th nowrap>Priority</th>
1337   <td tal:content="structure context/priority/menu">priority</td>
1338   <th nowrap>Status</th>
1339   <td tal:content="structure context/status/menu">status</td>
1340  </tr>
1341  
1342  <tr>
1343   <th nowrap>Superseder</th>
1344   <td>
1345    <span tal:replace="structure python:context.superseder.field(showid=1, size=20)" />
1346    <span tal:replace="structure python:db.issue.classhelp('id,title')" />
1347    <span tal:condition="context/superseder">
1348     <br>View: <span tal:replace="structure python:context.superseder.link(showid=1)" />
1349    </span>
1350   </td>
1351   <th nowrap>Nosy List</th>
1352   <td>
1353    <span tal:replace="structure context/nosy/field" />
1354    <span tal:replace="structure python:db.user.classhelp('username,realname,address,phone')" />
1355   </td>
1356  </tr>
1357  
1358  <tr>
1359   <th nowrap>Assigned To</th>
1360   <td tal:content="structure context/assignedto/menu">
1361    assignedto menu
1362   </td>
1363   <td>&nbsp;</td>
1364   <td>&nbsp;</td>
1365  </tr>
1366  
1367  <tr>
1368   <th nowrap>Change Note</th>
1369   <td colspan=3>
1370    <textarea name=":note" wrap="hard" rows="5" cols="60"></textarea>
1371   </td>
1372  </tr>
1373  
1374  <tr>
1375   <th nowrap>File</th>
1376   <td colspan=3><input type="file" name=":file" size="40"></td>
1377  </tr>
1378  
1379  <tr>
1380   <td>&nbsp;</td>
1381   <td colspan=3 tal:content="structure context/submit">
1382    submit button will go here
1383   </td>
1384  </tr>
1385  </table>
1388 When a change is submitted, the system automatically generates a message
1389 describing the changed properties. As shown in the example, the editor
1390 template can use the ":note" and ":file" fields, which are added to the
1391 standard change note message generated by Roundup.
1393 Spool Section
1394 ~~~~~~~~~~~~~
1396 The spool section lists related information like the messages and files of
1397 an issue.
1399 TODO
1402 History Section
1403 ~~~~~~~~~~~~~~~
1405 The final section displayed is the history of the item - its database journal.
1406 This is generally generated with the template::
1408  <tal:block tal:replace="structure context/history" />
1410 *To be done:*
1412 *The actual history entries of the item may be accessed for manual templating
1413 through the "journal" method of the item*::
1415  <tal:block tal:repeat="entry context/journal">
1416   a journal entry
1417  </tal:block>
1419 *where each journal entry is an HTMLJournalEntry.*
1421 Defining new web actions
1422 ------------------------
1424 XXX
1427 Access Controls
1428 ===============
1430 A set of Permissions are built in to the security module by default:
1432 - Edit (everything)
1433 - View (everything)
1435 The default interfaces define:
1437 - Web Registration
1438 - Web Access
1439 - Web Roles
1440 - Email Registration
1441 - Email Access
1443 These are hooked into the default Roles:
1445 - Admin (Edit everything, View everything, Web Roles)
1446 - User (Web Access, Email Access)
1447 - Anonymous (Web Registration, Email Registration)
1449 And finally, the "admin" user gets the "Admin" Role, and the "anonymous" user
1450 gets the "Anonymous" assigned when the database is initialised on installation.
1451 The two default schemas then define:
1453 - Edit issue, View issue (both)
1454 - Edit file, View file (both)
1455 - Edit msg, View msg (both)
1456 - Edit support, View support (extended only)
1458 and assign those Permissions to the "User" Role. New users are assigned the
1459 Roles defined in the config file as:
1461 - NEW_WEB_USER_ROLES
1462 - NEW_EMAIL_USER_ROLES
1464 You may alter the configuration variables to change the Role that new web or
1465 email users get, for example to not give them access to the web interface if
1466 they register through email.
1468 You may use the ``roundup-admin`` "``security``" command to display the
1469 current Role and Permission configuration in your tracker.
1471 Adding a new Permission
1472 -----------------------
1474 When adding a new Permission, you will need to:
1476 1. add it to your tracker's dbinit so it is created
1477 2. enable it for the Roles that should have it (verify with
1478    "``roundup-admin security``")
1479 3. add it to the relevant HTML interface templates
1480 4. add it to the appropriate xxxPermission methods on in your tracker
1481    interfaces module
1483 Example Scenarios
1484 -----------------
1486 **automatic registration of users in the e-mail gateway**
1487  By giving the "anonymous" user the "Email Registration" Role, any
1488  unidentified user will automatically be registered with the tracker (with
1489  no password, so they won't be able to log in through the web until an admin
1490  sets them a password). Note: this is the default behaviour in the tracker
1491  templates that ship with Roundup.
1493 **anonymous access through the e-mail gateway**
1494  Give the "anonymous" user the "Email Access" and ("Edit", "issue") Roles
1495  but not giving them the "Email Registration" Role. This means that when an
1496  unknown user sends email into the tracker, they're automatically logged in
1497  as "anonymous". Since they don't have the "Email Registration" Role, they
1498  won't be automatically registered, but since "anonymous" has permission
1499  to use the gateway, they'll still be able to submit issues. Note that the
1500  Sender information - their email address - will not be available - they're
1501  *anonymous*.
1503 XXX more examples needed
1506 Examples
1507 ========
1509 Adding a new field to the classic schema
1510 ----------------------------------------
1512 This example shows how to add a new constrained property (ie. a selection of
1513 distinct values) to your tracker.
1515 Introduction
1516 ~~~~~~~~~~~~
1518 To make the classic schema of roundup useful as a todo tracking system
1519 for a group of systems administrators, it needed an extra data field
1520 per issue: a category.
1522 This would let sysads quickly list all todos in their particular
1523 area of interest without having to do complex queries, and without
1524 relying on the spelling capabilities of other sysads (a losing
1525 proposition at best).
1527 Adding a field to the database
1528 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1530 This is the easiest part of the change. The category would just be a plain
1531 string, nothing fancy. To change what is in the database you need to add
1532 some lines to the ``open()`` function in ``dbinit.py`` under the comment::
1534     # add any additional database schema configuration here
1536 add::
1538     category = Class(db, "category", name=String())
1539     category.setkey("name")
1541 Here we are setting up a chunk of the database which we are calling
1542 "category". It contains a string, which we are refering to as "name" for
1543 lack of a more imaginative title. Then we are setting the key of this chunk
1544 of the database to be that "name". This is equivalent to an index for
1545 database types. This also means that there can only be one category with a
1546 given name.
1548 Adding the above lines allows us to create categories, but they're not tied
1549 to the issues that we are going to be creating. It's just a list of categories
1550 off on its own, which isn't much use. We need to link it in with the issues.
1551 To do that, find the lines in the ``open()`` function in ``dbinit.py`` which
1552 set up the "issue" class, and then add a link to the category::
1554     issue = IssueClass(db, "issue", ... , category=Multilink("category"), ... )
1556 The Multilink() means that each issue can have many categories. If you were
1557 adding something with a more one to one relationship use Link() instead.
1559 That is all you need to do to change the schema. The rest of the effort is
1560 fiddling around so you can actually use the new category.
1562 Populating the new category class
1563 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1565 If you haven't initialised the database with the roundup-admin "initialise"
1566 command, then you can add the following to the tracker ``dbinit.py`` in the
1567 ``init()`` function under the comment::
1569     # add any additional database create steps here - but only if you
1570     # haven't initialised the database with the admin "initialise" command
1572 add::
1574      category = db.getclass('category')
1575      category.create(name="scipy", order="1")
1576      category.create(name="chaco", order="2")
1577      category.create(name="weave", order="3")
1579 If the database is initalised, the you need to use the roundup-admin tool::
1581      % roundup-admin -i <tracker home>
1582      Roundup <version> ready for input.
1583      Type "help" for help.
1584      roundup> create category name=scipy order=1
1585      1
1586      roundup> create category name=chaco order=1
1587      2
1588      roundup> create category name=weave order=1
1589      3
1590      roundup> exit...
1591      There are unsaved changes. Commit them (y/N)? y
1594 Setting up security on the new objects
1595 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1597 By default only the admin user can look at and change objects. This doesn't
1598 suit us, as we want any user to be able to create new categories as
1599 required, and obviously everyone needs to be able to view the categories of
1600 issues for it to be useful.
1602 We therefore need to change the security of the category objects. This is
1603 also done in the ``open()`` function of ``dbinit.py``.
1605 There are currently two loops which set up permissions and then assign them
1606 to various roles. Simply add the new "category" to both lists::
1608     # new permissions for this schema
1609     for cl in 'issue', 'file', 'msg', 'user', 'category':
1610         db.security.addPermission(name="Edit", klass=cl,
1611             description="User is allowed to edit "+cl)
1612         db.security.addPermission(name="View", klass=cl,
1613             description="User is allowed to access "+cl)
1615     # Assign the access and edit permissions for issue, file and message
1616     # to regular users now
1617     for cl in 'issue', 'file', 'msg', 'category':
1618         p = db.security.getPermission('View', cl)
1619         db.security.addPermissionToRole('User', p)
1620         p = db.security.getPermission('Edit', cl)
1621         db.security.addPermissionToRole('User', p)
1623 So you are in effect doing the following::
1625     db.security.addPermission(name="Edit", klass='category',
1626         description="User is allowed to edit "+'category')
1627     db.security.addPermission(name="View", klass='category',
1628         description="User is allowed to access "+'category')
1630 which is creating two permission types; that of editing and viewing
1631 "category" objects respectively. Then the following lines assign those new
1632 permissions to the "User" role, so that normal users can view and edit
1633 "category" objects::
1635     p = db.security.getPermission('View', 'category')
1636     db.security.addPermissionToRole('User', p)
1638     p = db.security.getPermission('Edit', 'category')
1639     db.security.addPermissionToRole('User', p)
1641 This is all the work that needs to be done for the database. It will store
1642 categories, and let users view and edit them. Now on to the interface
1643 stuff.
1645 Changing the web left hand frame
1646 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1648 We need to give the users the ability to create new categories, and the
1649 place to put the link to this functionality is in the left hand function
1650 bar, under the "Issues" area. The file that defines how this area looks is
1651 ``html/page``, which is what we are going to be editing next.
1653 If you look at this file you can see that it contains a lot of "classblock"
1654 sections which are chunks of HTML that will be included or excluded in the
1655 output depending on whether the condition in the classblock is met. Under
1656 the end of the classblock for issue is where we are going to add the
1657 category code::
1659   <p class="classblock"
1660      tal:condition="python:request.user.hasPermission('View', 'category')">
1661    <b>Categories</b><br>
1662    <a tal:condition="python:request.user.hasPermission('Edit', 'category')"
1663       href="category?:template=item">New Category<br></a>
1664   </p>
1666 The first two lines is the classblock definition, which sets up a condition
1667 that only users who have "View" permission to the "category" object will
1668 have this section included in their output. Next comes a plain "Categories"
1669 header in bold. Everyone who can view categories will get that.
1671 Next comes the link to the editing area of categories. This link will only
1672 appear if the condition is matched: that condition being that the user has
1673 "Edit" permissions for the "category" objects. If they do have permission
1674 then they will get a link to another page which will let the user add new
1675 categories.
1677 Note that if you have permission to view but not edit categories then all
1678 you will see is a "Categories" header with nothing underneath it. This is
1679 obviously not very good interface design, but will do for now. I just claim
1680 that it is so I can add more links in this section later on. However to fix
1681 the problem you could change the condition in the classblock statement, so
1682 that only users with "Edit" permission would see the "Categories" stuff.
1684 Setting up a page to edit categories
1685 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1687 We defined code in the previous section which let users with the
1688 appropriate permissions see a link to a page which would let them edit
1689 conditions. Now we have to write that page.
1691 The link was for the item template for the category object. This translates
1692 into the system looking for a file called ``category.item`` in the ``html``
1693 tracker directory. This is the file that we are going to write now.
1695 First we add an info tag in a comment which doesn't affect the outcome
1696 of the code at all but is useful for debugging. If you load a page in a
1697 browser and look at the page source, you can see which sections come
1698 from which files by looking for these comments::
1700     <!-- category.item -->
1702 Next we need to add in the METAL macro stuff so we get the normal page
1703 trappings::
1705  <tal:block metal:use-macro="templates/page/macros/icing">
1706   <title metal:fill-slot="head_title">Category editing</title>
1707   <td class="page-header-top" metal:fill-slot="body_title">
1708    <h2>Category editing</h2>
1709   </td>
1710   <td class="content" metal:fill-slot="content">
1712 Next we need to setup up a standard HTML form, which is the whole
1713 purpose of this file. We link to some handy javascript which sends the form
1714 through only once. This is to stop users hitting the send button
1715 multiple times when they are impatient and thus having the form sent
1716 multiple times::
1718     <form method="POST" onSubmit="return submit_once()"
1719           enctype="multipart/form-data">
1721 Next we define some code which sets up the minimum list of fields that we
1722 require the user to enter. There will be only one field, that of "name", so
1723 they user better put something in it otherwise the whole form is pointless::
1725     <input type="hidden" name=":required" value="name">
1727 To get everything to line up properly we will put everything in a table,
1728 and put a nice big header on it so the user has an idea what is happening::
1730     <table class="form">
1731      <tr><th class="header" colspan=2>Category</th></tr>
1733 Next we need the actual field that the user is going to enter the new
1734 category. The "context.name.field(size=60)" bit tells roundup to generate a
1735 normal HTML field of size 60, and the contents of that field will be the
1736 "name" variable of the current context (which is "category"). The upshot of
1737 this is that when the user types something in to the form, a new category
1738 will be created with that name::
1740     <tr>
1741      <th nowrap>Name</th>
1742      <td tal:content="structure python:context.name.field(size=60)">name</td>
1743     </tr>
1745 Then a submit button so that the user can submit the new category::
1747     <tr>
1748      <td>&nbsp;</td>
1749      <td colspan=3 tal:content="structure context/submit">
1750       submit button will go here
1751      </td>
1752     </tr>
1754 Finally we finish off the tags we used at the start to do the METAL stuff::
1756   </td>
1757  </tal:block>
1759 So putting it all together, and closing the table and form we get::
1761  <!-- category.item -->
1762  <tal:block metal:use-macro="templates/page/macros/icing">
1763   <title metal:fill-slot="head_title">Category editing</title>
1764   <td class="page-header-top" metal:fill-slot="body_title">
1765    <h2>Category editing</h2>
1766   </td>
1767   <td class="content" metal:fill-slot="content">
1768    <form method="POST" onSubmit="return submit_once()"
1769          enctype="multipart/form-data">
1771     <input type="hidden" name=":required" value="name">
1773     <table class="form">
1774      <tr><th class="header" colspan=2>Category</th></tr>
1776      <tr>
1777       <th nowrap>Name</th>
1778       <td tal:content="structure python:context.name.field(size=60)">name</td>
1779      </tr>
1781      <tr>
1782       <td>&nbsp;</td>
1783       <td colspan=3 tal:content="structure context/submit">
1784        submit button will go here
1785       </td>
1786      </tr>
1787     </table>
1788    </form>
1789   </td>
1790  </tal:block>
1792 This is quite a lot to just ask the user one simple question, but
1793 there is a lot of setup for basically one line (the form line) to do
1794 its work. To add another field to "category" would involve one more line
1795 (well maybe a few extra to get the formatting correct).
1797 Adding the category to the issue
1798 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1800 We now have the ability to create issues to our hearts content, but
1801 that is pointless unless we can assign categories to issues.  Just like
1802 the ``html/category.item`` file was used to define how to add a new
1803 category, the ``html/issue.item`` is used to define how a new issue is
1804 created.
1806 Just like ``category.issue`` this file defines a form which has a table to lay
1807 things out. It doesn't matter where in the table we add new stuff,
1808 it is entirely up to your sense of aesthetics::
1810    <th nowrap>Category</th>
1811    <td><span tal:replace="structure context/category/field" />
1812        <span tal:replace="structure db/category/classhelp" />
1813    </td>
1815 First we define a nice header so that the user knows what the next section
1816 is, then the middle line does what we are most interested in. This
1817 ``context/category/field`` gets replaced with a field which contains the
1818 category in the current context (the current context being the new issue).
1820 The classhelp lines generate a link (labelled "list") to a popup window
1821 which contains the list of currently known categories.
1823 Searching on categories
1824 ~~~~~~~~~~~~~~~~~~~~~~~
1826 We can add categories, and create issues with categories. The next obvious
1827 thing that we would like to be would be to search issues based on their
1828 category, so that any one working on the web server could look at all
1829 issues in the category "Web" for example.
1831 If you look in the html/page file and look for the "Search Issues" you will
1832 see that it looks something like ``<a href="issue?:template=search">Search
1833 Issues</a>`` which shows us that when you click on "Search Issues" it will
1834 be looking for a ``issue.search`` file to display. So that is indeed the file
1835 that we are going to change.
1837 If you look at this file it should be starting to seem familiar. It is a
1838 simple HTML form using a table to define structure. You can add the new
1839 category search code anywhere you like within that form::
1841     <tr>
1842      <th>Category:</th>
1843      <td>
1844       <select name="category">
1845        <option value="">don't care</option>
1846        <option value="">------------</option>
1847        <option tal:repeat="s db/category/list" tal:attributes="value s/name"
1848                tal:content="s/name">category to filter on</option>
1849       </select>
1850      </td>
1851      <td><input type="checkbox" name=":columns" value="category" checked></td>
1852      <td><input type="radio" name=":sort" value="category"></td>
1853      <td><input type="radio" name=":group" value="category"></td>
1854     </tr>
1856 Most of this is straightforward to anyone who knows HTML. It is just
1857 setting up a select list followed by a checkbox and a couple of radio
1858 buttons. 
1860 The ``tal:repeat`` part repeats the tag for every item in the "category"
1861 table and setting "s" to be each category in turn.
1863 The ``tal:attributes`` part is setting up the ``value=`` part of the option tag
1864 to be the name part of "s" which is the current category in the loop.
1866 The ``tal:content`` part is setting the contents of the option tag to be the
1867 name part of "s" again. For objects more complex than category, obviously
1868 you would put an id in the value, and the descriptive part in the content;
1869 but for category they are the same.
1871 Adding category to the default view
1872 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1874 We can now add categories, add issues with categories, and search issues
1875 based on categories. This is everything that we need to do, however there
1876 is some more icing that we would like. I think the category of an issue is
1877 important enough that it should be displayed by default when listing all
1878 the issues.
1880 Unfortunately, this is a bit less obvious than the previous steps. The code
1881 defining how the issues look is in ``html/issue.index``. This is a large table
1882 with a form down the bottom for redisplaying and so forth. 
1884 Firstly we need to add an appropriate header to the start of the table::
1886     <th tal:condition="request/show/category">Category</th>
1888 The condition part of this statement is so that if the user has selected
1889 not to see the Category column then they won't.
1891 The rest of the table is a loop which will go through every issue that
1892 matches the display criteria. The loop variable is "i" - which means that
1893 every issue gets assigned to "i" in turn.
1895 The new part of code to display the category will look like this::
1897     <td tal:condition="request/show/category" tal:content="i/category"></td>
1899 The condition is the same as above: only display the condition when the
1900 user hasn't asked for it to be hidden. The next part is to set the content
1901 of the cell to be the category part of "i" - the current issue.
1903 Finally we have to edit ``html/page`` again. This time to tell it that when the
1904 user clicks on "Unnasigned Issues" or "All Issues" that the category should
1905 be displayed. If you scroll down the page file, you can see the links with
1906 lots of options. The option that we are interested in is the ``:columns=`` one
1907 which tells roundup which fields of the issue to display. Simply add
1908 "category" to that list and it all should work.
1911 Adding in state transition control
1912 ----------------------------------
1914 Sometimes tracker admins want to control the states that users may move issues
1915 to.
1917 1. add a Multilink property to the status class::
1919      stat = Class(db, "status", ... , transitions=Multilink('status'), ...)
1921    and then edit the statuses already created through the web using the
1922    generic class list / CSV editor.
1924 2. add an auditor module ``checktransition.py`` in your tracker's
1925    ``detectors`` directory::
1927      def checktransition(db, cl, nodeid, newvalues):
1928          ''' Check that the desired transition is valid for the "status"
1929              property.
1930          '''
1931          if not newvalues.has_key('status'):
1932              return
1933          current = cl.get(nodeid, 'status')
1934          new = newvalues['status']
1935          if new == current:
1936              return
1937          ok = db.status.get(current, 'transitions')
1938          if new not in ok:
1939              raise ValueError, 'Status not allowed to move from "%s" to "%s"'%(
1940                  db.status.get(current, 'name'), db.status.get(new, 'name'))
1942      def init(db):
1943          db.issue.audit('set', checktransition)
1945 3. in the ``issue.item`` template, change the status editing bit from::
1947     <th nowrap>Status</th>
1948     <td tal:content="structure context/status/menu">status</td>
1950    to::
1952     <th nowrap>Status</th>
1953     <td>
1954      <select tal:condition="context/id" name="status">
1955       <tal:block tal:define="ok context/status/transitions"
1956                  tal:repeat="state db/status/list">
1957        <option tal:condition="python:state.id in ok"
1958                tal:attributes="value state/id;
1959                                selected python:state.id == context.status.id"
1960                tal:content="state/name"></option>
1961       </tal:block>
1962      </select>
1963      <tal:block tal:condition="not:context/id"
1964                 tal:replace="structure context/status/menu" />
1965     </td>
1967    which displays only the allowed status to transition to.
1970 Displaying entire message contents in the issue display
1971 -------------------------------------------------------
1973 Alter the issue.item template section for messages to::
1975  <table class="messages" tal:condition="context/messages">
1976   <tr><th colspan=3 class="header">Messages</th></tr>
1977   <tal:block tal:repeat="msg context/messages/reverse">
1978    <tr>
1979     <th><a tal:attributes="href string:msg${msg/id}"
1980            tal:content="string:msg${msg/id}"></a></th>
1981     <th tal:content="string:Author: ${msg/author}">author</th>
1982     <th tal:content="string:Date: ${msg/date}">date</th>
1983    </tr>
1984    <tr>
1985     <td colspan="3" class="content">
1986      <pre tal:content="msg/content">content</pre>
1987     </td>
1988    </tr>
1989   </tal:block>
1990  </table>
1992 Restricting the list of users that are assignable to a task
1993 -----------------------------------------------------------
1995 1. In your tracker's "dbinit.py", create a new Role, say "Developer"::
1997      db.security.addRole(name='Developer', description='A developer')
1999 2. Just after that, create a new Permission, say "Fixer", specific to "issue"::
2001      p = db.security.addPermission(name='Fixer', klass='issue',
2002          description='User is allowed to be assigned to fix issues')
2004 3. Then assign the new Permission to your "Developer" Role::
2006      db.security.addPermissionToRole('Developer', p)
2008 4. In the issue item edit page ("html/issue.item" in your tracker dir), use
2009    the new Permission in restricting the "assignedto" list::
2011     <select name="assignedto">
2012      <option value="-1">- no selection -</option>
2013      <tal:block tal:repeat="user db/user/list">
2014      <option tal:condition="python:user.hasPermission('Fixer', context.classname)"
2015              tal:attributes="value user/id;
2016                              selected python:user.id == context.assignedto"
2017              tal:content="user/realname"></option>
2018      </tal:block>
2019     </select>
2021 For extra security, you may wish to set up an auditor to enforce the
2022 Permission requirement (install this as "assignedtoFixer.py" in your tracker
2023 "detectors" directory)::
2025   def assignedtoMustBeFixer(db, cl, nodeid, newvalues):
2026       ''' Ensure the assignedto value in newvalues is a used with the Fixer
2027           Permission
2028       '''
2029       if not newvalues.has_key('assignedto'):
2030           # don't care
2031           return
2032   
2033       # get the userid
2034       userid = newvalues['assignedto']
2035       if not db.security.hasPermission('Fixer', userid, cl.classname):
2036           raise ValueError, 'You do not have permission to edit %s'%cl.classname
2038   def init(db):
2039       db.issue.audit('set', assignedtoMustBeFixer)
2040       db.issue.audit('create', assignedtoMustBeFixer)
2042 So now, if the edit attempts to set the assignedto to a user that doesn't have
2043 the "Fixer" Permission, the error will be raised.
2046 Setting up a "wizard" (or "druid") for controlled adding of issues
2047 ------------------------------------------------------------------
2049 1. Set up the page templates you wish to use for data input. My wizard
2050    is going to be a two-step process, first figuring out what category of
2051    issue the user is submitting, and then getting details specific to that
2052    category. The first page includes a table of help, explaining what the
2053    category names mean, and then the core of the form::
2055     <form method="POST" onSubmit="return submit_once()"
2056           enctype="multipart/form-data">
2057       <input type="hidden" name=":template" value="add_page1">
2058       <input type="hidden" name=":action" value="page1submit">
2060       <strong>Category:</strong>
2061       <tal:block tal:replace="structure context/category/menu" />
2062       <input type="submit" value="Continue">
2063     </form>
2065    The next page has the usual issue entry information, with the addition of
2066    the following form fragments::
2068     <form method="POST" onSubmit="return submit_once()"
2069           enctype="multipart/form-data" tal:condition="context/is_edit_ok"
2070           tal:define="cat request/form/category/value">
2072       <input type="hidden" name=":template" value="add_page2">
2073       <input type="hidden" name=":required" value="title">
2074       <input type="hidden" name="category" tal:attributes="value cat">
2076        .
2077        .
2078        .
2079     </form>
2081    Note that later in the form, I test the value of "cat" include form
2082    elements that are appropriate. For example::
2084     <tal:block tal:condition="python:cat in '6 10 13 14 15 16 17'.split()">
2085      <tr>
2086       <th nowrap>Operating System</th>
2087       <td tal:content="structure context/os/field"></td>
2088      </tr>
2089      <tr>
2090       <th nowrap>Web Browser</th>
2091       <td tal:content="structure context/browser/field"></td>
2092      </tr>
2093     </tal:block>
2095    ... the above section will only be displayed if the category is one of 6,
2096    10, 13, 14, 15, 16 or 17.
2098 3. Determine what actions need to be taken between the pages - these are
2099    usually to validate user choices and determine what page is next. Now
2100    encode those actions in methods on the interfaces Client class and insert
2101    hooks to those actions in the "actions" attribute on that class, like so::
2103     actions = client.Class.actions + (
2104         ('page1_submit', page1SubmitAction),
2105     )
2107     def page1SubmitAction(self):
2108         ''' Verify that the user has selected a category, and then move on
2109             to page 2.
2110         '''
2111         category = self.form['category'].value
2112         if category == '-1':
2113             self.error_message.append('You must select a category of report')
2114             return
2115         # everything's ok, move on to the next page
2116         self.template = 'add_page2'
2118 4. Use the usual "new" action as the :action on the final page, and you're
2119    done (the standard context/submit method can do this for you).
2122 Using an external password validation source
2123 --------------------------------------------
2125 We have a centrally-managed password changing system for our users. This
2126 results in a UN*X passwd-style file that we use for verification of users.
2127 Entries in the file consist of ``name:password`` where the password is
2128 encrypted using the standard UN*X ``crypt()`` function (see the ``crypt``
2129 module in your Python distribution). An example entry would be::
2131     admin:aamrgyQfDFSHw
2133 Each user of Roundup must still have their information stored in the Roundup
2134 database - we just use the passwd file to check their password. To do this, we
2135 add the following code to our ``Client`` class in the tracker home
2136 ``interfaces.py`` module::
2138     def verifyPassword(self, userid, password):
2139         # get the user's username
2140         username = self.db.user.get(userid, 'username')
2142         # the passwords are stored in the "passwd.txt" file in the tracker
2143         # home
2144         file = os.path.join(self.db.config.TRACKER_HOME, 'passwd.txt')
2146         # see if we can find a match
2147         for ent in [line.strip().split(':') for line in open(file).readlines()]:
2148             if ent[0] == username:
2149                 return crypt.crypt(password, ent[1][:2]) == ent[1]
2151         # user doesn't exist in the file
2152         return 0
2154 What this does is look through the file, line by line, looking for a name that
2155 matches.
2157 We also remove the redundant password fields from the ``user.item`` template.
2160 -------------------
2162 Back to `Table of Contents`_
2164 .. _`Table of Contents`: index.html