| | 35 | |
| | 36 | field_types = [ 'milestone', 'priority', 'type', 'severity', 'version', 'component', 'keywords', 'focuses', ] |
| | 37 | |
| | 38 | # Sorting function |
| | 39 | def sort_nicely(field1, field2): |
| | 40 | try: |
| | 41 | idx1 = field_types.index(field1['name']) |
| | 42 | except ValueError: |
| | 43 | idx1 = 1000 # no match, push to the end |
| | 44 | |
| | 45 | try: |
| | 46 | idx2 = field_types.index(field2['name']) |
| | 47 | except ValueError: |
| | 48 | idx2 = 1000 # no match, push to the end |
| | 49 | |
| | 50 | return cmp(idx1, idx2) |
| | 51 | |
| | 52 | if ticket and 'fields' in locals(): |
| | 53 | # Sort the fields |
| | 54 | fields.sort(cmp=sort_nicely) |
| | 55 | |
| | 56 | # Re-generate fields_map for use within the ticket template |
| | 57 | fields_map = {} |
| | 58 | for i in xrange(0, len(fields)): |
| | 59 | fields_map[ fields[i]['name'] ] = i |