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: |
| … |
… |
|
| 164 | 164 | return field[0].get('value', '') |
| 165 | 165 | except KeyError: |
| 166 | 166 | pass |
| 167 | | |
| | 167 | |
| 168 | 168 | def populate(self, values): |
| 169 | 169 | """Populate the ticket with 'suitable' values from a dictionary""" |
| 170 | 170 | field_names = [f['name'] for f in self.fields] |
| … |
… |
|
| 179 | 179 | |
| 180 | 180 | def insert(self, when=None, db=None): |
| 181 | 181 | """Add ticket to database. |
| 182 | | |
| | 182 | |
| 183 | 183 | The `db` argument is deprecated in favor of `with_transaction()`. |
| 184 | 184 | """ |
| 185 | 185 | assert not self.exists, 'Cannot insert an existing ticket' |
| … |
… |
|
| 214 | 214 | for field in self.time_fields: |
| 215 | 215 | if field in values: |
| 216 | 216 | values[field] = to_utimestamp(values[field]) |
| 217 | | |
| | 217 | |
| 218 | 218 | # Insert ticket record |
| 219 | 219 | tkt_id = [None] |
| 220 | 220 | @self.env.with_transaction(db) |
| … |
… |
|
| 246 | 246 | Store ticket changes in the database. The ticket must already exist in |
| 247 | 247 | the database. Returns False if there were no changes to save, True |
| 248 | 248 | otherwise. |
| 249 | | |
| | 249 | |
| 250 | 250 | The `db` argument is deprecated in favor of `with_transaction()`. |
| 251 | 251 | """ |
| 252 | 252 | assert self.exists, 'Cannot update a new ticket' |
| … |
… |
|
| 337 | 337 | VALUES (%s, %s, %s, %s, %s, %s) |
| 338 | 338 | """, (self.id, when_ts, author, name, self._old[name], |
| 339 | 339 | self[name])) |
| 340 | | |
| | 340 | |
| 341 | 341 | # always save comment, even if empty |
| 342 | 342 | # (numbering support for timeline) |
| 343 | 343 | cursor.execute(""" |
| … |
… |
|
| 345 | 345 | (ticket,time,author,field,oldvalue,newvalue) |
| 346 | 346 | VALUES (%s,%s,%s,'comment',%s,%s) |
| 347 | 347 | """, (self.id, when_ts, author, comment_num, comment)) |
| 348 | | |
| | 348 | |
| 349 | 349 | cursor.execute("UPDATE ticket SET changetime=%s WHERE id=%s", |
| 350 | 350 | (when_ts, self.id)) |
| 351 | 351 | |
| … |
… |
|
| 384 | 384 | else: |
| 385 | 385 | cursor.execute(""" |
| 386 | 386 | SELECT time,author,field,oldvalue,newvalue, 1 AS permanent |
| 387 | | FROM ticket_change WHERE ticket=%s |
| | 387 | FROM ticket_change WHERE ticket=%s |
| 388 | 388 | UNION |
| 389 | 389 | SELECT time,author,'attachment',null,filename, 0 AS permanent |
| 390 | 390 | FROM attachment WHERE id=%s |
| … |
… |
|
| 401 | 401 | |
| 402 | 402 | def delete(self, db=None): |
| 403 | 403 | """Delete the ticket. |
| 404 | | |
| | 404 | |
| 405 | 405 | The `db` argument is deprecated in favor of `with_transaction()`. |
| 406 | 406 | """ |
| 407 | 407 | @self.env.with_transaction(db) |
| … |
… |
|
| 444 | 444 | if not row: |
| 445 | 445 | return |
| 446 | 446 | ts = row[0] |
| 447 | | |
| | 447 | |
| 448 | 448 | # Find modified fields and their previous value |
| 449 | 449 | cursor.execute(""" |
| 450 | 450 | SELECT field, oldvalue, newvalue FROM ticket_change |
| … |
… |
|
| 479 | 479 | cursor.execute(""" |
| 480 | 480 | UPDATE ticket SET %s=%%s WHERE id=%%s |
| 481 | 481 | """ % field, (oldvalue, self.id)) |
| 482 | | |
| | 482 | |
| 483 | 483 | # Delete the change |
| 484 | 484 | cursor.execute(""" |
| 485 | 485 | DELETE FROM ticket_change WHERE ticket=%s AND time=%s |
| 486 | 486 | """, (self.id, ts)) |
| 487 | | |
| | 487 | |
| 488 | 488 | # Fix the last modification time |
| 489 | 489 | cursor.execute(""" |
| 490 | 490 | UPDATE ticket SET changetime=( |
| … |
… |
|
| 492 | 492 | ORDER BY time DESC LIMIT 1) |
| 493 | 493 | WHERE id=%s |
| 494 | 494 | """, (self.id, self.id)) |
| 495 | | |
| | 495 | |
| 496 | 496 | self._fetch_ticket(self.id) |
| 497 | 497 | |
| 498 | 498 | def modify_comment(self, cdate, author, comment, when=None): |
| … |
… |
|
| 517 | 517 | break |
| 518 | 518 | if comment == (old_comment or ''): |
| 519 | 519 | return |
| 520 | | |
| | 520 | |
| 521 | 521 | # Comment history is stored in fields named "_comment%d" |
| 522 | 522 | # Find the next edit number |
| 523 | 523 | cursor.execute(""" |
| … |
… |
|
| 594 | 594 | '%' + db.like_escape('.' + scnum))) |
| 595 | 595 | for row in cursor: |
| 596 | 596 | return row |
| 597 | | |
| | 597 | |
| 598 | 598 | # Fallback when comment number is not available in oldvalue |
| 599 | 599 | num = 0 |
| 600 | 600 | cursor.execute(""" |
| … |
… |
|
| 619 | 619 | break |
| 620 | 620 | else: |
| 621 | 621 | return |
| 622 | | |
| | 622 | |
| 623 | 623 | # Find author if NULL |
| 624 | 624 | if author is None: |
| 625 | 625 | cursor.execute(""" |
| … |
… |
|
| 631 | 631 | break |
| 632 | 632 | return (ts, author, comment) |
| 633 | 633 | |
| 634 | | |
| 635 | 634 | def simplify_whitespace(name): |
| 636 | 635 | """Strip spaces and remove duplicate spaces within names""" |
| 637 | 636 | if name: |
| … |
… |
|
| 668 | 667 | |
| 669 | 668 | def delete(self, db=None): |
| 670 | 669 | """Delete the enum value. |
| 671 | | |
| | 670 | |
| 672 | 671 | The `db` argument is deprecated in favor of `with_transaction()`. |
| 673 | 672 | """ |
| 674 | 673 | assert self.exists, 'Cannot delete non-existent %s' % self.type |
| … |
… |
|
| 694 | 693 | |
| 695 | 694 | def insert(self, db=None): |
| 696 | 695 | """Add a new enum value. |
| 697 | | |
| | 696 | |
| 698 | 697 | The `db` argument is deprecated in favor of `with_transaction()`. |
| 699 | 698 | """ |
| 700 | 699 | assert not self.exists, 'Cannot insert existing %s' % self.type |
| … |
… |
|
| 721 | 720 | |
| 722 | 721 | def update(self, db=None): |
| 723 | 722 | """Update the enum value. |
| 724 | | |
| | 723 | |
| 725 | 724 | The `db` argument is deprecated in favor of `with_transaction()`. |
| 726 | 725 | """ |
| 727 | 726 | assert self.exists, 'Cannot update non-existent %s' % self.type |
| … |
… |
|
| 793 | 792 | |
| 794 | 793 | |
| 795 | 794 | class Component(object): |
| 796 | | |
| 797 | 795 | def __init__(self, env, name=None, db=None): |
| 798 | 796 | self.env = env |
| 799 | 797 | name = simplify_whitespace(name) |
| … |
… |
|
| 820 | 818 | |
| 821 | 819 | def delete(self, db=None): |
| 822 | 820 | """Delete the component. |
| 823 | | |
| | 821 | |
| 824 | 822 | The `db` argument is deprecated in favor of `with_transaction()`. |
| 825 | 823 | """ |
| 826 | 824 | assert self.exists, 'Cannot delete non-existent component' |
| … |
… |
|
| 835 | 833 | |
| 836 | 834 | def insert(self, db=None): |
| 837 | 835 | """Insert a new component. |
| 838 | | |
| | 836 | |
| 839 | 837 | The `db` argument is deprecated in favor of `with_transaction()`. |
| 840 | 838 | """ |
| 841 | 839 | assert not self.exists, 'Cannot insert existing component' |
| … |
… |
|
| 856 | 854 | |
| 857 | 855 | def update(self, db=None): |
| 858 | 856 | """Update the component. |
| 859 | | |
| | 857 | |
| 860 | 858 | The `db` argument is deprecated in favor of `with_transaction()`. |
| 861 | 859 | """ |
| 862 | 860 | assert self.exists, 'Cannot update non-existent component' |
| … |
… |
|
| 897 | 895 | |
| 898 | 896 | |
| 899 | 897 | class Milestone(object): |
| 900 | | |
| 901 | 898 | def __init__(self, env, name=None, db=None): |
| 902 | 899 | self.env = env |
| 903 | 900 | name = simplify_whitespace(name) |
| … |
… |
|
| 947 | 944 | |
| 948 | 945 | def delete(self, retarget_to=None, author=None, db=None): |
| 949 | 946 | """Delete the milestone. |
| 950 | | |
| | 947 | |
| 951 | 948 | The `db` argument is deprecated in favor of `with_transaction()`. |
| 952 | 949 | """ |
| 953 | 950 | @self.env.with_transaction(db) |
| … |
… |
|
| 974 | 971 | |
| 975 | 972 | def insert(self, db=None): |
| 976 | 973 | """Insert a new milestone. |
| 977 | | |
| | 974 | |
| 978 | 975 | The `db` argument is deprecated in favor of `with_transaction()`. |
| 979 | 976 | """ |
| 980 | 977 | self.name = simplify_whitespace(self.name) |
| … |
… |
|
| 998 | 995 | |
| 999 | 996 | def update(self, db=None): |
| 1000 | 997 | """Update the milestone. |
| 1001 | | |
| | 998 | |
| 1002 | 999 | The `db` argument is deprecated in favor of `with_transaction()`. |
| 1003 | 1000 | """ |
| 1004 | 1001 | self.name = simplify_whitespace(self.name) |
| … |
… |
|
| 1066 | 1063 | |
| 1067 | 1064 | |
| 1068 | 1065 | class Version(object): |
| 1069 | | |
| 1070 | 1066 | def __init__(self, env, name=None, db=None): |
| 1071 | 1067 | self.env = env |
| 1072 | 1068 | name = simplify_whitespace(name) |
| … |
… |
|
| 1093 | 1089 | |
| 1094 | 1090 | def delete(self, db=None): |
| 1095 | 1091 | """Delete the version. |
| 1096 | | |
| | 1092 | |
| 1097 | 1093 | The `db` argument is deprecated in favor of `with_transaction()`. |
| 1098 | 1094 | """ |
| 1099 | 1095 | assert self.exists, 'Cannot delete non-existent version' |
| … |
… |
|
| 1108 | 1104 | |
| 1109 | 1105 | def insert(self, db=None): |
| 1110 | 1106 | """Insert a new version. |
| 1111 | | |
| | 1107 | |
| 1112 | 1108 | The `db` argument is deprecated in favor of `with_transaction()`. |
| 1113 | 1109 | """ |
| 1114 | 1110 | assert not self.exists, 'Cannot insert existing version' |
| … |
… |
|
| 1128 | 1124 | |
| 1129 | 1125 | def update(self, db=None): |
| 1130 | 1126 | """Update the version. |
| 1131 | | |
| | 1127 | |
| 1132 | 1128 | The `db` argument is deprecated in favor of `with_transaction()`. |
| 1133 | 1129 | """ |
| 1134 | 1130 | assert self.exists, 'Cannot update non-existent version' |