1 ===================
2 Customising Roundup
3 ===================
5 :Version: $Revision: 1.80 $
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 Before you get too far, it's probably worth having a quick read of the Roundup
17 `design documentation`_.
19 Customisation of Roundup can take one of five forms:
21 1. `tracker configuration`_ file changes
22 2. database, or `tracker schema`_ changes
23 3. "definition" class `database content`_ changes
24 4. behavioural changes, through detectors_
25 5. `access controls`_
26 6. change the `web interface`_
28 The third case is special because it takes two distinctly different forms
29 depending upon whether the tracker has been initialised or not. The other two
30 may be done at any time, before or after tracker initialisation. Yes, this
31 includes adding or removing properties from classes.
34 Trackers in a Nutshell
35 ======================
37 Trackers have the following structure:
39 =================== ========================================================
40 Tracker File Description
41 =================== ========================================================
42 config.py Holds the basic `tracker configuration`_
43 dbinit.py Holds the `tracker schema`_
44 interfaces.py Defines the Web and E-Mail interfaces for the tracker
45 select_db.py Selects the database back-end for the tracker
46 db/ Holds the tracker's database
47 db/files/ Holds the tracker's upload files and messages
48 detectors/ Auditors and reactors for this tracker
49 html/ Web interface templates, images and style sheets
50 =================== ========================================================
52 Tracker Configuration
53 =====================
55 The config.py located in your tracker home contains the basic configuration
56 for the web and e-mail components of roundup's interfaces. As the name
57 suggests, this file is a Python module. This means that any valid python
58 expression may be used in the file. Mostly though, you'll be setting the
59 configuration variables to string values. Python string values must be quoted
60 with either single or double quotes::
62 'this is a string'
63 "this is also a string - use it when you have a 'single quote' in the value"
64 this is not a string - it's not quoted
66 Python strings may use formatting that's almost identical to C string
67 formatting. The ``%`` operator is used to perform the formatting, like so::
69 'roundup-admin@%s'%MAIL_DOMAIN
71 this will create a string ``'roundup-admin@tracker.domain.example'`` if
72 MAIL_DOMAIN is set to ``'tracker.domain.example'``.
74 You'll also note some values are set to::
76 os.path.join(TRACKER_HOME, 'db')
78 or similar. This creates a new string which holds the path to the "db"
79 directory in the TRACKER_HOME directory. This is just a convenience so if the
80 TRACKER_HOME changes you don't have to edit multiple valoues.
82 The configuration variables available are:
84 **TRACKER_HOME** - ``os.path.split(__file__)[0]``
85 The tracker home directory. The above default code will automatically
86 determine the tracker home for you, so you can just leave it alone.
88 **MAILHOST** - ``'localhost'``
89 The SMTP mail host that roundup will use to send e-mail.
91 **MAIL_DOMAIN** - ``'tracker.domain.example'``
92 The domain name used for email addresses.
94 **DATABASE** - ``os.path.join(TRACKER_HOME, 'db')``
95 This is the directory that the database is going to be stored in. By default
96 it is in the tracker home.
98 **TEMPLATES** - ``os.path.join(TRACKER_HOME, 'html')``
99 This is the directory that the HTML templates reside in. By default they are
100 in the tracker home.
102 **TRACKER_NAME** - ``'Roundup issue tracker'``
103 A descriptive name for your roundup tracker. This is sent out in e-mails and
104 appears in the heading of CGI pages.
106 **TRACKER_EMAIL** - ``'issue_tracker@%s'%MAIL_DOMAIN``
107 The email address that e-mail sent to roundup should go to. Think of it as the
108 tracker's personal e-mail address.
110 **TRACKER_WEB** - ``'http://tracker.example/cgi-bin/roundup.cgi/bugs/'``
111 The web address that the tracker is viewable at. This will be included in
112 information sent to users of the tracker. The URL **must** include the
113 cgi-bin part or anything else that is required to get to the home page of
114 the tracker. You **must** include a trailing '/' in the URL.
116 **ADMIN_EMAIL** - ``'roundup-admin@%s'%MAIL_DOMAIN``
117 The email address that roundup will complain to if it runs into trouble.
119 **EMAIL_FROM_TAG** - ``''``
120 Additional text to include in the "name" part of the ``From:`` address used
121 in nosy messages. If the sending user is "Foo Bar", the ``From:`` line is
122 usually::
124 "Foo Bar" <issue_tracker@tracker.example>
126 the EMAIL_FROM_TAG goes inside the "Foo Bar" quotes like so::
128 "Foo Bar EMAIL_FROM_TAG" <issue_tracker@tracker.example>
130 **MESSAGES_TO_AUTHOR** - ``'yes'`` or``'no'``
131 Send nosy messages to the author of the message.
133 **ADD_AUTHOR_TO_NOSY** - ``'new'``, ``'yes'`` or ``'no'``
134 Does the author of a message get placed on the nosy list automatically?
135 If ``'new'`` is used, then the author will only be added when a message
136 creates a new issue. If ``'yes'``, then the author will be added on followups
137 too. If ``'no'``, they're never added to the nosy.
139 **ADD_RECIPIENTS_TO_NOSY** - ``'new'``, ``'yes'`` or ``'no'``
140 Do the recipients (To:, Cc:) of a message get placed on the nosy list?
141 If ``'new'`` is used, then the recipients will only be added when a message
142 creates a new issue. If ``'yes'``, then the recipients will be added on
143 followups too. If ``'no'``, they're never added to the nosy.
145 **EMAIL_SIGNATURE_POSITION** - ``'top'``, ``'bottom'`` or ``'none'``
146 Where to place the email signature in messages that Roundup generates.
148 **EMAIL_KEEP_QUOTED_TEXT** - ``'yes'`` or ``'no'``
149 Keep email citations. Citations are the part of e-mail which the sender has
150 quoted in their reply to previous e-mail.
152 **EMAIL_LEAVE_BODY_UNCHANGED** - ``'no'``
153 Preserve the email body as is. Enabiling this will cause the entire message
154 body to be stored, including all citations and signatures. It should be
155 either ``'yes'`` or ``'no'``.
157 **MAIL_DEFAULT_CLASS** - ``'issue'`` or ``''``
158 Default class to use in the mailgw if one isn't supplied in email
159 subjects. To disable, comment out the variable below or leave it blank.
161 The default config.py is given below - as you
162 can see, the MAIL_DOMAIN must be edited before any interaction with the
163 tracker is attempted.::
165 # roundup home is this package's directory
166 TRACKER_HOME=os.path.split(__file__)[0]
168 # The SMTP mail host that roundup will use to send mail
169 MAILHOST = 'localhost'
171 # The domain name used for email addresses.
172 MAIL_DOMAIN = 'your.tracker.email.domain.example'
174 # This is the directory that the database is going to be stored in
175 DATABASE = os.path.join(TRACKER_HOME, 'db')
177 # This is the directory that the HTML templates reside in
178 TEMPLATES = os.path.join(TRACKER_HOME, 'html')
180 # A descriptive name for your roundup tracker
181 TRACKER_NAME = 'Roundup issue tracker'
183 # The email address that mail to roundup should go to
184 TRACKER_EMAIL = 'issue_tracker@%s'%MAIL_DOMAIN
186 # The web address that the tracker is viewable at. This will be included in
187 # information sent to users of the tracker. The URL MUST include the cgi-bin
188 # part or anything else that is required to get to the home page of the
189 # tracker. You MUST include a trailing '/' in the URL.
190 TRACKER_WEB = 'http://tracker.example/cgi-bin/roundup.cgi/bugs/'
192 # The email address that roundup will complain to if it runs into trouble
193 ADMIN_EMAIL = 'roundup-admin@%s'%MAIL_DOMAIN
195 # Additional text to include in the "name" part of the From: address used
196 # in nosy messages. If the sending user is "Foo Bar", the From: line is
197 # usually: "Foo Bar" <issue_tracker@tracker.example>
198 # the EMAIL_FROM_TAG goes inside the "Foo Bar" quotes like so:
199 # "Foo Bar EMAIL_FROM_TAG" <issue_tracker@tracker.example>
200 EMAIL_FROM_TAG = ""
202 # Send nosy messages to the author of the message
203 MESSAGES_TO_AUTHOR = 'no' # either 'yes' or 'no'
205 # Does the author of a message get placed on the nosy list automatically?
206 # If 'new' is used, then the author will only be added when a message
207 # creates a new issue. If 'yes', then the author will be added on followups
208 # too. If 'no', they're never added to the nosy.
209 ADD_AUTHOR_TO_NOSY = 'new' # one of 'yes', 'no', 'new'
211 # Do the recipients (To:, Cc:) of a message get placed on the nosy list?
212 # If 'new' is used, then the recipients will only be added when a message
213 # creates a new issue. If 'yes', then the recipients will be added on followups
214 # too. If 'no', they're never added to the nosy.
215 ADD_RECIPIENTS_TO_NOSY = 'new' # either 'yes', 'no', 'new'
217 # Where to place the email signature
218 EMAIL_SIGNATURE_POSITION = 'bottom' # one of 'top', 'bottom', 'none'
220 # Keep email citations
221 EMAIL_KEEP_QUOTED_TEXT = 'no' # either 'yes' or 'no'
223 # Preserve the email body as is
224 EMAIL_LEAVE_BODY_UNCHANGED = 'no' # either 'yes' or 'no'
226 # Default class to use in the mailgw if one isn't supplied in email
227 # subjects. To disable, comment out the variable below or leave it blank.
228 # Examples:
229 MAIL_DEFAULT_CLASS = 'issue' # use "issue" class by default
230 #MAIL_DEFAULT_CLASS = '' # disable (or just comment the var out)
232 #
233 # SECURITY DEFINITIONS
234 #
235 # define the Roles that a user gets when they register with the tracker
236 # these are a comma-separated string of role names (e.g. 'Admin,User')
237 NEW_WEB_USER_ROLES = 'User'
238 NEW_EMAIL_USER_ROLES = 'User'
240 Tracker Schema
241 ==============
243 Note: if you modify the schema, you'll most likely need to edit the
244 `web interface`_ HTML template files and `detectors`_ to reflect
245 your changes.
247 A tracker schema defines what data is stored in the tracker's database.
248 Schemas are defined using Python code in the ``dbinit.py`` module of your
249 tracker. The "classic" schema looks like this::
251 pri = Class(db, "priority", name=String(), order=String())
252 pri.setkey("name")
254 stat = Class(db, "status", name=String(), order=String())
255 stat.setkey("name")
257 keyword = Class(db, "keyword", name=String())
258 keyword.setkey("name")
260 user = Class(db, "user", username=String(), organisation=String(),
261 password=String(), address=String(), realname=String(), phone=String())
262 user.setkey("username")
264 msg = FileClass(db, "msg", author=Link("user"), summary=String(),
265 date=Date(), recipients=Multilink("user"), files=Multilink("file"))
267 file = FileClass(db, "file", name=String(), type=String())
269 issue = IssueClass(db, "issue", topic=Multilink("keyword"),
270 status=Link("status"), assignedto=Link("user"),
271 priority=Link("priority"))
272 issue.setkey('title')
274 Classes and Properties - creating a new information store
275 ---------------------------------------------------------
277 In the tracker above, we've defined 7 classes of information:
279 priority
280 Defines the possible levels of urgency for issues.
282 status
283 Defines the possible states of processing the issue may be in.
285 keyword
286 Initially empty, will hold keywords useful for searching issues.
288 user
289 Initially holding the "admin" user, will eventually have an entry for all
290 users using roundup.
292 msg
293 Initially empty, will all e-mail messages sent to or generated by
294 roundup.
296 file
297 Initially empty, will all files attached to issues.
299 issue
300 Initially empty, this is where the issue information is stored.
302 We define the "priority" and "status" classes to allow two things: reduction in
303 the amount of information stored on the issue and more powerful, accurate
304 searching of issues by priority and status. By only requiring a link on the
305 issue (which is stored as a single number) we reduce the chance that someone
306 mis-types a priority or status - or simply makes a new one up.
308 Class and Items
309 ~~~~~~~~~~~~~~~
311 A Class defines a particular class (or type) of data that will be stored in the
312 database. A class comprises one or more properties, which given the information
313 about the class items.
314 The actual data entered into the database, using class.create() are called
315 items. They have a special immutable property called id. We sometimes refer to
316 this as the itemid.
318 Properties
319 ~~~~~~~~~~
321 A Class is comprised of one or more properties of the following types:
323 * String properties are for storing arbitrary-length strings.
324 * Password properties are for storing encoded arbitrary-length strings. The
325 default encoding is defined on the roundup.password.Password class.
326 * Date properties store date-and-time stamps. Their values are Timestamp
327 objects.
328 * Number properties store numeric values.
329 * Boolean properties store on/off, yes/no, true/false values.
330 * A Link property refers to a single other item selected from a specified
331 class. The class is part of the property; the value is an integer, the id
332 of the chosen item.
333 * A Multilink property refers to possibly many items in a specified class.
334 The value is a list of integers.
336 FileClass
337 ~~~~~~~~~
339 FileClasses save their "content" attribute off in a separate file from the rest
340 of the database. This reduces the number of large entries in the database,
341 which generally makes databases more efficient, and also allows us to use
342 command-line tools to operate on the files. They are stored in the files sub-
343 directory of the db directory in your tracker.
345 IssueClass
346 ~~~~~~~~~~
348 IssueClasses automatically include the "messages", "files", "nosy", and
349 "superseder" properties.
350 The messages and files properties list the links to the messages and files
351 related to the issue. The nosy property is a list of links to users who wish to
352 be informed of changes to the issue - they get "CC'ed" e-mails when messages
353 are sent to or generated by the issue. The nosy reactor (in the detectors
354 directory) handles this action. The superceder link indicates an issue which
355 has superceded this one.
356 They also have the dynamically generated "creation", "activity" and "creator"
357 properties.
358 The value of the "creation" property is the date when an item was created, and
359 the value of the "activity" property is the date when any property on the item
360 was last edited (equivalently, these are the dates on the first and last
361 records in the item's journal). The "creator" property holds a link to the user
362 that created the issue.
364 setkey(property)
365 ~~~~~~~~~~~~~~~~
367 Select a String property of the class to be the key property. The key property
368 muse be unique, and allows references to the items in the class by the content
369 of the key property. That is, we can refer to users by their username, e.g.
370 let's say that there's an issue in roundup, issue 23. There's also a user,
371 richard who happens to be user 2. To assign an issue to him, we could do either
372 of::
374 roundup-admin set issue assignedto=2
376 or::
378 roundup-admin set issue assignedto=richard
380 Note, the same thing can be done in the web and e-mail interfaces.
382 create(information)
383 ~~~~~~~~~~~~~~~~~~~
385 Create an item in the database. This is generally used to create items in the
386 "definitional" classes like "priority" and "status".
389 Examples of adding to your schema
390 ---------------------------------
392 TODO
395 Detectors - adding behaviour to your tracker
396 ============================================
397 .. _detectors:
399 Detectors are initialised every time you open your tracker database, so you're
400 free to add and remove them any time, even after the database is initliased
401 via the "roundup-admin initalise" command.
403 The detectors in your tracker fire before (*auditors*) and after (*reactors*)
404 changes to the contents of your database. They are Python modules that sit in
405 your tracker's ``detectors`` directory. You will have some installed by
406 default - have a look. You can write new detectors or modify the existing
407 ones. The existing detectors installed for you are:
409 **nosyreaction.py**
410 This provides the automatic nosy list maintenance and email sending. The nosy
411 reactor (``nosyreaction``) fires when new messages are added to issues.
412 The nosy auditor (``updatenosy``) fires when issues are changed and figures
413 what changes need to be made to the nosy list (like adding new authors etc)
414 **statusauditor.py**
415 This provides the ``chatty`` auditor which changes the issue status from
416 ``unread`` or ``closed`` to ``chatting`` if new messages appear. It also
417 provides the ``presetunread`` auditor which pre-sets the status to
418 ``unread`` on new items if the status isn't explicitly defined.
420 See the detectors section in the `design document`__ for details of the
421 interface for detectors.
423 __ design.html
425 Sample additional detectors that have been found useful will appear in the
426 ``detectors`` directory of the Roundup distribution:
428 **newissuecopy.py**
429 This detector sends an email to a team address whenever a new issue is
430 created. The address is hard-coded into the detector, so edit it before you
431 use it (look for the text 'team@team.host') or you'll get email errors!
433 The detector code::
435 from roundup import roundupdb
437 def newissuecopy(db, cl, nodeid, oldvalues):
438 ''' Copy a message about new issues to a team address.
439 '''
440 # so use all the messages in the create
441 change_note = cl.generateCreateNote(nodeid)
443 # send a copy to the nosy list
444 for msgid in cl.get(nodeid, 'messages'):
445 try:
446 # note: last arg must be a list
447 cl.send_message(nodeid, msgid, change_note, ['team@team.host'])
448 except roundupdb.MessageSendError, message:
449 raise roundupdb.DetectorError, message
451 def init(db):
452 db.issue.react('create', newissuecopy)
455 Database Content
456 ================
458 Note: if you modify the content of definitional classes, you'll most likely
459 need to edit the tracker `detectors`_ to reflect your changes.
461 Customisation of the special "definitional" classes (eg. status, priority,
462 resolution, ...) may be done either before or after the tracker is
463 initialised. The actual method of doing so is completely different in each
464 case though, so be careful to use the right one.
466 **Changing content before tracker initialisation**
467 Edit the dbinit module in your tracker to alter the items created in using
468 the create() methods.
470 **Changing content after tracker initialisation**
471 As the "admin" user, click on the "class list" link in the web interface
472 to bring up a list of all database classes. Click on the name of the class
473 you wish to change the content of.
475 You may also use the roundup-admin interface's create, set and retire
476 methods to add, alter or remove items from the classes in question.
478 See "`adding a new field to the classic schema`_" for an example that requires
479 database content changes.
482 Access Controls
483 ===============
485 A set of Permissions are built in to the security module by default:
487 - Edit (everything)
488 - View (everything)
490 The default interfaces define:
492 - Web Registration
493 - Web Access
494 - Web Roles
495 - Email Registration
496 - Email Access
498 These are hooked into the default Roles:
500 - Admin (Edit everything, View everything, Web Roles)
501 - User (Web Access, Email Access)
502 - Anonymous (Web Registration, Email Registration)
504 And finally, the "admin" user gets the "Admin" Role, and the "anonymous" user
505 gets the "Anonymous" assigned when the database is initialised on installation.
506 The two default schemas then define:
508 - Edit issue, View issue (both)
509 - Edit file, View file (both)
510 - Edit msg, View msg (both)
511 - Edit support, View support (extended only)
513 and assign those Permissions to the "User" Role. Put together, these settings
514 appear in the ``open()`` function of the tracker ``dbinit.py`` (the following
515 is taken from the "minimal" template ``dbinit.py``)::
517 #
518 # SECURITY SETTINGS
519 #
520 # new permissions for this schema
521 for cl in ('user', ):
522 db.security.addPermission(name="Edit", klass=cl,
523 description="User is allowed to edit "+cl)
524 db.security.addPermission(name="View", klass=cl,
525 description="User is allowed to access "+cl)
527 # and give the regular users access to the web and email interface
528 p = db.security.getPermission('Web Access')
529 db.security.addPermissionToRole('User', p)
530 p = db.security.getPermission('Email Access')
531 db.security.addPermissionToRole('User', p)
533 # May users view other user information? Comment these lines out
534 # if you don't want them to
535 p = db.security.getPermission('View', 'user')
536 db.security.addPermissionToRole('User', p)
538 # Assign the appropriate permissions to the anonymous user's Anonymous
539 # Role. Choices here are:
540 # - Allow anonymous users to register through the web
541 p = db.security.getPermission('Web Registration')
542 db.security.addPermissionToRole('Anonymous', p)
543 # - Allow anonymous (new) users to register through the email gateway
544 p = db.security.getPermission('Email Registration')
545 db.security.addPermissionToRole('Anonymous', p)
548 New User Roles
549 --------------
551 New users are assigned the Roles defined in the config file as:
553 - NEW_WEB_USER_ROLES
554 - NEW_EMAIL_USER_ROLES
557 Changing Access Controls
558 ------------------------
560 You may alter the configuration variables to change the Role that new web or
561 email users get, for example to not give them access to the web interface if
562 they register through email.
564 You may use the ``roundup-admin`` "``security``" command to display the
565 current Role and Permission configuration in your tracker.
567 Adding a new Permission
568 ~~~~~~~~~~~~~~~~~~~~~~~
570 When adding a new Permission, you will need to:
572 1. add it to your tracker's dbinit so it is created
573 2. enable it for the Roles that should have it (verify with
574 "``roundup-admin security``")
575 3. add it to the relevant HTML interface templates
576 4. add it to the appropriate xxxPermission methods on in your tracker
577 interfaces module
579 Example Scenarios
580 ~~~~~~~~~~~~~~~~~
582 **automatic registration of users in the e-mail gateway**
583 By giving the "anonymous" user the "Email Registration" Role, any
584 unidentified user will automatically be registered with the tracker (with
585 no password, so they won't be able to log in through the web until an admin
586 sets them a password). Note: this is the default behaviour in the tracker
587 templates that ship with Roundup.
589 **anonymous access through the e-mail gateway**
590 Give the "anonymous" user the "Email Access" and ("Edit", "issue") Roles
591 but not giving them the "Email Registration" Role. This means that when an
592 unknown user sends email into the tracker, they're automatically logged in
593 as "anonymous". Since they don't have the "Email Registration" Role, they
594 won't be automatically registered, but since "anonymous" has permission
595 to use the gateway, they'll still be able to submit issues. Note that the
596 Sender information - their email address - will not be available - they're
597 *anonymous*.
599 **only developers may be assigned issues**
600 Create a new Permission called "Fixer" for the "issue" class. Create a new
601 Role "Developer" which has that Permission, and assign that to the
602 appropriate users. Filter the list of users available in the assignedto
603 list to include only those users. Enforce the Permission with an auditor. See
604 the example `restricting the list of users that are assignable to a task`_.
606 **only managers may sign off issues as complete**
607 Create a new Permission called "Closer" for the "issue" class. Create a new
608 Role "Manager" which has that Permission, and assign that to the appropriate
609 users. In your web interface, only display the "resolved" issue state option
610 when the user has the "Closer" Permissions. Enforce the Permission with
611 an auditor. This is very similar to the previous example, except that the
612 web interface check would look like::
614 <option tal:condition="python:request.user.hasPermission('Closer')"
615 value="resolved">Resolved</option>
617 **don't give users who register through email web access**
618 Create a new Role called "Email User" which has all the Permissions of the
619 normal "User" Role minus the "Web Access" Permission. This will allow users
620 to send in emails to the tracker, but not access the web interface.
622 **let some users edit the details of all users**
623 Create a new Role called "User Admin" which has the Permission for editing
624 users::
626 db.security.addRole(name='User Admin', description='Managing users')
627 p = db.security.getPermission('Edit', 'user')
628 db.security.addPermissionToRole('User Admin', p)
630 and assign the Role to the users who need the permission.
633 Web Interface
634 =============
636 .. contents::
637 :local:
638 :depth: 1
640 The web is provided by the roundup.cgi.client module and is used by
641 roundup.cgi, roundup-server and ZRoundup.
642 In all cases, we determine which tracker is being accessed
643 (the first part of the URL path inside the scope of the CGI handler) and pass
644 control on to the tracker interfaces.Client class - which uses the Client class
645 from roundup.cgi.client - which handles the rest of
646 the access through its main() method. This means that you can do pretty much
647 anything you want as a web interface to your tracker.
649 Repurcussions of changing the tracker schema
650 ---------------------------------------------
652 If you choose to change the `tracker schema`_ you will need to ensure the web
653 interface knows about it:
655 1. Index, item and search pages for the relevant classes may need to have
656 properties added or removed,
657 2. The "page" template may require links to be changed, as might the "home"
658 page's content arguments.
660 How requests are processed
661 --------------------------
663 The basic processing of a web request proceeds as follows:
665 1. figure out who we are, defaulting to the "anonymous" user
666 2. figure out what the request is for - we call this the "context"
667 3. handle any requested action (item edit, search, ...)
668 4. render the template requested by the context, resulting in HTML output
670 In some situations, exceptions occur:
672 - HTTP Redirect (generally raised by an action)
673 - SendFile (generally raised by determine_context)
674 here we serve up a FileClass "content" property
675 - SendStaticFile (generally raised by determine_context)
676 here we serve up a file from the tracker "html" directory
677 - Unauthorised (generally raised by an action)
678 here the action is cancelled, the request is rendered and an error
679 message is displayed indicating that permission was not
680 granted for the action to take place
681 - NotFound (raised wherever it needs to be)
682 this exception percolates up to the CGI interface that called the client
684 Determining web context
685 -----------------------
687 To determine the "context" of a request, we look at the URL and the special
688 request variable ``:template``. The URL path after the tracker identifier
689 is examined. Typical URL paths look like:
691 1. ``/tracker/issue``
692 2. ``/tracker/issue1``
693 3. ``/tracker/_file/style.css``
694 4. ``/cgi-bin/roundup.cgi/tracker/file1``
695 5. ``/cgi-bin/roundup.cgi/tracker/file1/kitten.png``
697 where the "tracker identifier" is "tracker" in the above cases. That means
698 we're looking at "issue", "issue1", "_file/style.css", "file1" and
699 "file1/kitten.png" in the cases above. The path is generally only one
700 entry long - longer paths are handled differently.
702 a. if there is no path, then we are in the "home" context.
703 b. if the path starts with "_file" (as in example 3,
704 "/tracker/_file/style.css"), then the additional path entry,
705 "style.css" specifies the filename of a static file we're to serve up
706 from the tracker "html" directory. Raises a SendStaticFile
707 exception.
708 c. if there is something in the path (as in example 1, "issue"), it identifies
709 the tracker class we're to display.
710 d. if the path is an item designator (as in examples 2 and 4, "issue1" and
711 "file1"), then we're to display a specific item.
712 e. if the path starts with an item designator and is longer than
713 one entry (as in example 5, "file1/kitten.png"), then we're assumed
714 to be handling an item of a
715 FileClass, and the extra path information gives the filename
716 that the client is going to label the download with (ie
717 "file1/kitten.png" is nicer to download than "file1"). This
718 raises a SendFile exception.
720 Both b. and e. stop before we bother to
721 determine the template we're going to use. That's because they
722 don't actually use templates.
724 The template used is specified by the ``:template`` CGI variable,
725 which defaults to:
727 - only classname suplied: "index"
728 - full item designator supplied: "item"
731 Performing actions in web requests
732 ----------------------------------
734 When a user requests a web page, they may optionally also request for an
735 action to take place. As described in `how requests are processed`_, the
736 action is performed before the requested page is generated. Actions are
737 triggered by using a ``:action`` CGI variable, where the value is one of:
739 **login**
740 Attempt to log a user in.
742 **logout**
743 Log the user out - make them "anonymous".
745 **register**
746 Attempt to create a new user based on the contents of the form and then log
747 them in.
749 **edit**
750 Perform an edit of an item in the database. There are some special form
751 elements you may use:
753 :link=designator:property and :multilink=designator:property
754 The value specifies an item designator and the property on that
755 item to add *this* item to as a link or multilink.
756 :note
757 Create a message and attach it to the current item's
758 "messages" property.
759 :file
760 Create a file and attach it to the current item's
761 "files" property. Attach the file to the message created from
762 the :note if it's supplied.
763 :required=property,property,...
764 The named properties are required to be filled in the form.
765 :remove:<propname>=id(s)
766 The ids will be removed from the multilink property. You may have multiple
767 :remove:<propname> form elements for a single <propname>.
768 :add:<propname>=id(s)
769 The ids will be added to the multilink property. You may have multiple
770 :add:<propname> form elements for a single <propname>.
772 **new**
773 Add a new item to the database. You may use the same special form elements
774 as in the "edit" action.
776 **retire**
777 Retire the item in the database.
779 **editCSV**
780 Performs an edit of all of a class' items in one go. See also the
781 *class*.csv templating method which generates the CSV data to be edited, and
782 the "_generic.index" template which uses both of these features.
784 **search**
785 Mangle some of the form variables.
787 Set the form ":filter" variable based on the values of the
788 filter variables - if they're set to anything other than
789 "dontcare" then add them to :filter.
791 Also handle the ":queryname" variable and save off the query to
792 the user's query list.
794 Each of the actions is implemented by a corresponding *actionAction* (where
795 "action" is the name of the action) method on
796 the roundup.cgi.Client class, which also happens to be in your tracker as
797 interfaces.Client. So if you need to define new actions, you may add them
798 there (see `defining new web actions`_).
800 Each action also has a corresponding *actionPermission* (where
801 "action" is the name of the action) method which determines
802 whether the action is permissible given the current user. The base permission
803 checks are:
805 **login**
806 Determine whether the user has permission to log in.
807 Base behaviour is to check the user has "Web Access".
808 **logout**
809 No permission checks are made.
810 **register**
811 Determine whether the user has permission to register
812 Base behaviour is to check the user has "Web Registration".
813 **edit**
814 Determine whether the user has permission to edit this item.
815 Base behaviour is to check the user can edit this class. If we're
816 editing the "user" class, users are allowed to edit their own
817 details. Unless it's the "roles" property, which requires the
818 special Permission "Web Roles".
819 **new**
820 Determine whether the user has permission to create (edit) this item.
821 Base behaviour is to check the user can edit this class. No
822 additional property checks are made. Additionally, new user items
823 may be created if the user has the "Web Registration" Permission.
824 **editCSV**
825 Determine whether the user has permission to edit this class.
826 Base behaviour is to check the user can edit this class.
827 **search**
828 Determine whether the user has permission to search this class.
829 Base behaviour is to check the user can view this class.
832 Default templates
833 -----------------
835 Most customisation of the web view can be done by modifying the templates in
836 the tracker **html** directory. There are several types of files in there:
838 **page**
839 This template usually defines the overall look of your tracker. When you
840 view an issue, it appears inside this template. When you view an index, it
841 also appears inside this template. This template defines a macro called
842 "icing" which is used by almost all other templates as a coating for their
843 content, using its "content" slot. It will also define the "head_title"
844 and "body_title" slots to allow setting of the page title.
845 **home**
846 the default page displayed when no other page is indicated by the user
847 **home.classlist**
848 a special version of the default page that lists the classes in the tracker
849 **classname.item**
850 displays an item of the *classname* class
851 **classname.index**
852 displays a list of *classname* items
853 **classname.search**
854 displays a search page for *classname* items
855 **_generic.index**
856 used to display a list of items where there is no *classname*.index available
857 **_generic.help**
858 used to display a "class help" page where there is no *classname*.help
859 **user.register**
860 a special page just for the user class that renders the registration page
861 **style.css**
862 a static file that is served up as-is
864 Note: Remember that you can create any template extension you want to, so
865 if you just want to play around with the templating for new issues, you can
866 copy the current "issue.item" template to "issue.test", and then access the
867 test template using the ":template" URL argument::
869 http://your.tracker.example/tracker/issue?:template=test
871 and it won't affect your users using the "issue.item" template.
874 How the templates work
875 ----------------------
877 Basic Templating Actions
878 ~~~~~~~~~~~~~~~~~~~~~~~~
880 Roundup's templates consist of special attributes on your template tags.
881 These attributes form the Template Attribute Language, or TAL. The basic tag
882 commands are:
884 **tal:define="variable expression; variable expression; ..."**
885 Define a new variable that is local to this tag and its contents. For
886 example::
888 <html tal:define="title request/description">
889 <head><title tal:content="title"></title></head>
890 </html>
892 In the example, the variable "title" is defined as being the result of the
893 expression "request/description". The tal:content command inside the <html>
894 tag may then use the "title" variable.
896 **tal:condition="expression"**
897 Only keep this tag and its contents if the expression is true. For example::
899 <p tal:condition="python:request.user.hasPermission('View', 'issue')">
900 Display some issue information.
901 </p>
903 In the example, the <p> tag and its contents are only displayed if the
904 user has the View permission for issues. We consider the number zero, a
905 blank string, an empty list, and the built-in variable nothing to be false
906 values. Nearly every other value is true, including non-zero numbers, and
907 strings with anything in them (even spaces!).
909 **tal:repeat="variable expression"**
910 Repeat this tag and its contents for each element of the sequence that the
911 expression returns, defining a new local variable and a special "repeat"
912 variable for each element. For example::
914 <tr tal:repeat="u user/list">
915 <td tal:content="u/id"></td>
916 <td tal:content="u/username"></td>
917 <td tal:content="u/realname"></td>
918 </tr>
920 The example would iterate over the sequence of users returned by
921 "user/list" and define the local variable "u" for each entry.
923 **tal:replace="expression"**
924 Replace this tag with the result of the expression. For example::
926 <span tal:replace="request/user/realname"></span>
928 The example would replace the <span> tag and its contents with the user's
929 realname. If the user's realname was "Bruce" then the resultant output
930 would be "Bruce".
932 **tal:content="expression"**
933 Replace the contents of this tag with the result of the expression. For
934 example::
936 <span tal:content="request/user/realname">user's name appears here</span>
938 The example would replace the contents of the <span> tag with the user's
939 realname. If the user's realname was "Bruce" then the resultant output
940 would be "<span>Bruce</span>".
942 **tal:attributes="attribute expression; attribute expression; ..."**
943 Set attributes on this tag to the results of expressions. For example::
945 <a tal:attributes="href string:user${request/user/id}">My Details</a>
947 In the example, the "href" attribute of the <a> tag is set to the value of
948 the "string:user${request/user/id}" expression, which will be something
949 like "user123".
951 **tal:omit-tag="expression"**
952 Remove this tag (but not its contents) if the expression is true. For
953 example::
955 <span tal:omit-tag="python:1">Hello, world!</span>
957 would result in output of::
959 Hello, world!
961 Note that the commands on a given tag are evaulated in the order above, so
962 *define* comes before *condition*, and so on.
964 Additionally, a tag is defined, tal:block, which is removed from output. Its
965 content is not, but the tag itself is (so don't go using any tal:attributes
966 commands on it). This is useful for making arbitrary blocks of HTML
967 conditional or repeatable (very handy for repeating multiple table rows,
968 which would othewise require an illegal tag placement to effect the repeat).
971 Templating Expressions
972 ~~~~~~~~~~~~~~~~~~~~~~
974 The expressions you may use in the attibute values may be one of the following
975 forms:
977 **Path Expressions** - eg. ``item/status/checklist``
978 These are object attribute / item accesses. Roughly speaking, the path
979 ``item/status/checklist`` is broken into parts ``item``, ``status``
980 and ``checklist``. The ``item`` part is the root of the expression.
981 We then look for a ``status`` attribute on ``item``, or failing that, a
982 ``status`` item (as in ``item['status']``). If that
983 fails, the path expression fails. When we get to the end, the object we're
984 left with is evaluated to get a string - methods are called, objects are
985 stringified. Path expressions may have an optional ``path:`` prefix, though
986 they are the default expression type, so it's not necessary.
988 If an expression evaluates to ``default`` then the expression is
989 "cancelled" - whatever HTML already exists in the template will remain
990 (tag content in the case of tal:content, attributes in the case of
991 tal:attributes).
993 If an expression evaluates to ``nothing`` then the target of the expression
994 is removed (tag content in the case of tal:content, attributes in the case
995 of tal:attributes and the tag itself in the case of tal:replace).
997 If an element in the path may not exist, then you can use the ``|``
998 operator in the expression to provide an alternative. So, the expression
999 ``request/form/foo/value | default`` would simply leave the current HTML
1000 in place if the "foo" form variable doesn't exist.
1002 You may use the python function ``path``, as in ``path("item/status")``, to
1003 embed path expressions in Python expressions.
1005 **String Expressions** - eg. ``string:hello ${user/name}``
1006 These expressions are simple string interpolations - though they can be just
1007 plain strings with no interpolation if you want. The expression in the
1008 ``${ ... }`` is just a path expression as above.
1010 **Python Expressions** - eg. ``python: 1+1``
1011 These expressions give the full power of Python. All the "root level"
1012 variables are available, so ``python:item.status.checklist()`` would be
1013 equivalent to ``item/status/checklist``, assuming that ``checklist`` is
1014 a method.
1016 Modifiers:
1018 **structure** - eg. ``structure python:msg.content.plain(hyperlink=1)``
1019 The result of expressions are normally *escaped* to be safe for HTML
1020 display (all "<", ">" and "&" are turned into special entities). The
1021 ``structure`` expression modifier turns off this escaping - the result
1022 of the expression is now assumed to be HTML structured text.
1024 **not:** - eg. ``not:python:1=1``
1025 This simply inverts the logical true/false value of another expression.
1028 Template Macros
1029 ~~~~~~~~~~~~~~~
1031 Macros are used in Roundup to save us from repeating the same common page
1032 stuctures over and over. The most common (and probably only) macro you'll use
1033 is the "icing" macro defined in the "page" template.
1035 Macros are generated and used inside your templates using special attributes
1036 similar to the `basic templating actions`_. In this case though, the
1037 attributes belong to the Macro Expansion Template Attribute Language, or
1038 METAL. The macro commands are:
1040 **metal:define-macro="macro name"**
1041 Define that the tag and its contents are now a macro that may be inserted
1042 into other templates using the *use-macro* command. For example::
1044 <html metal:define-macro="page">
1045 ...
1046 </html>
1048 defines a macro called "page" using the ``<html>`` tag and its contents.
1049 Once defined, macros are stored on the template they're defined on in the
1050 ``macros`` attribute. You can access them later on through the ``templates``
1051 variable, eg. the most common ``templates/page/macros/icing`` to access the
1052 "page" macro of the "page" template.
1054 **metal:use-macro="path expression"**
1055 Use a macro, which is identified by the path expression (see above). This
1056 will replace the current tag with the identified macro contents. For
1057 example::
1059 <tal:block metal:use-macro="templates/page/macros/icing">
1060 ...
1061 </tal:block>
1063 will replace the tag and its contents with the "page" macro of the "page"
1064 template.
1066 **metal:define-slot="slot name"** and **metal:fill-slot="slot name"**
1067 To define *dynamic* parts of the macro, you define "slots" which may be
1068 filled when the macro is used with a *use-macro* command. For example, the
1069 ``templates/page/macros/icing`` macro defines a slot like so::
1071 <title metal:define-slot="head_title">title goes here</title>
1073 In your *use-macro* command, you may now use a *fill-slot* command like
1074 this::
1076 <title metal:fill-slot="head_title">My Title</title>
1078 where the tag that fills the slot completely replaces the one defined as
1079 the slot in the macro.
1081 Note that you may not mix METAL and TAL commands on the same tag, but TAL
1082 commands may be used freely inside METAL-using tags (so your *fill-slots*
1083 tags may have all manner of TAL inside them).
1086 Information available to templates
1087 ----------------------------------
1089 Note: this is implemented by roundup.cgi.templating.RoundupPageTemplate
1091 The following variables are available to templates.
1093 **context**
1094 The current context. This is either None, a
1095 `hyperdb class wrapper`_ or a `hyperdb item wrapper`_
1096 **request**
1097 Includes information about the current request, including:
1098 - the current index information (``filterspec``, ``filter`` args,
1099 ``properties``, etc) parsed out of the form.
1100 - methods for easy filterspec link generation
1101 - *user*, the current user item as an HTMLItem instance
1102 - *form*
1103 The current CGI form information as a mapping of form argument
1104 name to value
1105 **config**
1106 This variable holds all the values defined in the tracker config.py file
1107 (eg. TRACKER_NAME, etc.)
1108 **db**
1109 The current database, used to access arbitrary database items.
1110 **templates**
1111 Access to all the tracker templates by name. Used mainly in *use-macro*
1112 commands.
1113 **utils**
1114 This variable makes available some utility functions like batching.
1115 **nothing**
1116 This is a special variable - if an expression evaluates to this, then the
1117 tag (in the case of a tal:replace), its contents (in the case of
1118 tal:content) or some attributes (in the case of tal:attributes) will not
1119 appear in the the output. So for example::
1121 <span tal:attributes="class nothing">Hello, World!</span>
1123 would result in::
1125 <span>Hello, World!</span>
1127 **default**
1128 Also a special variable - if an expression evaluates to this, then the
1129 existing HTML in the template will not be replaced or removed, it will
1130 remain. So::
1132 <span tal:replace="default">Hello, World!</span>
1134 would result in::
1136 <span>Hello, World!</span>
1138 The context variable
1139 ~~~~~~~~~~~~~~~~~~~~
1141 The *context* variable is one of three things based on the current context
1142 (see `determining web context`_ for how we figure this out):
1144 1. if we're looking at a "home" page, then it's None
1145 2. if we're looking at a specific hyperdb class, it's a
1146 `hyperdb class wrapper`_.
1147 3. if we're looking at a specific hyperdb item, it's a
1148 `hyperdb item wrapper`_.
1150 If the context is not None, we can access the properties of the class or item.
1151 The only real difference between cases 2 and 3 above are:
1153 1. the properties may have a real value behind them, and this will appear if
1154 the property is displayed through ``context/property`` or
1155 ``context/property/field``.
1156 2. the context's "id" property will be a false value in the second case, but
1157 a real, or true value in the third. Thus we can determine whether we're
1158 looking at a real item from the hyperdb by testing "context/id".
1160 Hyperdb class wrapper
1161 :::::::::::::::::::::
1163 Note: this is implemented by the roundup.cgi.templating.HTMLClass class.
1165 This wrapper object provides access to a hyperb class. It is used primarily
1166 in both index view and new item views, but it's also usable anywhere else that
1167 you wish to access information about a class, or the items of a class, when
1168 you don't have a specific item of that class in mind.
1170 We allow access to properties. There will be no "id" property. The value
1171 accessed through the property will be the current value of the same name from
1172 the CGI form.
1174 There are several methods available on these wrapper objects:
1176 =========== =============================================================
1177 Method Description
1178 =========== =============================================================
1179 properties return a `hyperdb property wrapper`_ for all of this class'
1180 properties.
1181 list lists all of the active (not retired) items in the class.
1182 csv return the items of this class as a chunk of CSV text.
1183 propnames lists the names of the properties of this class.
1184 filter lists of items from this class, filtered and sorted
1185 by the current *request* filterspec/filter/sort/group args
1186 classhelp display a link to a javascript popup containing this class'
1187 "help" template.
1188 submit generate a submit button (and action hidden element)
1189 renderWith render this class with the given template.
1190 history returns 'New node - no history' :)
1191 is_edit_ok is the user allowed to Edit the current class?
1192 is_view_ok is the user allowed to View the current class?
1193 =========== =============================================================
1195 Note that if you have a property of the same name as one of the above methods,
1196 you'll need to access it using a python "item access" expression. For example::
1198 python:context['list']
1200 will access the "list" property, rather than the list method.
1203 Hyperdb item wrapper
1204 ::::::::::::::::::::
1206 Note: this is implemented by the roundup.cgi.templating.HTMLItem class.
1208 This wrapper object provides access to a hyperb item.
1210 We allow access to properties. There will be no "id" property. The value
1211 accessed through the property will be the current value of the same name from
1212 the CGI form.
1214 There are several methods available on these wrapper objects:
1216 =============== =============================================================
1217 Method Description
1218 =============== =============================================================
1219 submit generate a submit button (and action hidden element)
1220 journal return the journal of the current item (**not implemented**)
1221 history render the journal of the current item as HTML
1222 renderQueryForm specific to the "query" class - render the search form for
1223 the query
1224 hasPermission specific to the "user" class - determine whether the user
1225 has a Permission
1226 is_edit_ok is the user allowed to Edit the current item?
1227 is_view_ok is the user allowed to View the current item?
1228 =============== =============================================================
1231 Note that if you have a property of the same name as one of the above methods,
1232 you'll need to access it using a python "item access" expression. For example::
1234 python:context['journal']
1236 will access the "journal" property, rather than the journal method.
1239 Hyperdb property wrapper
1240 ::::::::::::::::::::::::
1242 Note: this is implemented by subclasses roundup.cgi.templating.HTMLProperty
1243 class (HTMLStringProperty, HTMLNumberProperty, and so on).
1245 This wrapper object provides access to a single property of a class. Its
1246 value may be either:
1248 1. if accessed through a `hyperdb item wrapper`_, then it's a value from the
1249 hyperdb
1250 2. if access through a `hyperdb class wrapper`_, then it's a value from the
1251 CGI form
1254 The property wrapper has some useful attributes:
1256 =============== =============================================================
1257 Attribute Description
1258 =============== =============================================================
1259 _name the name of the property
1260 _value the value of the property if any - this is the actual value
1261 retrieved from the hyperdb for this property
1262 =============== =============================================================
1264 There are several methods available on these wrapper objects:
1266 ========= =====================================================================
1267 Method Description
1268 ========= =====================================================================
1269 plain render a "plain" representation of the property. This method may
1270 take two arguments:
1272 escape
1273 If true, escape the text so it is HTML safe (default: no). The
1274 reason this defaults to off is that text is usually escaped
1275 at a later stage by the TAL commands, unless the "structure"
1276 option is used in the template. The following are all equivalent::
1278 <p tal:content="structure python:msg.content.plain(escape=1)" />
1279 <p tal:content="python:msg.content.plain()" />
1280 <p tal:content="msg/content/plain" />
1281 <p tal:content="msg/content" />
1283 Usually you'll only want to use the escape option in a complex
1284 expression.
1286 hyperlink
1287 If true, turn URLs, email addresses and hyperdb item designators
1288 in the text into hyperlinks (default: no). Note that you'll need
1289 to use the "structure" TAL option if you want to use this::
1291 <p tal:content="structure python:msg.content.plain(hyperlink=1)" />
1293 Note also that the text is automatically HTML-escape before the
1294 hyperlinking transformation.
1296 field render an appropriate form edit field for the property - for most
1297 types this is a text entry box, but for Booleans it's a tri-state
1298 yes/no/neither selection.
1299 stext only on String properties - render the value of the
1300 property as StructuredText (requires the StructureText module
1301 to be installed separately)
1302 multiline only on String properties - render a multiline form edit
1303 field for the property
1304 email only on String properties - render the value of the
1305 property as an obscured email address
1306 confirm only on Password properties - render a second form edit field for
1307 the property, used for confirmation that the user typed the
1308 password correctly. Generates a field with name "name:confirm".
1309 now only on Date properties - return the current date as a new property
1310 reldate only on Date properties - render the interval between the
1311 date and now
1312 local only on Date properties - return this date as a new property with
1313 some timezone offset
1314 pretty only on Interval properties - render the interval in a
1315 pretty format (eg. "yesterday")
1316 menu only on Link and Multilink properties - render a form select
1317 list for this property
1318 reverse only on Multilink properties - produce a list of the linked
1319 items in reverse order
1320 ========= =====================================================================
1322 The request variable
1323 ~~~~~~~~~~~~~~~~~~~~
1325 Note: this is implemented by the roundup.cgi.templating.HTMLRequest class.
1327 The request variable is packed with information about the current request.
1329 .. taken from roundup.cgi.templating.HTMLRequest docstring
1331 =========== =================================================================
1332 Variable Holds
1333 =========== =================================================================
1334 form the CGI form as a cgi.FieldStorage
1335 env the CGI environment variables
1336 base the base URL for this tracker
1337 user a HTMLUser instance for this user
1338 classname the current classname (possibly None)
1339 template the current template (suffix, also possibly None)
1340 form the current CGI form variables in a FieldStorage
1341 =========== =================================================================
1343 **Index page specific variables (indexing arguments)**
1345 =========== =================================================================
1346 Variable Holds
1347 =========== =================================================================
1348 columns dictionary of the columns to display in an index page
1349 show a convenience access to columns - request/show/colname will
1350 be true if the columns should be displayed, false otherwise
1351 sort index sort column (direction, column name)
1352 group index grouping property (direction, column name)
1353 filter properties to filter the index on
1354 filterspec values to filter the index on
1355 search_text text to perform a full-text search on for an index
1356 =========== =================================================================
1358 There are several methods available on the request variable:
1360 =============== =============================================================
1361 Method Description
1362 =============== =============================================================
1363 description render a description of the request - handle for the page
1364 title
1365 indexargs_form render the current index args as form elements
1366 indexargs_url render the current index args as a URL
1367 base_javascript render some javascript that is used by other components of
1368 the templating
1369 batch run the current index args through a filter and return a
1370 list of items (see `hyperdb item wrapper`_, and
1371 `batching`_)
1372 =============== =============================================================
1374 The form variable
1375 :::::::::::::::::
1377 The form variable is a little special because it's actually a python
1378 FieldStorage object. That means that you have two ways to access its
1379 contents. For example, to look up the CGI form value for the variable
1380 "name", use the path expression::
1382 request/form/name/value
1384 or the python expression::
1386 python:request.form['name'].value
1388 Note the "item" access used in the python case, and also note the explicit
1389 "value" attribute we have to access. That's because the form variables are
1390 stored as MiniFieldStorages. If there's more than one "name" value in
1391 the form, then the above will break since ``request/form/name`` is actually a
1392 *list* of MiniFieldStorages. So it's best to know beforehand what you're
1393 dealing with.
1396 The db variable
1397 ~~~~~~~~~~~~~~~
1399 Note: this is implemented by the roundup.cgi.templating.HTMLDatabase class.
1401 Allows access to all hyperdb classes as attributes of this variable. If you
1402 want access to the "user" class, for example, you would use::
1404 db/user
1405 python:db.user
1407 The access results in a `hyperdb class wrapper`_.
1409 The templates variable
1410 ~~~~~~~~~~~~~~~~~~~~~~
1412 Note: this is implemented by the roundup.cgi.templating.Templates class.
1414 This variable doesn't have any useful methods defined. It supports being
1415 used in expressions to access the templates, and subsequently the template
1416 macros. You may access the templates using the following path expression::
1418 templates/name
1420 or the python expression::
1422 templates[name]
1424 where "name" is the name of the template you wish to access. The template you
1425 get access to has one useful attribute, "macros". To access a specific macro
1426 (called "macro_name"), use the path expression::
1428 templates/name/macros/macro_name
1430 or the python expression::
1432 templates[name].macros[macro_name]
1435 The utils variable
1436 ~~~~~~~~~~~~~~~~~~
1438 Note: this is implemented by the roundup.cgi.templating.TemplatingUtils class,
1439 but it may be extended as described below.
1441 =============== =============================================================
1442 Method Description
1443 =============== =============================================================
1444 Batch return a batch object using the supplied list
1445 =============== =============================================================
1447 You may add additional utility methods by writing them in your tracker
1448 ``interfaces.py`` module's ``TemplatingUtils`` class. See `adding a time log
1449 to your issues`_ for an example. The TemplatingUtils class itself will have a
1450 single attribute, ``client``, which may be used to access the ``client.db``
1451 when you need to perform arbitrary database queries.
1453 Batching
1454 ::::::::
1456 Use Batch to turn a list of items, or item ids of a given class, into a series
1457 of batches. Its usage is::
1459 python:util.Batch(sequence, size, start, end=0, orphan=0, overlap=0)
1461 or, to get the current index batch::
1463 request/batch
1465 The parameters are:
1467 ========= ==================================================================
1468 Parameter Usage
1469 ========= ==================================================================
1470 sequence a list of HTMLItems
1471 size how big to make the sequence.
1472 start where to start (0-indexed) in the sequence.
1473 end where to end (0-indexed) in the sequence.
1474 orphan if the next batch would contain less items than this
1475 value, then it is combined with this batch
1476 overlap the number of items shared between adjacent batches
1477 ========= ==================================================================
1479 All of the parameters are assigned as attributes on the batch object. In
1480 addition, it has several more attributes:
1482 =============== ============================================================
1483 Attribute Description
1484 =============== ============================================================
1485 start indicates the start index of the batch. *Note: unlike the
1486 argument, is a 1-based index (I know, lame)*
1487 first indicates the start index of the batch *as a 0-based
1488 index*
1489 length the actual number of elements in the batch
1490 sequence_length the length of the original, unbatched, sequence.
1491 =============== ============================================================
1493 And several methods:
1495 =============== ============================================================
1496 Method Description
1497 =============== ============================================================
1498 previous returns a new Batch with the previous batch settings
1499 next returns a new Batch with the next batch settings
1500 propchanged detect if the named property changed on the current item
1501 when compared to the last item
1502 =============== ============================================================
1504 An example of batching::
1506 <table class="otherinfo">
1507 <tr><th colspan="4" class="header">Existing Keywords</th></tr>
1508 <tr tal:define="keywords db/keyword/list"
1509 tal:repeat="start python:range(0, len(keywords), 4)">
1510 <td tal:define="batch python:utils.Batch(keywords, 4, start)"
1511 tal:repeat="keyword batch" tal:content="keyword/name">keyword here</td>
1512 </tr>
1513 </table>
1515 ... which will produce a table with four columns containing the items of the
1516 "keyword" class (well, their "name" anyway).
1518 Displaying Properties
1519 ---------------------
1521 Properties appear in the user interface in three contexts: in indices, in
1522 editors, and as search arguments.
1523 For each type of property, there are several display possibilities.
1524 For example, in an index view, a string property may just be
1525 printed as a plain string, but in an editor view, that property may be
1526 displayed in an editable field.
1529 Index Views
1530 -----------
1532 This is one of the class context views. It is also the default view for
1533 classes. The template used is "*classname*.index".
1535 Index View Specifiers
1536 ~~~~~~~~~~~~~~~~~~~~~
1538 An index view specifier (URL fragment) looks like this (whitespace has been
1539 added for clarity)::
1541 /issue?status=unread,in-progress,resolved&
1542 topic=security,ui&
1543 :group=+priority&
1544 :sort==activity&
1545 :filters=status,topic&
1546 :columns=title,status,fixer
1548 The index view is determined by two parts of the specifier: the layout part and
1549 the filter part. The layout part consists of the query parameters that begin
1550 with colons, and it determines the way that the properties of selected items
1551 are displayed. The filter part consists of all the other query parameters, and
1552 it determines the criteria by which items are selected for display.
1553 The filter part is interactively manipulated with the form widgets displayed in
1554 the filter section. The layout part is interactively manipulated by clicking on
1555 the column headings in the table.
1557 The filter part selects the union of the sets of items with values matching any
1558 specified Link properties and the intersection of the sets of items with values
1559 matching any specified Multilink properties.
1561 The example specifies an index of "issue" items. Only items with a "status" of
1562 either "unread" or "in-progres" or "resolved" are displayed, and only items
1563 with "topic" values including both "security" and "ui" are displayed. The items
1564 are grouped by priority, arranged in ascending order; and within groups, sorted
1565 by activity, arranged in descending order. The filter section shows filters for
1566 the "status" and "topic" properties, and the table includes columns for the
1567 "title", "status", and "fixer" properties.
1569 Searching Views
1570 ---------------
1572 Note: if you add a new column to the ``:columns`` form variable potentials
1573 then you will need to add the column to the appropriate `index views`_
1574 template so it is actually displayed.
1576 This is one of the class context views. The template used is typically
1577 "*classname*.search". The form on this page should have "search" as its
1578 ``:action`` variable. The "search" action:
1580 - sets up additional filtering, as well as performing indexed text searching
1581 - sets the ``:filter`` variable correctly
1582 - saves the query off if ``:query_name`` is set.
1584 The searching page should lay out any fields that you wish to allow the user
1585 to search one. If your schema contains a large number of properties, you
1586 should be wary of making all of those properties available for searching, as
1587 this can cause confusion. If the additional properties are Strings, consider
1588 having their value indexed, and then they will be searchable using the full
1589 text indexed search. This is both faster, and more useful for the end user.
1591 The two special form values on search pages which are handled by the "search"
1592 action are:
1594 :search_text
1595 Text to perform a search of the text index with. Results from that search
1596 will be used to limit the results of other filters (using an intersection
1597 operation)
1598 :query_name
1599 If supplied, the search parameters (including :search_text) will be saved
1600 off as a the query item and registered against the user's queries property.
1601 Note that the *classic* template schema has this ability, but the *minimal*
1602 template schema does not.
1605 Item Views
1606 ----------
1608 The basic view of a hyperdb item is provided by the "*classname*.item"
1609 template. It generally has three sections; an "editor", a "spool" and a
1610 "history" section.
1614 Editor Section
1615 ~~~~~~~~~~~~~~
1617 The editor section is used to manipulate the item - it may be a
1618 static display if the user doesn't have permission to edit the item.
1620 Here's an example of a basic editor template (this is the default "classic"
1621 template issue item edit form - from the "issue.item" template)::
1623 <table class="form">
1624 <tr>
1625 <th nowrap>Title</th>
1626 <td colspan=3 tal:content="structure python:context.title.field(size=60)">title</td>
1627 </tr>
1629 <tr>
1630 <th nowrap>Priority</th>
1631 <td tal:content="structure context/priority/menu">priority</td>
1632 <th nowrap>Status</th>
1633 <td tal:content="structure context/status/menu">status</td>
1634 </tr>
1636 <tr>
1637 <th nowrap>Superseder</th>
1638 <td>
1639 <span tal:replace="structure python:context.superseder.field(showid=1, size=20)" />
1640 <span tal:replace="structure python:db.issue.classhelp('id,title')" />
1641 <span tal:condition="context/superseder">
1642 <br>View: <span tal:replace="structure python:context.superseder.link(showid=1)" />
1643 </span>
1644 </td>
1645 <th nowrap>Nosy List</th>
1646 <td>
1647 <span tal:replace="structure context/nosy/field" />
1648 <span tal:replace="structure python:db.user.classhelp('username,realname,address,phone')" />
1649 </td>
1650 </tr>
1652 <tr>
1653 <th nowrap>Assigned To</th>
1654 <td tal:content="structure context/assignedto/menu">
1655 assignedto menu
1656 </td>
1657 <td> </td>
1658 <td> </td>
1659 </tr>
1661 <tr>
1662 <th nowrap>Change Note</th>
1663 <td colspan=3>
1664 <textarea name=":note" wrap="hard" rows="5" cols="60"></textarea>
1665 </td>
1666 </tr>
1668 <tr>
1669 <th nowrap>File</th>
1670 <td colspan=3><input type="file" name=":file" size="40"></td>
1671 </tr>
1673 <tr>
1674 <td> </td>
1675 <td colspan=3 tal:content="structure context/submit">
1676 submit button will go here
1677 </td>
1678 </tr>
1679 </table>
1682 When a change is submitted, the system automatically generates a message
1683 describing the changed properties. As shown in the example, the editor
1684 template can use the ":note" and ":file" fields, which are added to the
1685 standard change note message generated by Roundup.
1687 Spool Section
1688 ~~~~~~~~~~~~~
1690 The spool section lists related information like the messages and files of
1691 an issue.
1693 TODO
1696 History Section
1697 ~~~~~~~~~~~~~~~
1699 The final section displayed is the history of the item - its database journal.
1700 This is generally generated with the template::
1702 <tal:block tal:replace="structure context/history" />
1704 *To be done:*
1706 *The actual history entries of the item may be accessed for manual templating
1707 through the "journal" method of the item*::
1709 <tal:block tal:repeat="entry context/journal">
1710 a journal entry
1711 </tal:block>
1713 *where each journal entry is an HTMLJournalEntry.*
1715 Defining new web actions
1716 ------------------------
1718 You may define new actions to be triggered by the ``:action`` form variable.
1719 These are added to the tracker ``interfaces.py`` as methods on the ``Client``
1720 class.
1722 Adding action methods takes three steps; first you `define the new action
1723 method`_, then you `register the action method`_ with the cgi interface so
1724 it may be triggered by the ``:action`` form variable. Finally you actually
1725 `use the new action`_ in your HTML form.
1727 See "`setting up a "wizard" (or "druid") for controlled adding of issues`_"
1728 for an example.
1730 Define the new action method
1731 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1733 The action methods have the following interface::
1735 def myActionMethod(self):
1736 ''' Perform some action. No return value is required.
1737 '''
1739 The *self* argument is an instance of your tracker ``instance.Client`` class -
1740 thus it's mostly implemented by ``roundup.cgi.Client``. See the docstring of
1741 that class for details of what it can do.
1743 The method will typically check the ``self.form`` variable's contents. It
1744 may then:
1746 - add information to ``self.ok_message`` or ``self.error_message``
1747 - change the ``self.template`` variable to alter what the user will see next
1748 - raise Unauthorised, SendStaticFile, SendFile, NotFound or Redirect
1749 exceptions
1752 Register the action method
1753 ~~~~~~~~~~~~~~~~~~~~~~~~~~
1755 The method is now written, but isn't available to the user until you add it to
1756 the `instance.Client`` class ``actions`` variable, like so::
1758 actions = client.Class.actions + (
1759 ('myaction', 'myActionMethod'),
1760 )
1762 This maps the action name "myaction" to the action method we defined.
1765 Use the new action
1766 ~~~~~~~~~~~~~~~~~~
1768 In your HTML form, add a hidden form element like so::
1770 <input type="hidden" name=":action" value="myaction">
1772 where "myaction" is the name you registered in the previous step.
1775 Examples
1776 ========
1778 .. contents::
1779 :local:
1780 :depth: 1
1782 Adding a new field to the classic schema
1783 ----------------------------------------
1785 This example shows how to add a new constrained property (ie. a selection of
1786 distinct values) to your tracker.
1788 Introduction
1789 ~~~~~~~~~~~~
1791 To make the classic schema of roundup useful as a todo tracking system
1792 for a group of systems administrators, it needed an extra data field
1793 per issue: a category.
1795 This would let sysads quickly list all todos in their particular
1796 area of interest without having to do complex queries, and without
1797 relying on the spelling capabilities of other sysads (a losing
1798 proposition at best).
1800 Adding a field to the database
1801 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1803 This is the easiest part of the change. The category would just be a plain
1804 string, nothing fancy. To change what is in the database you need to add
1805 some lines to the ``open()`` function in ``dbinit.py`` under the comment::
1807 # add any additional database schema configuration here
1809 add::
1811 category = Class(db, "category", name=String())
1812 category.setkey("name")
1814 Here we are setting up a chunk of the database which we are calling
1815 "category". It contains a string, which we are refering to as "name" for
1816 lack of a more imaginative title. Then we are setting the key of this chunk
1817 of the database to be that "name". This is equivalent to an index for
1818 database types. This also means that there can only be one category with a
1819 given name.
1821 Adding the above lines allows us to create categories, but they're not tied
1822 to the issues that we are going to be creating. It's just a list of categories
1823 off on its own, which isn't much use. We need to link it in with the issues.
1824 To do that, find the lines in the ``open()`` function in ``dbinit.py`` which
1825 set up the "issue" class, and then add a link to the category::
1827 issue = IssueClass(db, "issue", ... , category=Multilink("category"), ... )
1829 The Multilink() means that each issue can have many categories. If you were
1830 adding something with a more one to one relationship use Link() instead.
1832 That is all you need to do to change the schema. The rest of the effort is
1833 fiddling around so you can actually use the new category.
1835 Populating the new category class
1836 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1838 If you haven't initialised the database with the roundup-admin "initialise"
1839 command, then you can add the following to the tracker ``dbinit.py`` in the
1840 ``init()`` function under the comment::
1842 # add any additional database create steps here - but only if you
1843 # haven't initialised the database with the admin "initialise" command
1845 add::
1847 category = db.getclass('category')
1848 category.create(name="scipy", order="1")
1849 category.create(name="chaco", order="2")
1850 category.create(name="weave", order="3")
1852 If the database is initalised, the you need to use the roundup-admin tool::
1854 % roundup-admin -i <tracker home>
1855 Roundup <version> ready for input.
1856 Type "help" for help.
1857 roundup> create category name=scipy order=1
1858 1
1859 roundup> create category name=chaco order=1
1860 2
1861 roundup> create category name=weave order=1
1862 3
1863 roundup> exit...
1864 There are unsaved changes. Commit them (y/N)? y
1867 Setting up security on the new objects
1868 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1870 By default only the admin user can look at and change objects. This doesn't
1871 suit us, as we want any user to be able to create new categories as
1872 required, and obviously everyone needs to be able to view the categories of
1873 issues for it to be useful.
1875 We therefore need to change the security of the category objects. This is
1876 also done in the ``open()`` function of ``dbinit.py``.
1878 There are currently two loops which set up permissions and then assign them
1879 to various roles. Simply add the new "category" to both lists::
1881 # new permissions for this schema
1882 for cl in 'issue', 'file', 'msg', 'user', 'category':
1883 db.security.addPermission(name="Edit", klass=cl,
1884 description="User is allowed to edit "+cl)
1885 db.security.addPermission(name="View", klass=cl,
1886 description="User is allowed to access "+cl)
1888 # Assign the access and edit permissions for issue, file and message
1889 # to regular users now
1890 for cl in 'issue', 'file', 'msg', 'category':
1891 p = db.security.getPermission('View', cl)
1892 db.security.addPermissionToRole('User', p)
1893 p = db.security.getPermission('Edit', cl)
1894 db.security.addPermissionToRole('User', p)
1896 So you are in effect doing the following::
1898 db.security.addPermission(name="Edit", klass='category',
1899 description="User is allowed to edit "+'category')
1900 db.security.addPermission(name="View", klass='category',
1901 description="User is allowed to access "+'category')
1903 which is creating two permission types; that of editing and viewing
1904 "category" objects respectively. Then the following lines assign those new
1905 permissions to the "User" role, so that normal users can view and edit
1906 "category" objects::
1908 p = db.security.getPermission('View', 'category')
1909 db.security.addPermissionToRole('User', p)
1911 p = db.security.getPermission('Edit', 'category')
1912 db.security.addPermissionToRole('User', p)
1914 This is all the work that needs to be done for the database. It will store
1915 categories, and let users view and edit them. Now on to the interface
1916 stuff.
1918 Changing the web left hand frame
1919 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1921 We need to give the users the ability to create new categories, and the
1922 place to put the link to this functionality is in the left hand function
1923 bar, under the "Issues" area. The file that defines how this area looks is
1924 ``html/page``, which is what we are going to be editing next.
1926 If you look at this file you can see that it contains a lot of "classblock"
1927 sections which are chunks of HTML that will be included or excluded in the
1928 output depending on whether the condition in the classblock is met. Under
1929 the end of the classblock for issue is where we are going to add the
1930 category code::
1932 <p class="classblock"
1933 tal:condition="python:request.user.hasPermission('View', 'category')">
1934 <b>Categories</b><br>
1935 <a tal:condition="python:request.user.hasPermission('Edit', 'category')"
1936 href="category?:template=item">New Category<br></a>
1937 </p>
1939 The first two lines is the classblock definition, which sets up a condition
1940 that only users who have "View" permission to the "category" object will
1941 have this section included in their output. Next comes a plain "Categories"
1942 header in bold. Everyone who can view categories will get that.
1944 Next comes the link to the editing area of categories. This link will only
1945 appear if the condition is matched: that condition being that the user has
1946 "Edit" permissions for the "category" objects. If they do have permission
1947 then they will get a link to another page which will let the user add new
1948 categories.
1950 Note that if you have permission to view but not edit categories then all
1951 you will see is a "Categories" header with nothing underneath it. This is
1952 obviously not very good interface design, but will do for now. I just claim
1953 that it is so I can add more links in this section later on. However to fix
1954 the problem you could change the condition in the classblock statement, so
1955 that only users with "Edit" permission would see the "Categories" stuff.
1957 Setting up a page to edit categories
1958 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1960 We defined code in the previous section which let users with the
1961 appropriate permissions see a link to a page which would let them edit
1962 conditions. Now we have to write that page.
1964 The link was for the item template for the category object. This translates
1965 into the system looking for a file called ``category.item`` in the ``html``
1966 tracker directory. This is the file that we are going to write now.
1968 First we add an info tag in a comment which doesn't affect the outcome
1969 of the code at all but is useful for debugging. If you load a page in a
1970 browser and look at the page source, you can see which sections come
1971 from which files by looking for these comments::
1973 <!-- category.item -->
1975 Next we need to add in the METAL macro stuff so we get the normal page
1976 trappings::
1978 <tal:block metal:use-macro="templates/page/macros/icing">
1979 <title metal:fill-slot="head_title">Category editing</title>
1980 <td class="page-header-top" metal:fill-slot="body_title">
1981 <h2>Category editing</h2>
1982 </td>
1983 <td class="content" metal:fill-slot="content">
1985 Next we need to setup up a standard HTML form, which is the whole
1986 purpose of this file. We link to some handy javascript which sends the form
1987 through only once. This is to stop users hitting the send button
1988 multiple times when they are impatient and thus having the form sent
1989 multiple times::
1991 <form method="POST" onSubmit="return submit_once()"
1992 enctype="multipart/form-data">
1994 Next we define some code which sets up the minimum list of fields that we
1995 require the user to enter. There will be only one field, that of "name", so
1996 they user better put something in it otherwise the whole form is pointless::
1998 <input type="hidden" name=":required" value="name">
2000 To get everything to line up properly we will put everything in a table,
2001 and put a nice big header on it so the user has an idea what is happening::
2003 <table class="form">
2004 <tr><th class="header" colspan=2>Category</th></tr>
2006 Next we need the actual field that the user is going to enter the new
2007 category. The "context.name.field(size=60)" bit tells roundup to generate a
2008 normal HTML field of size 60, and the contents of that field will be the
2009 "name" variable of the current context (which is "category"). The upshot of
2010 this is that when the user types something in to the form, a new category
2011 will be created with that name::
2013 <tr>
2014 <th nowrap>Name</th>
2015 <td tal:content="structure python:context.name.field(size=60)">name</td>
2016 </tr>
2018 Then a submit button so that the user can submit the new category::
2020 <tr>
2021 <td> </td>
2022 <td colspan=3 tal:content="structure context/submit">
2023 submit button will go here
2024 </td>
2025 </tr>
2027 Finally we finish off the tags we used at the start to do the METAL stuff::
2029 </td>
2030 </tal:block>
2032 So putting it all together, and closing the table and form we get::
2034 <!-- category.item -->
2035 <tal:block metal:use-macro="templates/page/macros/icing">
2036 <title metal:fill-slot="head_title">Category editing</title>
2037 <td class="page-header-top" metal:fill-slot="body_title">
2038 <h2>Category editing</h2>
2039 </td>
2040 <td class="content" metal:fill-slot="content">
2041 <form method="POST" onSubmit="return submit_once()"
2042 enctype="multipart/form-data">
2044 <input type="hidden" name=":required" value="name">
2046 <table class="form">
2047 <tr><th class="header" colspan=2>Category</th></tr>
2049 <tr>
2050 <th nowrap>Name</th>
2051 <td tal:content="structure python:context.name.field(size=60)">name</td>
2052 </tr>
2054 <tr>
2055 <td> </td>
2056 <td colspan=3 tal:content="structure context/submit">
2057 submit button will go here
2058 </td>
2059 </tr>
2060 </table>
2061 </form>
2062 </td>
2063 </tal:block>
2065 This is quite a lot to just ask the user one simple question, but
2066 there is a lot of setup for basically one line (the form line) to do
2067 its work. To add another field to "category" would involve one more line
2068 (well maybe a few extra to get the formatting correct).
2070 Adding the category to the issue
2071 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2073 We now have the ability to create issues to our hearts content, but
2074 that is pointless unless we can assign categories to issues. Just like
2075 the ``html/category.item`` file was used to define how to add a new
2076 category, the ``html/issue.item`` is used to define how a new issue is
2077 created.
2079 Just like ``category.issue`` this file defines a form which has a table to lay
2080 things out. It doesn't matter where in the table we add new stuff,
2081 it is entirely up to your sense of aesthetics::
2083 <th nowrap>Category</th>
2084 <td><span tal:replace="structure context/category/field" />
2085 <span tal:replace="structure db/category/classhelp" />
2086 </td>
2088 First we define a nice header so that the user knows what the next section
2089 is, then the middle line does what we are most interested in. This
2090 ``context/category/field`` gets replaced with a field which contains the
2091 category in the current context (the current context being the new issue).
2093 The classhelp lines generate a link (labelled "list") to a popup window
2094 which contains the list of currently known categories.
2096 Searching on categories
2097 ~~~~~~~~~~~~~~~~~~~~~~~
2099 We can add categories, and create issues with categories. The next obvious
2100 thing that we would like to be would be to search issues based on their
2101 category, so that any one working on the web server could look at all
2102 issues in the category "Web" for example.
2104 If you look in the html/page file and look for the "Search Issues" you will
2105 see that it looks something like ``<a href="issue?:template=search">Search
2106 Issues</a>`` which shows us that when you click on "Search Issues" it will
2107 be looking for a ``issue.search`` file to display. So that is indeed the file
2108 that we are going to change.
2110 If you look at this file it should be starting to seem familiar. It is a
2111 simple HTML form using a table to define structure. You can add the new
2112 category search code anywhere you like within that form::
2114 <tr>
2115 <th>Category:</th>
2116 <td>
2117 <select name="category">
2118 <option value="">don't care</option>
2119 <option value="">------------</option>
2120 <option tal:repeat="s db/category/list" tal:attributes="value s/name"
2121 tal:content="s/name">category to filter on</option>
2122 </select>
2123 </td>
2124 <td><input type="checkbox" name=":columns" value="category" checked></td>
2125 <td><input type="radio" name=":sort" value="category"></td>
2126 <td><input type="radio" name=":group" value="category"></td>
2127 </tr>
2129 Most of this is straightforward to anyone who knows HTML. It is just
2130 setting up a select list followed by a checkbox and a couple of radio
2131 buttons.
2133 The ``tal:repeat`` part repeats the tag for every item in the "category"
2134 table and setting "s" to be each category in turn.
2136 The ``tal:attributes`` part is setting up the ``value=`` part of the option tag
2137 to be the name part of "s" which is the current category in the loop.
2139 The ``tal:content`` part is setting the contents of the option tag to be the
2140 name part of "s" again. For objects more complex than category, obviously
2141 you would put an id in the value, and the descriptive part in the content;
2142 but for category they are the same.
2144 Adding category to the default view
2145 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2147 We can now add categories, add issues with categories, and search issues
2148 based on categories. This is everything that we need to do, however there
2149 is some more icing that we would like. I think the category of an issue is
2150 important enough that it should be displayed by default when listing all
2151 the issues.
2153 Unfortunately, this is a bit less obvious than the previous steps. The code
2154 defining how the issues look is in ``html/issue.index``. This is a large table
2155 with a form down the bottom for redisplaying and so forth.
2157 Firstly we need to add an appropriate header to the start of the table::
2159 <th tal:condition="request/show/category">Category</th>
2161 The condition part of this statement is so that if the user has selected
2162 not to see the Category column then they won't.
2164 The rest of the table is a loop which will go through every issue that
2165 matches the display criteria. The loop variable is "i" - which means that
2166 every issue gets assigned to "i" in turn.
2168 The new part of code to display the category will look like this::
2170 <td tal:condition="request/show/category" tal:content="i/category"></td>
2172 The condition is the same as above: only display the condition when the
2173 user hasn't asked for it to be hidden. The next part is to set the content
2174 of the cell to be the category part of "i" - the current issue.
2176 Finally we have to edit ``html/page`` again. This time to tell it that when the
2177 user clicks on "Unnasigned Issues" or "All Issues" that the category should
2178 be displayed. If you scroll down the page file, you can see the links with
2179 lots of options. The option that we are interested in is the ``:columns=`` one
2180 which tells roundup which fields of the issue to display. Simply add
2181 "category" to that list and it all should work.
2184 Adding in state transition control
2185 ----------------------------------
2187 Sometimes tracker admins want to control the states that users may move issues
2188 to.
2190 1. make "status" a required variable. This is achieved by adding the
2191 following to the top of the form in the ``issue.item`` template::
2193 <input type="hidden" name="@required" value="status">
2195 this will force users to select a status.
2197 2. add a Multilink property to the status class::
2199 stat = Class(db, "status", ... , transitions=Multilink('status'), ...)
2201 and then edit the statuses already created either:
2203 a. through the web using the class list -> status class editor, or
2204 b. using the roundup-admin "set" command.
2206 3. add an auditor module ``checktransition.py`` in your tracker's
2207 ``detectors`` directory::
2209 def checktransition(db, cl, nodeid, newvalues):
2210 ''' Check that the desired transition is valid for the "status"
2211 property.
2212 '''
2213 if not newvalues.has_key('status'):
2214 return
2215 current = cl.get(nodeid, 'status')
2216 new = newvalues['status']
2217 if new == current:
2218 return
2219 ok = db.status.get(current, 'transitions')
2220 if new not in ok:
2221 raise ValueError, 'Status not allowed to move from "%s" to "%s"'%(
2222 db.status.get(current, 'name'), db.status.get(new, 'name'))
2224 def init(db):
2225 db.issue.audit('set', checktransition)
2227 4. in the ``issue.item`` template, change the status editing bit from::
2229 <th nowrap>Status</th>
2230 <td tal:content="structure context/status/menu">status</td>
2232 to::
2234 <th nowrap>Status</th>
2235 <td>
2236 <select tal:condition="context/id" name="status">
2237 <tal:block tal:define="ok context/status/transitions"
2238 tal:repeat="state db/status/list">
2239 <option tal:condition="python:state.id in ok"
2240 tal:attributes="value state/id;
2241 selected python:state.id == context.status.id"
2242 tal:content="state/name"></option>
2243 </tal:block>
2244 </select>
2245 <tal:block tal:condition="not:context/id"
2246 tal:replace="structure context/status/menu" />
2247 </td>
2249 which displays only the allowed status to transition to.
2252 Displaying only message summaries in the issue display
2253 ------------------------------------------------------
2255 Alter the issue.item template section for messages to::
2257 <table class="messages" tal:condition="context/messages">
2258 <tr><th colspan=5 class="header">Messages</th></tr>
2259 <tr tal:repeat="msg context/messages">
2260 <td><a tal:attributes="href string:msg${msg/id}"
2261 tal:content="string:msg${msg/id}"></a></td>
2262 <td tal:content="msg/author">author</td>
2263 <td nowrap tal:content="msg/date/pretty">date</td>
2264 <td tal:content="msg/summary">summary</td>
2265 <td>
2266 <a tal:attributes="href string:?:remove:messages=${msg/id}&:action=edit">remove</a>
2267 </td>
2268 </tr>
2269 </table>
2271 Restricting the list of users that are assignable to a task
2272 -----------------------------------------------------------
2274 1. In your tracker's "dbinit.py", create a new Role, say "Developer"::
2276 db.security.addRole(name='Developer', description='A developer')
2278 2. Just after that, create a new Permission, say "Fixer", specific to "issue"::
2280 p = db.security.addPermission(name='Fixer', klass='issue',
2281 description='User is allowed to be assigned to fix issues')
2283 3. Then assign the new Permission to your "Developer" Role::
2285 db.security.addPermissionToRole('Developer', p)
2287 4. In the issue item edit page ("html/issue.item" in your tracker dir), use
2288 the new Permission in restricting the "assignedto" list::
2290 <select name="assignedto">
2291 <option value="-1">- no selection -</option>
2292 <tal:block tal:repeat="user db/user/list">
2293 <option tal:condition="python:user.hasPermission('Fixer', context._classname)"
2294 tal:attributes="value user/id;
2295 selected python:user.id == context.assignedto"
2296 tal:content="user/realname"></option>
2297 </tal:block>
2298 </select>
2300 For extra security, you may wish to set up an auditor to enforce the
2301 Permission requirement (install this as "assignedtoFixer.py" in your tracker
2302 "detectors" directory)::
2304 def assignedtoMustBeFixer(db, cl, nodeid, newvalues):
2305 ''' Ensure the assignedto value in newvalues is a used with the Fixer
2306 Permission
2307 '''
2308 if not newvalues.has_key('assignedto'):
2309 # don't care
2310 return
2312 # get the userid
2313 userid = newvalues['assignedto']
2314 if not db.security.hasPermission('Fixer', userid, cl.classname):
2315 raise ValueError, 'You do not have permission to edit %s'%cl.classname
2317 def init(db):
2318 db.issue.audit('set', assignedtoMustBeFixer)
2319 db.issue.audit('create', assignedtoMustBeFixer)
2321 So now, if the edit attempts to set the assignedto to a user that doesn't have
2322 the "Fixer" Permission, the error will be raised.
2325 Setting up a "wizard" (or "druid") for controlled adding of issues
2326 ------------------------------------------------------------------
2328 1. Set up the page templates you wish to use for data input. My wizard
2329 is going to be a two-step process, first figuring out what category of
2330 issue the user is submitting, and then getting details specific to that
2331 category. The first page includes a table of help, explaining what the
2332 category names mean, and then the core of the form::
2334 <form method="POST" onSubmit="return submit_once()"
2335 enctype="multipart/form-data">
2336 <input type="hidden" name=":template" value="add_page1">
2337 <input type="hidden" name=":action" value="page1submit">
2339 <strong>Category:</strong>
2340 <tal:block tal:replace="structure context/category/menu" />
2341 <input type="submit" value="Continue">
2342 </form>
2344 The next page has the usual issue entry information, with the addition of
2345 the following form fragments::
2347 <form method="POST" onSubmit="return submit_once()"
2348 enctype="multipart/form-data" tal:condition="context/is_edit_ok"
2349 tal:define="cat request/form/category/value">
2351 <input type="hidden" name=":template" value="add_page2">
2352 <input type="hidden" name=":required" value="title">
2353 <input type="hidden" name="category" tal:attributes="value cat">
2355 .
2356 .
2357 .
2358 </form>
2360 Note that later in the form, I test the value of "cat" include form
2361 elements that are appropriate. For example::
2363 <tal:block tal:condition="python:cat in '6 10 13 14 15 16 17'.split()">
2364 <tr>
2365 <th nowrap>Operating System</th>
2366 <td tal:content="structure context/os/field"></td>
2367 </tr>
2368 <tr>
2369 <th nowrap>Web Browser</th>
2370 <td tal:content="structure context/browser/field"></td>
2371 </tr>
2372 </tal:block>
2374 ... the above section will only be displayed if the category is one of 6,
2375 10, 13, 14, 15, 16 or 17.
2377 3. Determine what actions need to be taken between the pages - these are
2378 usually to validate user choices and determine what page is next. Now
2379 encode those actions in methods on the interfaces Client class and insert
2380 hooks to those actions in the "actions" attribute on that class, like so::
2382 actions = client.Client.actions + (
2383 ('page1_submit', 'page1SubmitAction'),
2384 )
2386 def page1SubmitAction(self):
2387 ''' Verify that the user has selected a category, and then move on
2388 to page 2.
2389 '''
2390 category = self.form['category'].value
2391 if category == '-1':
2392 self.error_message.append('You must select a category of report')
2393 return
2394 # everything's ok, move on to the next page
2395 self.template = 'add_page2'
2397 4. Use the usual "new" action as the :action on the final page, and you're
2398 done (the standard context/submit method can do this for you).
2401 Using an external password validation source
2402 --------------------------------------------
2404 We have a centrally-managed password changing system for our users. This
2405 results in a UN*X passwd-style file that we use for verification of users.
2406 Entries in the file consist of ``name:password`` where the password is
2407 encrypted using the standard UN*X ``crypt()`` function (see the ``crypt``
2408 module in your Python distribution). An example entry would be::
2410 admin:aamrgyQfDFSHw
2412 Each user of Roundup must still have their information stored in the Roundup
2413 database - we just use the passwd file to check their password. To do this, we
2414 add the following code to our ``Client`` class in the tracker home
2415 ``interfaces.py`` module::
2417 def verifyPassword(self, userid, password):
2418 # get the user's username
2419 username = self.db.user.get(userid, 'username')
2421 # the passwords are stored in the "passwd.txt" file in the tracker
2422 # home
2423 file = os.path.join(self.db.config.TRACKER_HOME, 'passwd.txt')
2425 # see if we can find a match
2426 for ent in [line.strip().split(':') for line in open(file).readlines()]:
2427 if ent[0] == username:
2428 return crypt.crypt(password, ent[1][:2]) == ent[1]
2430 # user doesn't exist in the file
2431 return 0
2433 What this does is look through the file, line by line, looking for a name that
2434 matches.
2436 We also remove the redundant password fields from the ``user.item`` template.
2439 Adding a "vacation" flag to users for stopping nosy messages
2440 ------------------------------------------------------------
2442 When users go on vacation and set up vacation email bouncing, you'll start to
2443 see a lot of messages come back through Roundup "Fred is on vacation". Not
2444 very useful, and relatively easy to stop.
2446 1. add a "vacation" flag to your users::
2448 user = Class(db, "user",
2449 username=String(), password=Password(),
2450 address=String(), realname=String(),
2451 phone=String(), organisation=String(),
2452 alternate_addresses=String(),
2453 roles=String(), queries=Multilink("query"),
2454 vacation=Boolean())
2456 2. So that users may edit the vacation flags, add something like the
2457 following to your ``user.item`` template::
2459 <tr>
2460 <th>On Vacation</th>
2461 <td tal:content="structure context/vacation/field">vacation</td>
2462 </tr>
2464 3. edit your detector ``nosyreactor.py`` so that the ``nosyreaction()``
2465 consists of::
2467 def nosyreaction(db, cl, nodeid, oldvalues):
2468 # send a copy of all new messages to the nosy list
2469 for msgid in determineNewMessages(cl, nodeid, oldvalues):
2470 try:
2471 users = db.user
2472 messages = db.msg
2474 # figure the recipient ids
2475 sendto = []
2476 r = {}
2477 recipients = messages.get(msgid, 'recipients')
2478 for recipid in messages.get(msgid, 'recipients'):
2479 r[recipid] = 1
2481 # figure the author's id, and indicate they've received the
2482 # message
2483 authid = messages.get(msgid, 'author')
2485 # possibly send the message to the author, as long as they aren't
2486 # anonymous
2487 if (db.config.MESSAGES_TO_AUTHOR == 'yes' and
2488 users.get(authid, 'username') != 'anonymous'):
2489 sendto.append(authid)
2490 r[authid] = 1
2492 # now figure the nosy people who weren't recipients
2493 nosy = cl.get(nodeid, 'nosy')
2494 for nosyid in nosy:
2495 # Don't send nosy mail to the anonymous user (that user
2496 # shouldn't appear in the nosy list, but just in case they
2497 # do...)
2498 if users.get(nosyid, 'username') == 'anonymous':
2499 continue
2500 # make sure they haven't seen the message already
2501 if not r.has_key(nosyid):
2502 # send it to them
2503 sendto.append(nosyid)
2504 recipients.append(nosyid)
2506 # generate a change note
2507 if oldvalues:
2508 note = cl.generateChangeNote(nodeid, oldvalues)
2509 else:
2510 note = cl.generateCreateNote(nodeid)
2512 # we have new recipients
2513 if sendto:
2514 # filter out the people on vacation
2515 sendto = [i for i in sendto if not users.get(i, 'vacation', 0)]
2517 # map userids to addresses
2518 sendto = [users.get(i, 'address') for i in sendto]
2520 # update the message's recipients list
2521 messages.set(msgid, recipients=recipients)
2523 # send the message
2524 cl.send_message(nodeid, msgid, note, sendto)
2525 except roundupdb.MessageSendError, message:
2526 raise roundupdb.DetectorError, message
2528 Note that this is the standard nosy reaction code, with the small addition
2529 of::
2531 # filter out the people on vacation
2532 sendto = [i for i in sendto if not users.get(i, 'vacation', 0)]
2534 which filters out the users that have the vacation flag set to true.
2537 Adding a time log to your issues
2538 --------------------------------
2540 We want to log the dates and amount of time spent working on issues, and be
2541 able to give a summary of the total time spent on a particular issue.
2543 1. Add a new class to your tracker ``dbinit.py``::
2545 # storage for time logging
2546 timelog = Class(db, "timelog", period=Interval())
2548 Note that we automatically get the date of the time log entry creation
2549 through the standard property "creation".
2551 2. Link to the new class from your issue class (again, in ``dbinit.py``)::
2553 issue = IssueClass(db, "issue",
2554 assignedto=Link("user"), topic=Multilink("keyword"),
2555 priority=Link("priority"), status=Link("status"),
2556 times=Multilink("timelog"))
2558 the "times" property is the new link to the "timelog" class.
2560 3. We'll need to let people add in times to the issue, so in the web interface
2561 we'll have a new entry field, just below the change note box::
2563 <tr>
2564 <th nowrap>Time Log</th>
2565 <td colspan=3><input name=":timelog">
2566 (enter as "3y 1m 4d 2:40:02" or parts thereof)
2567 </td>
2568 </tr>
2570 Note that we've made up a new form variable, but since we place a colon ":"
2571 in front of it, it won't clash with any existing property variables. The
2572 names you *can't* use are ``:note``, ``:file``, ``:action``, ``:required``
2573 and ``:template``. These variables are described in the section
2574 `performing actions in web requests`_.
2576 4. We also need to handle this new field in the CGI interface - the way to
2577 do this is through implementing a new form action (see `Setting up a
2578 "wizard" (or "druid") for controlled adding of issues`_ for another example
2579 where we implemented a new CGI form action).
2581 In this case, we'll want our action to:
2583 1. create a new "timelog" entry,
2584 2. fake that the issue's "times" property has been edited, and then
2585 3. call the normal CGI edit action handler.
2587 The code to do this is::
2589 class Client(client.Client):
2590 ''' derives basic CGI implementation from the standard module,
2591 with any specific extensions
2592 '''
2593 actions = client.Client.actions + (
2594 ('edit_with_timelog', 'timelogEditAction'),
2595 ('new_with_timelog', 'timelogEditAction'),
2596 )
2598 def timelogEditAction(self):
2599 ''' Handle the creation of a new time log entry if necessary.
2601 If we create a new entry, fake up a CGI form value for the
2602 altered "times" property of the issue being edited.
2604 Punt to the regular edit action when we're done.
2605 '''
2606 # if there's a timelog value specified, create an entry
2607 if self.form.has_key(':timelog') and \
2608 self.form[':timelog'].value.strip():
2609 period = Interval(self.form[':timelog'].value)
2610 # create it
2611 newid = self.db.timelog.create(period=period)
2613 # if we're editing an existing item, get the old timelog value
2614 if self.nodeid:
2615 l = self.db.issue.get(self.nodeid, 'times')
2616 l.append(newid)
2617 else:
2618 l = [newid]
2620 # now make the fake CGI form values
2621 for entry in l:
2622 self.form.list.append(MiniFieldStorage('times', entry))
2624 # punt to the normal edit action
2625 if self.nodeid:
2626 return self.editItemAction()
2627 else:
2628 return self.newItemAction()
2630 you add this code to your Client class in your tracker's ``interfaces.py``
2631 file. Locate the section that looks like::
2633 class Client:
2634 ''' derives basic CGI implementation from the standard module,
2635 with any specific extensions
2636 '''
2637 pass
2639 and insert this code in place of the ``pass`` statement.
2641 5. You'll also need to modify your ``issue.item`` form submit action so it
2642 calls the time logging action we just created. The current template will
2643 look like this::
2645 <tr>
2646 <td> </td>
2647 <td colspan=3 tal:content="structure context/submit">
2648 submit button will go here
2649 </td>
2650 </tr>
2652 replace it with this::
2654 <tr>
2655 <td> </td>
2656 <td colspan=3>
2657 <tal:block tal:condition="context/id">
2658 <input type="hidden" name=":action" value="edit_with_timelog">
2659 <input type="submit" name="submit" value="Submit Changes">
2660 </tal:block>
2661 <tal:block tal:condition="not:context/id">
2662 <input type="hidden" name=":action" value="new_with_timelog">
2663 <input type="submit" name="submit" value="Submit New Issue">
2664 </tal:block>
2665 </td>
2666 </tr>
2668 The important change is setting the action to "edit_with_timelog" for
2669 edit operations (where the item exists) and "new_with_timelog" for
2670 creations operations.
2672 6. We want to display a total of the time log times that have been accumulated
2673 for an issue. To do this, we'll need to actually write some Python code,
2674 since it's beyond the scope of PageTemplates to perform such calculations.
2675 We do this by adding a method to the TemplatingUtils class in our tracker
2676 ``interfaces.py`` module::
2678 class TemplatingUtils:
2679 ''' Methods implemented on this class will be available to HTML
2680 templates through the 'utils' variable.
2681 '''
2682 def totalTimeSpent(self, times):
2683 ''' Call me with a list of timelog items (which have an Interval
2684 "period" property)
2685 '''
2686 total = Interval('')
2687 for time in times:
2688 total += time.period._value
2689 return total
2691 Replace the ``pass`` line as we did in step 4 above with the Client class.
2692 As indicated in the docstrings, we will be able to access the
2693 ``totalTimeSpent`` method via the ``utils`` variable in our templates.
2695 7. Display the time log for an issue::
2697 <table class="otherinfo" tal:condition="context/times">
2698 <tr><th colspan="3" class="header">Time Log
2699 <tal:block tal:replace="python:utils.totalTimeSpent(context.times)" />
2700 </th></tr>
2701 <tr><th>Date</th><th>Period</th><th>Logged By</th></tr>
2702 <tr tal:repeat="time context/times">
2703 <td tal:content="time/creation"></td>
2704 <td tal:content="time/period"></td>
2705 <td tal:content="time/creator"></td>
2706 </tr>
2707 </table>
2709 I put this just above the Messages log in my issue display. Note our use
2710 of the ``totalTimeSpent`` method which will total up the times for the
2711 issue and return a new Interval. That will be automatically displayed in
2712 the template as text like "+ 1y 2:40" (1 year, 2 hours and 40 minutes).
2714 8. If you're using a persistent web server - roundup-server or mod_python for
2715 example - then you'll need to restart that to pick up the code changes.
2716 When that's done, you'll be able to use the new time logging interface.
2718 Using a UN*X passwd file as the user database
2719 ---------------------------------------------
2721 On some systems the primary store of users is the UN*X passwd file. It holds
2722 information on users such as their username, real name, password and primary
2723 user group.
2725 Roundup can use this store as its primary source of user information, but it
2726 needs additional information too - email address(es), roundup Roles, vacation
2727 flags, roundup hyperdb item ids, etc. Also, "retired" users must still exist
2728 in the user database, unlike some passwd files in which the users are removed
2729 when they no longer have access to a system.
2731 To make use of the passwd file, we therefore synchronise between the two user
2732 stores. We also use the passwd file to validate the user logins, as described
2733 in the previous example, `using an external password validation source`_. We
2734 keep the users lists in sync using a fairly simple script that runs once a
2735 day, or several times an hour if more immediate access is needed. In short, it:
2737 1. parses the passwd file, finding usernames, passwords and real names,
2738 2. compares that list to the current roundup user list:
2740 a. entries no longer in the passwd file are *retired*
2741 b. entries with mismatching real names are *updated*
2742 c. entries only exist in the passwd file are *created*
2744 3. send an email to administrators to let them know what's been done.
2746 The retiring and updating are simple operations, requiring only a call to
2747 ``retire()`` or ``set()``. The creation operation requires more information
2748 though - the user's email address and their roundup Roles. We're going to
2749 assume that the user's email address is the same as their login name, so we
2750 just append the domain name to that. The Roles are determined using the
2751 passwd group identifier - mapping their UN*X group to an appropriate set of
2752 Roles.
2754 The script to perform all this, broken up into its main components, is as
2755 follows. Firstly, we import the necessary modules and open the tracker we're
2756 to work on::
2758 import sys, os, smtplib
2759 from roundup import instance, date
2761 # open the tracker
2762 tracker_home = sys.argv[1]
2763 tracker = instance.open(tracker_home)
2765 Next we read in the *passwd* file from the tracker home::
2767 # read in the users
2768 file = os.path.join(tracker_home, 'users.passwd')
2769 users = [x.strip().split(':') for x in open(file).readlines()]
2771 Handle special users (those to ignore in the file, and those who don't appear
2772 in the file)::
2774 # users to not keep ever, pre-load with the users I know aren't
2775 # "real" users
2776 ignore = ['ekmmon', 'bfast', 'csrmail']
2778 # users to keep - pre-load with the roundup-specific users
2779 keep = ['comment_pool', 'network_pool', 'admin', 'dev-team', 'cs_pool',
2780 'anonymous', 'system_pool', 'automated']
2782 Now we map the UN*X group numbers to the Roles that users should have::
2784 roles = {
2785 '501': 'User,Tech', # tech
2786 '502': 'User', # finance
2787 '503': 'User,CSR', # customer service reps
2788 '504': 'User', # sales
2789 '505': 'User', # marketing
2790 }
2792 Now we do all the work. Note that the body of the script (where we have the
2793 tracker database open) is wrapped in a ``try`` / ``finally`` clause, so that
2794 we always close the database cleanly when we're finished. So, we now do all
2795 the work::
2797 # open the database
2798 db = tracker.open('admin')
2799 try:
2800 # store away messages to send to the tracker admins
2801 msg = []
2803 # loop over the users list read in from the passwd file
2804 for user,passw,uid,gid,real,home,shell in users:
2805 if user in ignore:
2806 # this user shouldn't appear in our tracker
2807 continue
2808 keep.append(user)
2809 try:
2810 # see if the user exists in the tracker
2811 uid = db.user.lookup(user)
2813 # yes, they do - now check the real name for correctness
2814 if real != db.user.get(uid, 'realname'):
2815 db.user.set(uid, realname=real)
2816 msg.append('FIX %s - %s'%(user, real))
2817 except KeyError:
2818 # nope, the user doesn't exist
2819 db.user.create(username=user, realname=real,
2820 address='%s@ekit-inc.com'%user, roles=roles[gid])
2821 msg.append('ADD %s - %s (%s)'%(user, real, roles[gid]))
2823 # now check that all the users in the tracker are also in our "keep"
2824 # list - retire those who aren't
2825 for uid in db.user.list():
2826 user = db.user.get(uid, 'username')
2827 if user not in keep:
2828 db.user.retire(uid)
2829 msg.append('RET %s'%user)
2831 # if we did work, then send email to the tracker admins
2832 if msg:
2833 # create the email
2834 msg = '''Subject: %s user database maintenance
2836 %s
2837 '''%(db.config.TRACKER_NAME, '\n'.join(msg))
2839 # send the email
2840 smtp = smtplib.SMTP(db.config.MAILHOST)
2841 addr = db.config.ADMIN_EMAIL
2842 smtp.sendmail(addr, addr, msg)
2844 # now we're done - commit the changes
2845 db.commit()
2846 finally:
2847 # always close the database cleanly
2848 db.close()
2850 And that's it!
2853 Enabling display of either message summaries or the entire messages
2854 -------------------------------------------------------------------
2856 This is pretty simple - all we need to do is copy the code from the example
2857 `displaying only message summaries in the issue display`_ into our template
2858 alongside the summary display, and then introduce a switch that shows either
2859 one or the other. We'll use a new form variable, ``:whole_messages`` to
2860 achieve this::
2862 <table class="messages" tal:condition="context/messages">
2863 <tal:block tal:condition="not:request/form/:whole_messages/value | python:0">
2864 <tr><th colspan=3 class="header">Messages</th>
2865 <th colspan=2 class="header">
2866 <a href="?:whole_messages=yes">show entire messages</a>
2867 </th>
2868 </tr>
2869 <tr tal:repeat="msg context/messages">
2870 <td><a tal:attributes="href string:msg${msg/id}"
2871 tal:content="string:msg${msg/id}"></a></td>
2872 <td tal:content="msg/author">author</td>
2873 <td nowrap tal:content="msg/date/pretty">date</td>
2874 <td tal:content="msg/summary">summary</td>
2875 <td>
2876 <a tal:attributes="href string:?:remove:messages=${msg/id}&:action=edit">remove</a>
2877 </td>
2878 </tr>
2879 </tal:block>
2881 <tal:block tal:condition="request/form/:whole_messages/value | python:0">
2882 <tr><th colspan=2 class="header">Messages</th>
2883 <th class="header"><a href="?:whole_messages=">show only summaries</a></th>
2884 </tr>
2885 <tal:block tal:repeat="msg context/messages">
2886 <tr>
2887 <th tal:content="msg/author">author</th>
2888 <th nowrap tal:content="msg/date/pretty">date</th>
2889 <th style="text-align: right">
2890 (<a tal:attributes="href string:?:remove:messages=${msg/id}&:action=edit">remove</a>)
2891 </th>
2892 </tr>
2893 <tr><td colspan=3 tal:content="msg/content"></td></tr>
2894 </tal:block>
2895 </tal:block>
2896 </table>
2899 Blocking issues that depend on other issues
2900 -------------------------------------------
2902 We needed the ability to mark certain issues as "blockers" - that is,
2903 they can't be resolved until another issue (the blocker) they rely on
2904 is resolved. To achieve this:
2906 1. Create a new property on the issue Class, ``blockers=Multilink("issue")``.
2907 Edit your tracker's dbinit.py file. Where the "issue" class is defined,
2908 something like::
2910 issue = IssueClass(db, "issue",
2911 assignedto=Link("user"), topic=Multilink("keyword"),
2912 priority=Link("priority"), status=Link("status"))
2914 add the blockers entry like so::
2916 issue = IssueClass(db, "issue",
2917 blockers=Multilink("issue"),
2918 assignedto=Link("user"), topic=Multilink("keyword"),
2919 priority=Link("priority"), status=Link("status"))
2921 2. Add the new "blockers" property to the issue.item edit page, using
2922 something like::
2924 <th nowrap>Waiting On</th>
2925 <td>
2926 <span tal:replace="structure python:context.blockers.field(showid=1,
2927 size=20)" />
2928 <span tal:replace="structure python:db.issue.classhelp('id,title')" />
2929 <span tal:condition="context/blockers" tal:repeat="blk context/blockers">
2930 <br>View: <a tal:attributes="href string:issue${blk/id}"
2931 tal:content="blk/id"></a>
2932 </span>
2934 You'll need to fiddle with your item page layout to find an appropriate
2935 place to put it - I'll leave that fun part up to you. Just make sure it
2936 appears in the first table, possibly somewhere near the "superseders"
2937 field.
2939 3. Create a new detector module (attached) which enforces the rules:
2941 - issues may not be resolved if they have blockers
2942 - when a blocker is resolved, it's removed from issues it blocks
2944 The contents of the detector should be something like this::
2946 def blockresolution(db, cl, nodeid, newvalues):
2947 ''' If the issue has blockers, don't allow it to be resolved.
2948 '''
2949 if nodeid is None:
2950 blockers = []
2951 else:
2952 blockers = cl.get(nodeid, 'blockers')
2953 blockers = newvalues.get('blockers', blockers)
2955 # don't do anything if there's no blockers or the status hasn't changed
2956 if not blockers or not newvalues.has_key('status'):
2957 return
2959 # get the resolved state ID
2960 resolved_id = db.status.lookup('resolved')
2962 # format the info
2963 u = db.config.TRACKER_WEB
2964 s = ', '.join(['<a href="%sissue%s">%s</a>'%(u,id,id) for id in blockers])
2965 if len(blockers) == 1:
2966 s = 'issue %s is'%s
2967 else:
2968 s = 'issues %s are'%s
2970 # ok, see if we're trying to resolve
2971 if newvalues['status'] == resolved_id:
2972 raise ValueError, "This issue can't be resolved until %s resolved."%s
2974 def resolveblockers(db, cl, nodeid, newvalues):
2975 ''' When we resolve an issue that's a blocker, remove it from the
2976 blockers list of the issue(s) it blocks.
2977 '''
2978 if not newvalues.has_key('status'):
2979 return
2981 # get the resolved state ID
2982 resolved_id = db.status.lookup('resolved')
2984 # interesting?
2985 if newvalues['status'] != resolved_id:
2986 return
2988 # yes - find all the blocked issues, if any, and remove me from their
2989 # blockers list
2990 issues = cl.find(blockers=nodeid)
2991 for issueid in issues:
2992 blockers = cl.get(issueid, 'blockers')
2993 if nodeid in blockers:
2994 blockers.remove(nodeid)
2995 cl.set(issueid, blockers=blockers)
2998 def init(db):
2999 # might, in an obscure situation, happen in a create
3000 db.issue.audit('create', blockresolution)
3001 db.issue.audit('set', blockresolution)
3003 # can only happen on a set
3004 db.issue.react('set', resolveblockers)
3006 Put the above code in a file called "blockers.py" in your tracker's
3007 "detectors" directory.
3009 4. Finally, and this is an optional step, modify the tracker web page URLs
3010 so they filter out issues with any blockers. You do this by adding an
3011 additional filter on "blockers" for the value "-1". For example, the
3012 existing "Show All" link in the "page" template (in the tracker's
3013 "html" directory) looks like this::
3015 <a href="issue?:sort=-activity&:group=priority&:filter=status&:columns=id,activity,title,creator,assignedto,status&status=-1,1,2,3,4,5,6,7">Show All</a><br>
3017 modify it to add the "blockers" info to the URL (note, both the
3018 ":filter" *and* "blockers" values must be specified)::
3020 <a href="issue?:sort=-activity&:group=priority&:filter=status,blockers@blockers=-1&:columns=id,activity,title,creator,assignedto,status&status=-1,1,2,3,4,5,6,7">Show All</a><br>
3022 That's it. You should now be able to se blockers on your issues. Note that
3023 if you want to know whether an issue has any other issues dependent on it
3024 (ie. it's in their blockers list) you can look at the journal history
3025 at the bottom of the issue page - look for a "link" event to another
3026 issue's "blockers" property.
3029 -------------------
3031 Back to `Table of Contents`_
3033 .. _`Table of Contents`: index.html
3034 .. _`design documentation`: design.html