Permalink
Browse files

Merge branch 'master' into topic-status-check

Conflicts:
	tracsubtickets/api.py
  • Loading branch information...
2 parents ae2e9d5 + a0fc153 commit 8a2b509c4232c2e48443fbf8c520b3c02a40f199 @itota committed Oct 28, 2012
Showing with 45 additions and 32 deletions.
  1. +21 −13 tracsubtickets/api.py
  2. +24 −19 tracsubtickets/web_ui.py
View
34 tracsubtickets/api.py
@@ -34,6 +34,7 @@
from trac.core import *
from trac.env import IEnvironmentSetupParticipant
from trac.db import DatabaseManager
+from trac.resource import ResourceNotFound
from trac.ticket.model import Ticket
from trac.ticket.api import ITicketChangeListener, ITicketManipulator
from trac.ticket.notification import TicketNotifyEmail
@@ -191,19 +192,20 @@ def validate_ticket(self, req, ticket):
cursor = db.cursor()
try:
- ids = []
+ invalid_ids = set()
_ids = set(NUMBERS_RE.findall(ticket['parents'] or ''))
myid = str(ticket.id)
for id in _ids:
if id == myid:
+ invalid_ids.add(id)
yield 'parents', _('A ticket cannot be a parent to itself')
else:
# check if the id exists
cursor.execute("SELECT id FROM ticket WHERE id=%s", (id, ))
row = cursor.fetchone()
if row is None:
+ invalid_ids.add(id)
yield 'parents', _('Ticket #%s does not exist') % id
- ids.append(id)
# circularity check function
def _check_parents(id, all_parents):
@@ -212,26 +214,32 @@ def _check_parents(id, all_parents):
cursor.execute("SELECT parent FROM subtickets WHERE child=%s", (id, ))
for x in [int(x[0]) for x in cursor]:
if x in all_parents:
+ invalid_ids.add(x)
error = ' > '.join(['#%s' % n for n in all_parents + [x]])
errors.append(('parents', _('Circularity error: %s') % error))
else:
errors += _check_parents(x, all_parents)
return errors
- for x in ids:
+ for x in [i for i in _ids if i not in invalid_ids]:
# check parent ticket state
- parent = Ticket(self.env, x)
- if parent and parent['status'] in self.restricted_status and ticket['status'] not in self.restricted_status:
- yield 'parents', _('Parent ticket #%s is closed') % x
- else:
- # check circularity
- all_parents = ticket.id and [ticket.id] or []
- for error in _check_parents(int(x), all_parents):
- yield error
+ try:
+ parent = Ticket(self.env, x)
+ if parent and parent['status'] in self.restricted_status and ticket['status'] not in self.restricted_status:
+ yield 'parents', _('Parent ticket #%s is closed') % x
+ else:
+ # check circularity
+ all_parents = ticket.id and [ticket.id] or []
+ for error in _check_parents(int(x), all_parents):
+ yield error
+ except ResourceNotFound, e:
+ invalid_ids.add(x)
- ticket['parents'] = ', '.join(sorted(ids, key=lambda x: int(x)))
+ valid_ids = _ids.difference(invalid_ids)
+ ticket['parents'] = valid_ids and ', '.join(sorted(valid_ids, key=lambda x: int(x))) or ''
except Exception, e:
- self.log.error(e)
+ import traceback
+ self.log.error(traceback.format_exc())
yield 'parents', _('Not a valid list of ticket IDs')
View
43 tracsubtickets/web_ui.py
@@ -32,6 +32,7 @@
from trac.web.chrome import ITemplateProvider, add_stylesheet
from trac.ticket.api import ITicketManipulator
from trac.ticket.model import Ticket
+from trac.resource import ResourceNotFound
from genshi.builder import tag
from genshi.filters import Transformer
@@ -62,31 +63,35 @@ def pre_process_request(self, req, handler):
def post_process_request(self, req, template, data, content_type):
path = req.path_info
if path.startswith('/ticket/') or path.startswith('/newticket'):
- # get parents data
- ticket = data['ticket']
- parents = ticket['parents'] or ''
- ids = set(NUMBERS_RE.findall(parents))
-
- if len(parents) > 0:
- self._append_parent_links(req, data, ids)
-
- children = self.get_children(ticket.id)
- if children:
- data['subtickets'] = children
+ # get parent ticket's data
+ if data and 'ticket' in data:
+ ticket = data['ticket']
+ parents = ticket['parents'] or ''
+ ids = set(NUMBERS_RE.findall(parents))
+
+ if len(parents) > 0:
+ self._append_parent_links(req, data, ids)
+
+ children = self.get_children(ticket.id)
+ if children:
+ data['subtickets'] = children
return template, data, content_type
def _append_parent_links(self, req, data, ids):
links = []
for id in sorted(ids, key=lambda x: int(x)):
- ticket = Ticket(self.env, id)
- elem = tag.a('#%s' % id,
- href=req.href.ticket(id),
- class_='%s ticket' % ticket['status'],
- title=ticket['summary'])
- if len(links) > 0:
- links.append(', ')
- links.append(elem)
+ try:
+ ticket = Ticket(self.env, id)
+ elem = tag.a('#%s' % id,
+ href=req.href.ticket(id),
+ class_='%s ticket' % ticket['status'],
+ title=ticket['summary'])
+ if len(links) > 0:
+ links.append(', ')
+ links.append(elem)
+ except ResourceNotFound, e:
+ pass
for field in data.get('fields', ''):
if field.get('name') == 'parents':
field['rendered'] = tag.span(*links)

0 comments on commit 8a2b509

Please sign in to comment.