o k`*@sddlZddlTddlmZddlmZddlmZmZddl m Z ddl m Z ddl mZdd lmZmZdd lmZdd lmZmZdd lmZmZdd lmZmZmZddlmZm Z m!Z!Gddde"Z#dS)N)*)NotificationSystem)IPermissionRequestor)ITicketManipulator TicketSystem)Ticket)BatchTicketChangeEvent)to_list) datetime_nowutc)tag)exception_to_unicode to_unicode)_tag_)HTTPBadRequestIRequestFilterIRequestHandler)Chromeadd_script_data add_warningc@seZdZdZeeeedZe e Z e dZdZddZddZd d Zd d Zd dZddZddZddZddZddZddZddZdS)BatchModifyModuleacTicket batch modification module. This component allows multiple tickets to be modified in one request from the custom query page. For users with the TICKET_BATCH_MODIFY permission it will add a [TracBatchModify batch modify] section underneath custom query results. Users can choose which tickets and fields they wish to modify. Fz[;\s,]+z, cCs |jdkS)Nz /batchmodify) path_info)selfreqr3/usr/lib/python3/dist-packages/trac/ticket/batch.py match_request5s zBatchModifyModule.match_requestc Cs|jdkr ttd|jd|jdd}|jd}i}t|j D]*}|d}|dd |jvr6d nd vrQ|d d krQd|}||jvrQ|j|||<q't |jdd}| |||||| |jdpp|j dS)NPOSTzInvalid request arguments.TICKET_BATCH_MODIFYbatchmod_value_commentactionname)id resolutionstatusownertime changetimesummary description TICKET_ADMIN)reporterrtypetextareabatchmod_value_selected_tickets query_href)methodrrpermrequireargsgetrenvget_ticket_fieldsr _save_ticket_changesredirecthrefquery) rrcommentr" new_valuesfieldr#arg_namer1rrrprocess_request8s,        z!BatchModifyModule.process_requestcCs|S)Nr)rrhandlerrrrpre_process_requestVsz%BatchModifyModule.pre_process_requestcCsZ|jdkr(|dur(d|dvr(||||dt|j}|||||||fS)Nz/queryrtickettickets)rr4add_template_datarr8add_auto_previewadd_wiki_toolbars)rrtemplatedatametadatachromerrrpost_process_requestYs    z&BatchModifyModule.post_process_requestcCsdddgfddgfgS)Nr TICKET_MODIFYr,rrrrrget_permission_actionsdsz(BatchModifyModule.get_permission_actionscCszd|d<|jdp |j|d<||||d<tdddtdd dtd d dtd d dg}t|||ddS)NT batch_modifyr2action_controlsadd+)r#valueremove-z add / remove+-zset to=)batch_list_modesbatch_list_properties)sessionr<r=_get_action_controlsrr_get_list_fields)rrrKrFr[rrrrGis     z#BatchModifyModule.add_template_datacCsddt|jDS)NcSs.g|]}|ddkr|ddkr|dqS)r.textformatlistr#)r7).0frrr ws z6BatchModifyModule._get_list_fields..)rr8r9rPrrrr_vs z"BatchModifyModule._get_list_fieldscs4fdd|D}i}i}|D]6}tjjD]-}|||p gD]"\}} | |vr:t|| ||| <|| |q!||| <|g|| <q!qqddtt|ddddD} g} | D];} d} g} g}|| d} ||| D]}| ||| \}}}| s|} ||| |qq| | | t || fq\| S) Ncsg|] }tj|dqS)r$)rr8)rctrPrrre|sz:BatchModifyModule._get_action_controls..cSsg|]\}}|qSrr)rcawrrrrecSs|d|dfS)Nrr)itemrrrsz8BatchModifyModule._get_action_controls..T)keyreverser) rr8action_controllersget_ticket_actionsmaxappendsortediteritems_get_action_controllersrender_ticket_action_controlr )rr ticket_datarFaction_weightsaction_ticketsrfctrlweightr"sorted_actionsrS first_labelhintswidgetsrE controllerlabelwidgethintrrPrr^{sN      z&BatchModifyModule._get_action_controlsccs@t|jjD]}dd|||pgD}||vr|VqdS)z>Generator yielding the controllers handling the given `action`cSsg|]\}}|qSrr)rcrhrgrrrreriz=BatchModifyModule._get_action_controllers..N)rr8rorp)rrrEr"ractionsrrrrvsz)BatchModifyModule._get_action_controllersc Cs~|}|}|D]2}|jd|}|r<||vr||nd}|jd|d} |jd|d} ||| | |||<q |S)Nbatchmod_mode_r!batchmod_primary_batchmod_secondary_)r_copyr6r7 _change_list) rrrEr? list_fields_valuesr@modeoldnewnew2rrr_get_updated_ticket_valuessz,BatchModifyModule._get_updated_ticket_valuesc Csd}|jD]}t|dr |||D] }d}t|td|dqqg} |D]U} t|j| } ||| |} ||| |D] } | | || |q;| | |jD]$}| || D]\}}d}|rnt|tdt ||dqXt||qXqP| | q%|sdStt}|jj'| D]} | j|j||d ||| |D] } | || |qqWdn1swYt|||j|||}z t|j|WdSty}z|jd t|t|td t|dWYd}~dSd}~ww) zSave changes to tickets.Tvalidate_commentFz*The ticket comment is invalid: %(message)s)messagez2The ticket field %(field)s is invalid: %(message)s)r@rN)whenz6Failure sending notification on ticket batchchange: %sz[The changes have been saved, but an error occurred while sending notifications: %(message)s)ticket_manipulatorshasattrrrrrr8rrvupdateget_ticket_changespopulatevalidate_ticketr strongrrr r db_transaction save_changesauthnameapply_action_side_effectsrrnotify Exceptionlogerrorr r)rrr1r?r>r"valid manipulatorrrFid_rfvaluesctlrr@reventerrrr:sn         z&BatchModifyModule._save_ticket_changescCst||j}t||j}t||j}|dkr|}nN|dkr,|D] }||vr*||qn;|dkrC|D]}||vrA||||vs8q2n$|dkrg|D] }||vrT||qI|D]}||vrf||||vs]qW|j|S)NrZrUrXrY)r list_separator_rerrrWlist_connector_stringjoin)rold_listnew_list new_list2r changed_listentryrrrrs:        zBatchModifyModule._change_listN)__name__ __module__ __qualname____doc__ implementsrrris_valid_default_handlerExtensionPointrrrecompilerrrrBrDrNrQrGr_r^rvrr:rrrrrr!s&    % 6r)$r trac.coretrac.notification.apir trac.permrtrac.ticket.apirrtrac.ticket.modelrtrac.ticket.notificationr trac.utilr trac.util.datefmtr r trac.util.htmlr trac.util.textr rtrac.util.translationrr trac.web.apirrrtrac.web.chromerrr Componentrrrrrs