diff --git a/trac/ticket/model.py b/trac/ticket/model.py
|
a
|
b
|
|
| 52 | 52 | tkt_id = int(tkt_id) |
| 53 | 53 | self.resource = Resource('ticket', tkt_id, version) |
| 54 | 54 | self.fields = TicketSystem(self.env).get_ticket_fields() |
| 55 | | self.time_fields = [f['name'] for f in self.fields |
| 56 | | if f['type'] == 'time'] |
| | 55 | self.custom_fields = [] |
| | 56 | self.std_fields = [] |
| | 57 | self.time_fields = [] |
| | 58 | for f in self.fields: |
| | 59 | if f.get('custom'): |
| | 60 | self.custom_fields.append(f['name']) |
| | 61 | else: |
| | 62 | self.std_fields.append(f['name']) |
| | 63 | if f['type'] == 'time': |
| | 64 | self.time_fields.append(f['name']) |
| | 65 | |
| 57 | 66 | self.values = {} |
| 58 | 67 | if tkt_id is not None: |
| 59 | 68 | self._fetch_ticket(tkt_id, db) |
| … |
… |
|
| 95 | 104 | db = self._get_db(db) |
| 96 | 105 | |
| 97 | 106 | # Fetch the standard ticket fields |
| 98 | | std_fields = [f['name'] for f in self.fields |
| 99 | | if not f.get('custom')] |
| 100 | 107 | cursor = db.cursor() |
| 101 | 108 | cursor.execute("SELECT %s FROM ticket WHERE id=%%s" |
| 102 | | % ','.join(std_fields), (tkt_id,)) |
| | 109 | % ','.join(self.std_fields), (tkt_id,)) |
| 103 | 110 | row = cursor.fetchone() |
| 104 | 111 | if not row: |
| 105 | 112 | raise ResourceNotFound(_('Ticket %(id)s does not exist.', |
| 106 | 113 | id=tkt_id), _('Invalid ticket number')) |
| 107 | 114 | |
| 108 | 115 | self.id = tkt_id |
| 109 | | for i, field in enumerate(std_fields): |
| | 116 | for i, field in enumerate(self.std_fields): |
| 110 | 117 | value = row[i] |
| 111 | 118 | if field in self.time_fields: |
| 112 | 119 | self.values[field] = from_utimestamp(value) |
| … |
… |
|
| 116 | 123 | self.values[field] = value |
| 117 | 124 | |
| 118 | 125 | # Fetch custom fields if available |
| 119 | | custom_fields = [f['name'] for f in self.fields if f.get('custom')] |
| 120 | 126 | cursor.execute("SELECT name,value FROM ticket_custom WHERE ticket=%s", |
| 121 | 127 | (tkt_id,)) |
| 122 | 128 | for name, value in cursor: |
| 123 | | if name in custom_fields: |
| | 129 | if name in self.custom_fields: |
| 124 | 130 | if value is None: |
| 125 | 131 | self.values[name] = empty |
| 126 | 132 | else: |
| … |
… |
|
| 193 | 199 | # No such component exists |
| 194 | 200 | pass |
| 195 | 201 | |
| | 202 | # new ticket has separate field lists |
| | 203 | custom_fields = [] |
| | 204 | std_fields = [] |
| | 205 | for f in self.fields: |
| | 206 | if f['name'] in self.values: |
| | 207 | if f.get('custom'): |
| | 208 | custom_fields.append(f['name']) |
| | 209 | else: |
| | 210 | std_fields.append(f['name']) |
| | 211 | |
| 196 | 212 | # Perform type conversions |
| 197 | 213 | values = dict(self.values) |
| 198 | 214 | for field in self.time_fields: |
| … |
… |
|
| 200 | 216 | values[field] = to_utimestamp(values[field]) |
| 201 | 217 | |
| 202 | 218 | # Insert ticket record |
| 203 | | std_fields = [] |
| 204 | | custom_fields = [] |
| 205 | | for f in self.fields: |
| 206 | | fname = f['name'] |
| 207 | | if fname in self.values: |
| 208 | | if f.get('custom'): |
| 209 | | custom_fields.append(fname) |
| 210 | | else: |
| 211 | | std_fields.append(fname) |
| 212 | | |
| 213 | 219 | tkt_id = [None] |
| 214 | 220 | @self.env.with_transaction(db) |
| 215 | 221 | def do_insert(db): |
| … |
… |
|
| 306 | 312 | comment_num = str(num + 1) |
| 307 | 313 | |
| 308 | 314 | # store fields |
| 309 | | custom_fields = [f['name'] for f in self.fields if f.get('custom')] |
| 310 | | |
| 311 | 315 | for name in self._old.keys(): |
| 312 | | if name in custom_fields: |
| | 316 | if name in self.custom_fields: |
| 313 | 317 | cursor.execute(""" |
| 314 | 318 | SELECT * FROM ticket_custom |
| 315 | 319 | WHERE ticket=%s and name=%s |
| … |
… |
|
| 441 | 445 | return |
| 442 | 446 | ts = row[0] |
| 443 | 447 | |
| 444 | | custom_fields = set(f['name'] for f in self.fields |
| 445 | | if f.get('custom')) |
| 446 | | |
| 447 | 448 | # Find modified fields and their previous value |
| 448 | 449 | cursor.execute(""" |
| 449 | 450 | SELECT field, oldvalue, newvalue FROM ticket_change |
| … |
… |
|
| 469 | 470 | break |
| 470 | 471 | else: |
| 471 | 472 | # No next change, edit ticket field |
| 472 | | if field in custom_fields: |
| | 473 | if field in self.custom_fields: |
| 473 | 474 | cursor.execute(""" |
| 474 | 475 | UPDATE ticket_custom SET value=%s |
| 475 | 476 | WHERE ticket=%s AND name=%s |