- Copy templates/ticket.html into trac/myproject/templates/ticket.html
- Insert the following code snippet to the beginning of the template:
<?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)
?>
That's it, if you have any custom fields and you want them ordered, put them into the field_types list.
Hi, I copied this code into the templates/ticket.html and where I must call the sorting function when I want to order the fields for create new ticket?
ReplyDeleteThanks
K
The above code already calls that function for you in the last line.
ReplyDeleteThe "fields" list comes from the templating engine and then it's sorted according to the order in the "field_types" list.
thanks, I copied, inserted code to the but any changes of the order my fields.
ReplyDeleteWell, either you didn't define "field_types" properly, or the code is not in the right ticket.html, or the old template is compiled and cached somewhere.
ReplyDeleteoh.now it's all right.
ReplyDeleteThank you very much
Thank you very much. Your codes are wonderful.
ReplyDeletethanks for the good work and to make it available to all.
ReplyDeleteI have found out that fields' name have to be all lower case for this to work properly (I have custom fields).