Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…38de4a9-2c31-0410-bb0d-d01ad7a04d2d
  • Loading branch information
maierman committed May 29, 2007
1 parent 320dcda commit de9aa86
Showing 1 changed file with 23 additions and 18 deletions.
41 changes: 23 additions & 18 deletions tracduplicates/web_ui.py
@@ -1,5 +1,3 @@
from time import time

from trac.core import *
from trac.web.api import IRequestFilter
from trac.web.chrome import ITemplateProvider, add_stylesheet, add_script
Expand All @@ -14,7 +12,10 @@ class DuplicatesModule(Component):

# IRequestFilter methods
def pre_process_request(self, req, handler):
if req.path_info.startswith('/ticket/') and req.method == 'POST' and not req.args.has_key('preview'):
if not req.path_info.startswith('/ticket/') or not req.method == 'POST':
return handler

if not req.args.has_key('preview'):
if req.args.get('action') == 'duplicate':
req.args['action'] = 'resolve'
req.args['resolve_resolution'] = 'duplicate'
Expand Down Expand Up @@ -45,27 +46,31 @@ def get_templates_dirs(self):
def prepare_ticket(self, req, ticket, fields, actions):
return handler

def save_changes(self, author, comment, when=0, db=None, cnum=''):
dupeticket = Ticket(self.env, self.duplicate_id, db=db)
dupeticket.save_changes(
get_reporter_id(req, 'author'),
"*** Ticket #%d marked duplicate of this one ***" % self.id,
when=when,
db=db
)
if not comment or not len(comment.strip()):
comment = ""
else:
comment += "\n\n"
comment += "*** Marked duplicate of #%d ***" % self.duplicate_id
return self._dhook_save_changes(author, comment, when=when, db=db, cnum=cnum)

def validate_ticket(self, req, ticket):
""" Somewhat hacky; what if we later fail... Anyway :p """
if req.args.get('is_duped'):
now = int(time())
db = self.env.get_db_cnx()
comment = req.args.get('comment')
try:
dupeid = int(req.args.get('duplicate_id'))
dupeticket = Ticket(self.env, dupeid, db=db)
dupeticket.save_changes(
get_reporter_id(req, 'author'),
"*** Ticket #%d marked duplicate of this one ***" % ticket.id,
when=now,
db=db
)
if not comment or not len(comment.strip()):
comment = ""
else:
comment += "\n\n"
comment += "*** Marked duplicate of #%d ***" % dupeid
req.args['comment'] = comment
Ticket(self.env, dupeid, db=db)
ticket.duplicate_id = dupeid
ticket._dhook_save_changes = ticket.save_changes
ticket.save_changes = self.save_changes
except (ValueError, TypeError, TracError):
yield None, "Invalid Duplicate Ticket Id"

0 comments on commit de9aa86

Please sign in to comment.