You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@bloodhound.apache.org by ma...@apache.org on 2013/05/14 11:41:58 UTC
svn commit: r1482273 - in
/bloodhound/trunk/bloodhound_relations/bhrelations: templates/manage.html
web_ui.py
Author: matevz
Date: Tue May 14 09:41:57 2013
New Revision: 1482273
URL: http://svn.apache.org/r1482273
Log:
Ref #523 - improved error handling + cross-product relations (<prefix>:ticket:<id> syntax for now)
Modified:
bloodhound/trunk/bloodhound_relations/bhrelations/templates/manage.html
bloodhound/trunk/bloodhound_relations/bhrelations/web_ui.py
Modified: bloodhound/trunk/bloodhound_relations/bhrelations/templates/manage.html
URL: http://svn.apache.org/viewvc/bloodhound/trunk/bloodhound_relations/bhrelations/templates/manage.html?rev=1482273&r1=1482272&r2=1482273&view=diff
==============================================================================
--- bloodhound/trunk/bloodhound_relations/bhrelations/templates/manage.html (original)
+++ bloodhound/trunk/bloodhound_relations/bhrelations/templates/manage.html Tue May 14 09:41:57 2013
@@ -88,7 +88,7 @@
<py:for each="relgroup,items in relations.iteritems()">
<tr py:for="item in items">
<td class="sel"><input type="checkbox" name="sel" value="${item.relation_id}" /></td>
- <td class="type">${item['label']}</td>
+ <td class="type">$relgroup</td>
<td class="ticket">
<a href="${item['desthref']}">#${item['destination'].id}</a>
</td>
Modified: bloodhound/trunk/bloodhound_relations/bhrelations/web_ui.py
URL: http://svn.apache.org/viewvc/bloodhound/trunk/bloodhound_relations/bhrelations/web_ui.py?rev=1482273&r1=1482272&r2=1482273&view=diff
==============================================================================
--- bloodhound/trunk/bloodhound_relations/bhrelations/web_ui.py (original)
+++ bloodhound/trunk/bloodhound_relations/bhrelations/web_ui.py Tue May 14 09:41:57 2013
@@ -1,106 +1,126 @@
-#!/usr/bin/env python
-# -*- coding: UTF-8 -*-
-
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-
-
-r"""Ticket relations for Apache(TM) Bloodhound
-
-Ticket relations user interface.
-"""
-
-import re
-import pkg_resources
-
-from trac.core import Component, implements, TracError
-from trac.resource import get_resource_url
-from trac.ticket.model import Ticket
-from trac.web import IRequestHandler
-from trac.web.chrome import ITemplateProvider
-
-from bhrelations.api import RelationsSystem
-
-
-class RelationManagementModule(Component):
- implements(IRequestHandler, ITemplateProvider)
-
- # IRequestHandler methods
- def match_request(self, req):
- match = re.match(r'/ticket/([0-9]+)/relations/*$', req.path_info)
- if not match:
- return False
-
- req.args['id'] = match.group(1)
- return True
-
- def process_request(self, req):
- tid = req.args.get('id')
- if not tid:
- raise TracError('No ticket id provided.')
-
- req.perm.require('TICKET_VIEW')
- ticket = Ticket(self.env, tid)
- relsys = RelationsSystem(self.env)
-
- if req.method == 'POST':
- if req.args.has_key('remove'):
- rellist = req.args.get('sel')
- if rellist:
- if isinstance(rellist, basestring):
- rellist = [rellist, ]
- for rel in rellist:
- relsys.delete(rel)
- elif req.args.has_key('add'):
- dest_tid = req.args.get('dest_tid')
- reltype = req.args.get('reltype')
- comment = req.args.get('comment')
- if dest_tid and reltype:
- dest_ticket = Ticket(self.env, dest_tid)
- relsys.add(ticket, dest_ticket, reltype, comment,
- req.authname)
- else:
- raise TracError(_('Invalid operation.'))
-
- data = {
- 'ticket': ticket,
- 'reltypes': relsys.get_relation_types(),
- 'relations': self.get_ticket_relations(ticket),
- }
- return 'manage.html', data, None
-
- # ITemplateProvider methods
- def get_htdocs_dirs(self):
- resource_filename = pkg_resources.resource_filename
- return [('relations', resource_filename('bhrelations', 'htdocs')), ]
-
- def get_templates_dirs(self):
- resource_filename = pkg_resources.resource_filename
- return [resource_filename('bhrelations', 'templates'), ]
-
- # utility functions
- def get_ticket_relations(self, ticket):
- grouped_relations = {}
- relsys = RelationsSystem(self.env)
- reltypes = relsys.get_relation_types()
- for r in relsys.get_relations(ticket):
- r['desthref'] = get_resource_url(self.env, r['destination'],
- self.env.href)
- r['label'] = relsys.render_relation_type(r['type'])
- grouped_relations.setdefault(reltypes[r['type']], []).append(r)
- return grouped_relations
-
+#!/usr/bin/env python
+# -*- coding: UTF-8 -*-
+
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+
+r"""Ticket relations for Apache(TM) Bloodhound
+
+Ticket relations user interface.
+"""
+
+import re
+import pkg_resources
+
+from trac.core import Component, implements, TracError
+from trac.resource import get_resource_url
+from trac.ticket.model import Ticket
+from trac.util.translation import _
+from trac.web import IRequestHandler
+from trac.web.chrome import ITemplateProvider
+
+from bhrelations.api import RelationsSystem, ResourceIdSerializer, \
+ TicketRelationsSpecifics
+
+
+class RelationManagementModule(Component):
+ implements(IRequestHandler, ITemplateProvider)
+
+ # IRequestHandler methods
+ def match_request(self, req):
+ match = re.match(r'/ticket/([0-9]+)/relations/*$', req.path_info)
+ if not match:
+ return False
+
+ req.args['id'] = match.group(1)
+ return True
+
+ def process_request(self, req):
+ tid = req.args.get('id')
+ if not tid:
+ raise TracError(_('No ticket id provided.'))
+
+ try:
+ ticket = Ticket(self.env, tid)
+ except ValueError:
+ raise TracError(_('Invalid ticket id.'))
+
+ req.perm.require('TICKET_VIEW')
+ relsys = RelationsSystem(self.env)
+
+ if req.method == 'POST':
+ if req.args.has_key('remove'):
+ rellist = req.args.get('sel')
+ if rellist:
+ if isinstance(rellist, basestring):
+ rellist = [rellist, ]
+ for rel in rellist:
+ relsys.delete(rel)
+ elif req.args.has_key('add'):
+ dest_tid = req.args.get('dest_tid')
+ reltype = req.args.get('reltype')
+ comment = req.args.get('comment')
+ if dest_tid and reltype:
+ try:
+ dest_ticket = self.find_ticket(dest_tid)
+ except ValueError:
+ raise TracError(_('Invalid ticket id.'))
+ relsys.add(ticket, dest_ticket, reltype, comment,
+ req.authname)
+ else:
+ raise TracError(_('Invalid operation.'))
+
+ data = {
+ 'ticket': ticket,
+ 'reltypes': relsys.get_relation_types(),
+ 'relations': self.get_ticket_relations(ticket),
+ }
+ return 'manage.html', data, None
+
+ # ITemplateProvider methods
+ def get_htdocs_dirs(self):
+ resource_filename = pkg_resources.resource_filename
+ return [('relations', resource_filename('bhrelations', 'htdocs')), ]
+
+ def get_templates_dirs(self):
+ resource_filename = pkg_resources.resource_filename
+ return [resource_filename('bhrelations', 'templates'), ]
+
+ # utility functions
+ def get_ticket_relations(self, ticket):
+ grouped_relations = {}
+ relsys = RelationsSystem(self.env)
+ reltypes = relsys.get_relation_types()
+ for r in relsys.get_relations(ticket):
+ r['desthref'] = get_resource_url(self.env, r['destination'],
+ self.env.href)
+ grouped_relations.setdefault(reltypes[r['type']], []).append(r)
+ return grouped_relations
+
+ def find_ticket(self, tid):
+ try:
+ ticket = Ticket(self.env, tid)
+ except ValueError:
+ trs = TicketRelationsSpecifics(self.env)
+ try:
+ resource = ResourceIdSerializer.get_resource_by_id(tid)
+ ticket = trs._create_ticket_by_full_id(resource)
+ except:
+ raise ValueError
+ return ticket
+