diff --git a/tracsubtickets/api.py b/tracsubtickets/api.py index 35fbed7..7818b1f 100644 --- a/tracsubtickets/api.py +++ b/tracsubtickets/api.py @@ -47,7 +47,7 @@ # i18n support for plugins, available since Trac r7705 # use _, tag_ and N_ as usual, e.g. _("this is a message text") -_, tag_, N_, add_domain = domain_functions('tracsubtickets', +_, tag_, N_, add_domain = domain_functions('tracsubtickets', '_', 'tag_', 'N_', 'add_domain') @@ -71,8 +71,7 @@ def environment_created(self): def environment_needs_upgrade(self, db): cursor = db.cursor() - cursor.execute("SELECT value FROM system WHERE name=%s", - (db_default.name, )) + cursor.execute("SELECT value FROM system WHERE name=%s", (db_default.name, )) value = cursor.fetchone() try: self.found_db_version = int(value[0]) @@ -95,17 +94,15 @@ def upgrade_environment(self, db): old_data = {} # {table.name: (cols, rows)} cursor = db.cursor() if not self.found_db_version: - cursor.execute("INSERT INTO system (name, value) VALUES (%s, %s)", - (db_default.name, db_default.version)) + cursor.execute("INSERT INTO system (name, value) VALUES (%s, %s)", (db_default.name, db_default.version)) else: - cursor.execute("UPDATE system SET value=%s WHERE name=%s", - (db_default.version, db_default.name)) + cursor.execute("UPDATE system SET value=%s WHERE name=%s", (db_default.version, db_default.name)) for table in db_default.tables: cursor.execute("SELECT * FROM %s", (table.name, )) cols = [x[0] for x in cursor.description], rows = cursor.fetchall() old_data[table.name] = (cols, rows) - cursor.execute("DROP TABLE %s", (table.name)) + cursor.execute("DROP TABLE %s", (table.name, )) # insert the default table for table in db_default.tables: @@ -132,13 +129,15 @@ def ticket_created(self, ticket): self.ticket_changed(ticket, '', ticket['reporter'], {'parents': ''}) def ticket_changed(self, ticket, comment, author, old_values): + self.log.debug("Ticket changed. Ticket id: %s" % ticket.id) if 'parents' not in old_values: return old_parents = old_values.get('parents', '') or '' old_parents = set(NUMBERS_RE.findall(old_parents)) new_parents = set(NUMBERS_RE.findall(ticket['parents'] or '')) - + self.log.debug("Old parents: %s" % old_parents) + self.log.debug("New parents: %s" % new_parents) if new_parents == old_parents: return @@ -147,19 +146,18 @@ def ticket_changed(self, ticket, comment, author, old_values): # remove old parents for parent in old_parents - new_parents: - cursor.execute("DELETE FROM subtickets WHERE parent=%s AND child=%s", - (parent, ticket.id)) + cursor.execute("DELETE FROM subtickets WHERE parent = %s AND child = %s", [str(parent), str(ticket.id)] ) + # add new parents for parent in new_parents - old_parents: - cursor.execute("INSERT INTO subtickets VALUES(%s, %s)", - (parent, ticket.id)) + cursor.execute("INSERT INTO subtickets VALUES(%s, %s)", (parent, ticket.id)) db.commit() def ticket_deleted(self, ticket): db = self.env.get_db_cnx() cursor = db.cursor() # TODO: check if there's any child ticket - cursor.execute("DELETE FROM subtickets WHERE child=%s", (ticket.id, )) + cursor.execute("DELETE FROM subtickets WHERE child=%s", [str(ticket.id)]) db.commit() # ITicketManipulator methods @@ -189,7 +187,7 @@ def validate_ticket(self, req, ticket): def _check_parents(id, all_parents): all_parents = all_parents + [id] errors = [] - cursor.execute("SELECT parent FROM subtickets WHERE child=%s", (id, )) + cursor.execute("SELECT parent FROM subtickets WHERE child=%s", [str(id)]) for x in [int(x[0]) for x in cursor]: if x in all_parents: error = ' > '.join(['#%s' % n for n in all_parents + [x]]) diff --git a/tracsubtickets/web_ui.py b/tracsubtickets/web_ui.py index 3b33175..968398c 100644 --- a/tracsubtickets/web_ui.py +++ b/tracsubtickets/web_ui.py @@ -37,9 +37,7 @@ from api import NUMBERS_RE, _ - class SubTicketsModule(Component): - implements(ITemplateProvider, IRequestFilter, ITicketManipulator, @@ -94,12 +92,13 @@ def prepare_ticket(self, req, ticket, fields, actions): pass def get_children(self, parent_id, db=None): + self.log.debug("Get children for parent: %s" % parent_id) children = {} if not db: db = self.env.get_db_cnx() + cursor = db.cursor() - cursor.execute("SELECT parent, child FROM subtickets WHERE parent=%s", - (parent_id, )) + cursor.execute("SELECT parent, child FROM subtickets WHERE parent=%s", [str(parent_id)] ) for parent, child in cursor: children[child] = None @@ -108,15 +107,13 @@ def get_children(self, parent_id, db=None): children[id] = self.get_children(id, db) return children - + def validate_ticket(self, req, ticket): action = req.args.get('action') if action == 'resolve': db = self.env.get_db_cnx() cursor = db.cursor() - - cursor.execute("SELECT parent, child FROM subtickets WHERE parent=%s", - (ticket.id, )) + cursor.execute("SELECT parent, child FROM subtickets WHERE parent=%s", [str(ticket.id)] ) for parent, child in cursor: if Ticket(self.env, child)['status'] != 'closed':