Modify ↓
Opened 12 years ago
Last modified 12 years ago
#10804 new enhancement
Expand SortMilestoneVersion to cover Custom Query milestone field
Reported by: | Owned by: | Franz | |
---|---|---|---|
Priority: | normal | Component: | TicketNavPlugin |
Severity: | normal | Keywords: | sort milestone |
Cc: | Trac Release: | 1.2 |
Description
Expand the plugin to cover the custom query milestone field as well. Here are the changes to the SortMilestoneVersion class I made to get this to work:
class SortMilestoneVersion(Component): """Sorts drop-down lists of version and milestone regardless of the case and make milestone a must field, when a default milestone is set. Default behavior of Trac for sorting milestones is: inbox, v1, v2, Inbox, V1, V2 This plugin sorts it as following: inbox, Inbox, v1, V1, v2, V2 """ implements (ITemplateStreamFilter) #ITemplateStreamFilter def filter_stream(self, req, method, filename, stream, data): if filename and (filename == 'ticket.html' or filename == 'newticket' or filename == 'query.html'): # print "filename '%s' matches" % filename if not data: return stream try: fields = data['fields'] if not fields: return stream version = self.get_field_list(fields, 'version') version['options'].sort(key=unicode.lower) milestones = self.get_field_list(fields, 'milestone') if self.config.get('ticket', 'default_milestone'): milestones['optional'] = False for opt in milestones['optgroups']: opt['options'].sort(key=unicode.lower) except Exception, e: self.log.error('error has occured by sorting: %s' % e) return stream def get_field_list(self, fields, fieldname): if not fields or not fieldname: return None for fld in fields: if isinstance(fld, dict): if fld['name'] == fieldname: return fld elif isinstance(fld, str): if fields[fld]['name'] == fieldname: return fields[fld] else: pass return None # return None if fieldname not found
Attachments (0)
Note: See
TracTickets for help on using
tickets.
Update: minor modification to support 0.12 and 1.0