Reorder all fields in Trac
We decided to add a business justification field to our Trac instance today, but needed to put it directly below the description field so that it was in a more logical position for the users. It is not possible to intermingle custom ticket fields with standard ones (from within Trac), so editing the ticket template file will be required.
Note: This has been developed and tested for Trac-1.0.1dev_r11400, and may not work on other versions without modifications
Another Note: This process is overkill in most scenarios, and is really only useful if you also need to change the ordering of default ticket fields. If you are just trying to order custom fields, please take a look at the order
property in Trac’s documentation
- Copy
ticket.html
to your local Trac environment’s templates directory (/var/local/trac/templates
in my case)# Ubuntu sudo cp /usr/local/lib/python2.7/dist-packages/Trac-1.0.1dev_r11400-py2.7.egg/trac/ticket/templates/ticket.html /var/local/trac/templates/ # RedHat/CentOS sudo cp /usr/local/lib/python2.7/site-packages/Trac-1.0.1dev_r11400-py2.7.egg/trac/ticket/templates/ticket.html /var/local/trac/templates/
- Add the below code to the top of the copied template file (/var/local/trac/templates/ticket.html). Note –
summary
,reporter
, anddescription
are hard coded into Trac and cannot be modified using this method. You can manually alter them further down in this template if necessary (not covered here).<?python # Define the field order. Note that `summary`, `reporter`, and `description` are hard coded into Trac ## Add custom fields anywhere in the below list, excluded elements will be added to the end field_types = [ 'type', 'priority', 'component', 'cc', 'keywords', ] # Sorting function def sort_nicely(field1, field2): try: idx1 = field_types.index(field1['name']) except ValueError: idx1 = 1000 # no match, push to the end try: idx2 = field_types.index(field2['name']) except ValueError: idx2 = 1000 # no match, push to the end return cmp(idx1, idx2) # Sort the fields fields.sort(cmp=sort_nicely) # Re-generate fields_map for use within the ticket template field_types = ['summary', 'reporter', 'description',] + field_types #< Inject the hard coded fields fields_map = {} for i in xrange(0, len(fields)): fields_map[fields[i]['name']] = i ?>
- Restart tracd (or restart the web server if WSGI, uWSGI, etc.)
Wondering, what version of Trac was this patch developed using?
This patch was developed for Trac-1.0.1dev_r11400. I went ahead and updated the post too. Thanks for reading my blog!
http://trac.edgewall.org/wiki/TracTicketsCustomFields has information about the .order from [ticket-custom] section of trac.ini. IMHO this should be the way to go for most user requirements, but I confess, that it is somewhat hidden in the current official wiki documentation.
Good call out; you are very right that the best way to order fields is by using the `.order` property while defining custom fields. This didn’t work in my case because I needed the ability to mix custom fields in with the standardized ones. I’ve added a note with the link into this article in order to point users in the correct direction. Thanks for the comment, and for reading my blog!