<s> from trac . core import Component , implements <EOL> from trac . resource import ResourceNotFound <EOL> from trac . ticket . api import ITicketActionController <EOL> from trac . ticket . default_workflow import ConfigurableTicketWorkflow <EOL> from trac . ticket . model import Milestone <EOL> from trac . util . translation import _ <EOL> from trac . web . chrome import add_warning <EOL> revision = "<STR_LIT>" <EOL> url = "<STR_LIT>" <EOL> class MilestoneOperation ( Component ) : <EOL> """<STR_LIT>""" <EOL> implements ( ITicketActionController ) <EOL> def get_ticket_actions ( self , req , ticket ) : <EOL> actions_we_handle = [ ] <EOL> if req . authname != '<STR_LIT>' and '<STR_LIT>' in req . perm ( ticket . resource ) : <EOL> controller = ConfigurableTicketWorkflow ( self . env ) <EOL> actions_we_handle = controller . get_actions_by_operation_for_req ( <EOL> req , ticket , '<STR_LIT>' ) <EOL> self . log . debug ( '<STR_LIT>' , actions_we_handle ) <EOL> return actions_we_handle <EOL> def get_all_status ( self ) : <EOL> return [ ] <EOL> def render_ticket_action_control ( self , req , ticket , action ) : <EOL> actions = ConfigurableTicketWorkflow ( self . env ) . actions <EOL> label = actions [ action ] [ '<STR_LIT:label>' ] <EOL> res_ms = self . __get_resolution_milestone_dict ( ticket , action ) <EOL> resolutions = '<STR_LIT>' <EOL> milestone = None <EOL> for i , resolution in enumerate ( res_ms ) : <EOL> if i > <NUM_LIT:0> : <EOL> resolutions = "<STR_LIT>" % ( resolutions , resolution ) <EOL> else : <EOL> resolutions = "<STR_LIT>" % resolution <EOL> milestone = res_ms [ resolution ] <EOL> hint = None <EOL> if res_ms : <EOL> try : <EOL> Milestone ( self . env , milestone ) <EOL> except ResourceNotFound : <EOL> pass <EOL> else : <EOL> hint = _ ( "<STR_LIT>" <EOL> "<STR_LIT>" , <EOL> resolutions = resolutions , milestone = milestone ) <EOL> return label , None , hint <EOL> def get_ticket_changes ( self , req , ticket , action ) : <EOL> if action == '<STR_LIT>' and req . args and '<STR_LIT>' in req . args : <EOL> old_milestone = ticket . _old . get ( '<STR_LIT>' ) or None <EOL> user_milestone = ticket [ '<STR_LIT>' ] or None <EOL> if old_milestone is None : <EOL> new_status = req . args [ '<STR_LIT>' ] <EOL> new_milestone = self . __get_new_milestone ( ticket , action , <EOL> new_status ) <EOL> if new_milestone is not None or user_milestone is None : <EOL> try : <EOL> Milestone ( self . env , new_milestone ) <EOL> except ResourceNotFound : <EOL> add_warning ( req , _ ( "<STR_LIT>" <EOL> "<STR_LIT>" , name = new_milestone ) ) <EOL> else : <EOL> self . log . info ( '<STR_LIT>' , <EOL> old_milestone , new_milestone ) <EOL> return { '<STR_LIT>' : new_milestone } <EOL> return { } <EOL> def apply_action_side_effects ( self , req , ticket , action ) : <EOL> pass <EOL> def __get_new_milestone ( self , ticket , action , new_status ) : <EOL> """<STR_LIT>""" <EOL> if new_status : <EOL> res_ms = self . __get_resolution_milestone_dict ( ticket , action ) <EOL> return res_ms . get ( new_status ) <EOL> def __get_resolution_milestone_dict ( self , ticket , action ) : <EOL> transitions = self . config . get ( '<STR_LIT>' , <EOL> action + '<STR_LIT>' ) . strip ( ) <EOL> transition = [ x . strip ( ) for x in transitions . split ( '<STR_LIT>' ) ] <EOL> res_milestone = { } <EOL> if len ( transition ) == <NUM_LIT:2> : <EOL> resolutions = [ y . strip ( ) for y in transition [ <NUM_LIT:0> ] . split ( '<STR_LIT:U+002C>' ) ] <EOL> for res in resolutions : <EOL> res_milestone [ res ] = transition [ <NUM_LIT:1> ] <EOL> return res_milestone </s>
