diff --git a/trac/ticket/model.py b/trac/ticket/model.py
|
a
|
b
|
|
| 45 | 45 | # 0.11 compatibility |
| 46 | 46 | time_created = property(lambda self: self.values.get('time')) |
| 47 | 47 | time_changed = property(lambda self: self.values.get('changetime')) |
| 48 | | |
| | 48 | |
| 49 | 49 | def __init__(self, env, tkt_id=None, db=None, version=None): |
| 50 | 50 | self.env = env |
| 51 | 51 | if tkt_id is not None: |
| … |
… |
|
| 159 | 159 | return field[0].get('value', '') |
| 160 | 160 | except KeyError: |
| 161 | 161 | pass |
| 162 | | |
| | 162 | |
| 163 | 163 | def populate(self, values): |
| 164 | 164 | """Populate the ticket with 'suitable' values from a dictionary""" |
| 165 | 165 | field_names = [f['name'] for f in self.fields] |
| … |
… |
|
| 174 | 174 | |
| 175 | 175 | def insert(self, when=None, db=None): |
| 176 | 176 | """Add ticket to database. |
| 177 | | |
| | 177 | |
| 178 | 178 | The `db` argument is deprecated in favor of `with_transaction()`. |
| 179 | 179 | """ |
| 180 | 180 | assert not self.exists, 'Cannot insert an existing ticket' |
| … |
… |
|
| 199 | 199 | for field in self.time_fields: |
| 200 | 200 | if field in values: |
| 201 | 201 | values[field] = to_utimestamp(values[field]) |
| 202 | | |
| | 202 | |
| 203 | 203 | # Insert ticket record |
| 204 | 204 | tkt_id = [None] |
| 205 | 205 | @self.env.with_transaction(db) |
| … |
… |
|
| 231 | 231 | Store ticket changes in the database. The ticket must already exist in |
| 232 | 232 | the database. Returns False if there were no changes to save, True |
| 233 | 233 | otherwise. |
| 234 | | |
| | 234 | |
| 235 | 235 | The `db` argument is deprecated in favor of `with_transaction()`. |
| 236 | 236 | """ |
| 237 | 237 | assert self.exists, 'Cannot update a new ticket' |
| … |
… |
|
| 322 | 322 | VALUES (%s, %s, %s, %s, %s, %s) |
| 323 | 323 | """, (self.id, when_ts, author, name, self._old[name], |
| 324 | 324 | self[name])) |
| 325 | | |
| | 325 | |
| 326 | 326 | # always save comment, even if empty |
| 327 | 327 | # (numbering support for timeline) |
| 328 | 328 | cursor.execute(""" |
| … |
… |
|
| 330 | 330 | (ticket,time,author,field,oldvalue,newvalue) |
| 331 | 331 | VALUES (%s,%s,%s,'comment',%s,%s) |
| 332 | 332 | """, (self.id, when_ts, author, comment_num, comment)) |
| 333 | | |
| | 333 | |
| 334 | 334 | cursor.execute("UPDATE ticket SET changetime=%s WHERE id=%s", |
| 335 | 335 | (when_ts, self.id)) |
| 336 | 336 | |
| … |
… |
|
| 369 | 369 | else: |
| 370 | 370 | cursor.execute(""" |
| 371 | 371 | SELECT time,author,field,oldvalue,newvalue, 1 AS permanent |
| 372 | | FROM ticket_change WHERE ticket=%s |
| | 372 | FROM ticket_change WHERE ticket=%s |
| 373 | 373 | UNION |
| 374 | 374 | SELECT time,author,'attachment',null,filename, 0 AS permanent |
| 375 | 375 | FROM attachment WHERE id=%s |
| … |
… |
|
| 386 | 386 | |
| 387 | 387 | def delete(self, db=None): |
| 388 | 388 | """Delete the ticket. |
| 389 | | |
| | 389 | |
| 390 | 390 | The `db` argument is deprecated in favor of `with_transaction()`. |
| 391 | 391 | """ |
| 392 | 392 | @self.env.with_transaction(db) |
| … |
… |
|
| 429 | 429 | if not row: |
| 430 | 430 | return |
| 431 | 431 | ts = row[0] |
| 432 | | |
| | 432 | |
| 433 | 433 | # Find modified fields and their previous value |
| 434 | 434 | cursor.execute(""" |
| 435 | 435 | SELECT field, oldvalue, newvalue FROM ticket_change |
| … |
… |
|
| 464 | 464 | cursor.execute(""" |
| 465 | 465 | UPDATE ticket SET %s=%%s WHERE id=%%s |
| 466 | 466 | """ % field, (oldvalue, self.id)) |
| 467 | | |
| | 467 | |
| 468 | 468 | # Delete the change |
| 469 | 469 | cursor.execute(""" |
| 470 | 470 | DELETE FROM ticket_change WHERE ticket=%s AND time=%s |
| 471 | 471 | """, (self.id, ts)) |
| 472 | | |
| | 472 | |
| 473 | 473 | # Fix the last modification time |
| 474 | 474 | cursor.execute(""" |
| 475 | 475 | UPDATE ticket SET changetime=( |
| … |
… |
|
| 477 | 477 | ORDER BY time DESC LIMIT 1) |
| 478 | 478 | WHERE id=%s |
| 479 | 479 | """, (self.id, self.id)) |
| 480 | | |
| | 480 | |
| 481 | 481 | self._fetch_ticket(self.id) |
| 482 | 482 | |
| 483 | 483 | def modify_comment(self, cdate, author, comment, when=None): |
| … |
… |
|
| 502 | 502 | break |
| 503 | 503 | if comment == (old_comment or ''): |
| 504 | 504 | return |
| 505 | | |
| | 505 | |
| 506 | 506 | # Comment history is stored in fields named "_comment%d" |
| 507 | 507 | # Find the next edit number |
| 508 | 508 | cursor.execute(""" |
| … |
… |
|
| 579 | 579 | '%' + db.like_escape('.' + scnum))) |
| 580 | 580 | for row in cursor: |
| 581 | 581 | return row |
| 582 | | |
| | 582 | |
| 583 | 583 | # Fallback when comment number is not available in oldvalue |
| 584 | 584 | num = 0 |
| 585 | 585 | cursor.execute(""" |
| … |
… |
|
| 604 | 604 | break |
| 605 | 605 | else: |
| 606 | 606 | return |
| 607 | | |
| | 607 | |
| 608 | 608 | # Find author if NULL |
| 609 | 609 | if author is None: |
| 610 | 610 | cursor.execute(""" |
| … |
… |
|
| 616 | 616 | break |
| 617 | 617 | return (ts, author, comment) |
| 618 | 618 | |
| 619 | | |
| 620 | 619 | def simplify_whitespace(name): |
| 621 | 620 | """Strip spaces and remove duplicate spaces within names""" |
| 622 | 621 | if name: |
| … |
… |
|
| 653 | 652 | |
| 654 | 653 | def delete(self, db=None): |
| 655 | 654 | """Delete the enum value. |
| 656 | | |
| | 655 | |
| 657 | 656 | The `db` argument is deprecated in favor of `with_transaction()`. |
| 658 | 657 | """ |
| 659 | 658 | assert self.exists, 'Cannot delete non-existent %s' % self.type |
| … |
… |
|
| 679 | 678 | |
| 680 | 679 | def insert(self, db=None): |
| 681 | 680 | """Add a new enum value. |
| 682 | | |
| | 681 | |
| 683 | 682 | The `db` argument is deprecated in favor of `with_transaction()`. |
| 684 | 683 | """ |
| 685 | 684 | assert not self.exists, 'Cannot insert existing %s' % self.type |
| … |
… |
|
| 706 | 705 | |
| 707 | 706 | def update(self, db=None): |
| 708 | 707 | """Update the enum value. |
| 709 | | |
| | 708 | |
| 710 | 709 | The `db` argument is deprecated in favor of `with_transaction()`. |
| 711 | 710 | """ |
| 712 | 711 | assert self.exists, 'Cannot update non-existent %s' % self.type |
| … |
… |
|
| 778 | 777 | |
| 779 | 778 | |
| 780 | 779 | class Component(object): |
| 781 | | |
| 782 | 780 | def __init__(self, env, name=None, db=None): |
| 783 | 781 | self.env = env |
| 784 | 782 | name = simplify_whitespace(name) |
| … |
… |
|
| 805 | 803 | |
| 806 | 804 | def delete(self, db=None): |
| 807 | 805 | """Delete the component. |
| 808 | | |
| | 806 | |
| 809 | 807 | The `db` argument is deprecated in favor of `with_transaction()`. |
| 810 | 808 | """ |
| 811 | 809 | assert self.exists, 'Cannot delete non-existent component' |
| … |
… |
|
| 820 | 818 | |
| 821 | 819 | def insert(self, db=None): |
| 822 | 820 | """Insert a new component. |
| 823 | | |
| | 821 | |
| 824 | 822 | The `db` argument is deprecated in favor of `with_transaction()`. |
| 825 | 823 | """ |
| 826 | 824 | assert not self.exists, 'Cannot insert existing component' |
| … |
… |
|
| 841 | 839 | |
| 842 | 840 | def update(self, db=None): |
| 843 | 841 | """Update the component. |
| 844 | | |
| | 842 | |
| 845 | 843 | The `db` argument is deprecated in favor of `with_transaction()`. |
| 846 | 844 | """ |
| 847 | 845 | assert self.exists, 'Cannot update non-existent component' |
| … |
… |
|
| 882 | 880 | |
| 883 | 881 | |
| 884 | 882 | class Milestone(object): |
| 885 | | |
| 886 | 883 | def __init__(self, env, name=None, db=None): |
| 887 | 884 | self.env = env |
| 888 | 885 | name = simplify_whitespace(name) |
| … |
… |
|
| 932 | 929 | |
| 933 | 930 | def delete(self, retarget_to=None, author=None, db=None): |
| 934 | 931 | """Delete the milestone. |
| 935 | | |
| | 932 | |
| 936 | 933 | The `db` argument is deprecated in favor of `with_transaction()`. |
| 937 | 934 | """ |
| 938 | 935 | @self.env.with_transaction(db) |
| … |
… |
|
| 959 | 956 | |
| 960 | 957 | def insert(self, db=None): |
| 961 | 958 | """Insert a new milestone. |
| 962 | | |
| | 959 | |
| 963 | 960 | The `db` argument is deprecated in favor of `with_transaction()`. |
| 964 | 961 | """ |
| 965 | 962 | self.name = simplify_whitespace(self.name) |
| … |
… |
|
| 983 | 980 | |
| 984 | 981 | def update(self, db=None): |
| 985 | 982 | """Update the milestone. |
| 986 | | |
| | 983 | |
| 987 | 984 | The `db` argument is deprecated in favor of `with_transaction()`. |
| 988 | 985 | """ |
| 989 | 986 | self.name = simplify_whitespace(self.name) |
| … |
… |
|
| 1051 | 1048 | |
| 1052 | 1049 | |
| 1053 | 1050 | class Version(object): |
| 1054 | | |
| 1055 | 1051 | def __init__(self, env, name=None, db=None): |
| 1056 | 1052 | self.env = env |
| 1057 | 1053 | name = simplify_whitespace(name) |
| … |
… |
|
| 1078 | 1074 | |
| 1079 | 1075 | def delete(self, db=None): |
| 1080 | 1076 | """Delete the version. |
| 1081 | | |
| | 1077 | |
| 1082 | 1078 | The `db` argument is deprecated in favor of `with_transaction()`. |
| 1083 | 1079 | """ |
| 1084 | 1080 | assert self.exists, 'Cannot delete non-existent version' |
| … |
… |
|
| 1093 | 1089 | |
| 1094 | 1090 | def insert(self, db=None): |
| 1095 | 1091 | """Insert a new version. |
| 1096 | | |
| | 1092 | |
| 1097 | 1093 | The `db` argument is deprecated in favor of `with_transaction()`. |
| 1098 | 1094 | """ |
| 1099 | 1095 | assert not self.exists, 'Cannot insert existing version' |
| … |
… |
|
| 1113 | 1109 | |
| 1114 | 1110 | def update(self, db=None): |
| 1115 | 1111 | """Update the version. |
| 1116 | | |
| | 1112 | |
| 1117 | 1113 | The `db` argument is deprecated in favor of `with_transaction()`. |
| 1118 | 1114 | """ |
| 1119 | 1115 | assert self.exists, 'Cannot update non-existent version' |