Dark Developments Where Knowledge Meets Power

12Dec/110

Trac – Arrange fields in Tickets

Posted by Dark#Basics

TRAC - Arrange Fields in Tickets
For one of our customers we had to organise the order of the fields when you create a ticket. This can be done by copying the templates/ticket.html to trac/projectname/templates/ticket.html Next, edit the ticket.html template and insert the following code snippet in the beginning of the template.

Select All Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<!--?python
  # define the order
  field_types = ["type", "priority", "milestone",  "keywords", "cc",  "component"]
 
  # 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)
 
  fields.sort(cmp=sort_nicely)
?-->

If you have custom fields and you want them ordered, put them into the field_types list.

Filed under: Trac No Comments