o k`.%@sddlmZddlmZddlmZmZmZddlm Z m Z m Z m Z ddl mZddlmZddlmZddlmZdd lmZmZdd lmZmZmZdd lmZdd lmZd dZ GdddeZ!GdddeZ"dS)) itemgetterresource_filename) Component implementsExtensionPoint)INotificationDistributorINotificationFormatterINotificationSubscriberNotificationSystem) Subscription)IPreferencePanelProvideras_int)tag)_ cleandoc_)ChromeITemplateProvider add_noticeget_session_attribute) WikiMacroBasecCst|||d|S)Nnotification.format.%sr)envsid authenticated transportr9/usr/lib/python3/dist-packages/trac/notification/prefs.pyget_preferred_format"sr c@seZdZeeeeeZee Z ee Z ddZ ddZdddZdd Zd d Zd d ZddZddZddZddZddZddZddZdS)NotificationPreferencescCs|j|j|j|jd|_dS)N)zadd-rulez delete-rulez move-rulereplace) _add_rule _delete_rule _move_rule_replace_rules post_handlersselfrrr__init__.s  z NotificationPreferences.__init__ccsdtdfVdS)N notification Notifications)r)r)reqrrrget_preference_panels8sz-NotificationPreferences.get_preference_panelsNc s*|jdkr7|jdddd}t|dkr.|\}}|j|}|r.|||t|td| |j di}g} i} i} i} g} |j D](}| }|sOqF|jjsX|rXqF| |jj|d t|d rn| |qFtd d | D}t|j}|D]G}g||<||| |<|jd || |<||| |<|||D]"|d}|rd|i}|fdd dD|||qqi}t| t ddD] \}}}}}|!|g||}|r||||dq|| | | | |dtdtddd}t"|j#|dt|dfS)NPOSTactionrz!Your preferences have been saved.r+)class descriptiondefault_subscriptionscss |] }|d|dfVqdS)r4r5Nr).0srrr WszBNotificationPreferences.render_preference_panel..rr4r5c3s|] }||fVqdSNr)r7keyrrrr9cs)idadverbr4priority)r;)r?r5)alwaysneverNotifyz Never notify)rules subscribers formattersselected_formatdefault_format default_rulesadverbs adverb_labelszprefs_notification.html)data)$methodargsgetfirstsplitlenr'getrrredirecthrefprefsrFr5sessionrrequires_authenticationappend __class____name__hasattrextendr6dictr r_iter_transports_get_supported_stylesget_default_format _iter_rulesupdatesortedr setdefaultr add_jquery_ui)r)r-panel path_info action_argr0arghandlerrErFrGrHrIdefaultsir5desc_mapnstvaluesrJklassdistformatr@r?rMrr<rrender_preference_panel;s              z/NotificationPreferences.render_preference_panelcCsgSr:rr(rrrget_htdocs_dirssz'NotificationPreferences.get_htdocs_dirscCstdd}|gS)Nztrac.notification templatesr)r) resource_dirrrrget_templates_dirss z*NotificationPreferences.get_templates_dirscCs~t|j}|jj|d<|jjrdnd|d<||d<|jd|d|d<|jd ||d <|jd ||d <t|j|dS) Nrr2rr distributorz format-%sr1rtz new-adverb-%sr?z new-rule-%sr4)r rrWrrrOrSadd)r)rjr-rulerrrr#s  z!NotificationPreferences._add_rulecCs |j}t|j||j|jdSr:)rWr deleterrr)r)rjr-rWrrrr$sz$NotificationPreferences._delete_rulecCshdd|ddD}t|dkr.|\}}|dkr0|dkr2|j}t|j|||j|jdSdSdSdS)NcSsg|]}t|dqS)rr)r7valrrr sz6NotificationPreferences._move_rule..-r2r3r)rQrRrWr moverrr)r)rjr-tokensrule_idr@rWrrrr%s z"NotificationPreferences._move_rulec Csg}|D]F}|jd|}|||}|jd||d|jd|}|jd|}ttt |t |D]}| ||||||dq;q|jj } |jj } |j jt|j | | |WddS1snwYdS)Nzformat-rr1zadverb-zclass-)rzrtr?r4)r_rOrP_normalize_formatrWsetgetlistrangeminrRrYrrrdb_transactionr replace_all) r)rjr- subscriptionsrformat_rKclassesidxrrrrrr&s*     "z&NotificationPreferences._replace_rulesccs.|j}t|j|j|j|D]}|VqdSr:)rWr find_by_sid_and_distributorrrr)r)r-rrWr=rrrrbsz#NotificationPreferences._iter_rulesccs&|jD] }|D]}|Vq qdSr:) distributors transports)r)rzrrrrr_s   z(NotificationPreferences._iter_transportscCs8t}|jD]}||D] \}}||q qt|Sr:)rrGget_supported_stylesr{rd)r)rstyles formatterstylerealm_rrrr`s   z-NotificationPreferences._get_supported_stylescCs|r ||}||vr |SdS)Nr1)r`)r)rrrrrrrs  z)NotificationPreferences._normalize_formatr:)r[ __module__ __qualname__rr rrr rFrrr rGr*r.rurvryr#r$r%r&rbr_r`rrrrrr!'s$  F   r!c@s eZdZdZedZddZdS)SubscriberListMacromessagesaDisplay a list of all installed notification subscribers, including documentation if available. Optionally, the name of a specific subscriber can be provided as an argument. In that case, only the documentation for that subscriber will be rendered. Note that this macro will not be able to display the documentation of subscribers if the `PythonOptimize` option is enabled for mod_python! c s|r|nd}|d}it|jjD]}|jj}|r"||r(||<qtj ddtj ddt t t tdt tdtfdd ttDS) Nr1*ztrac-subscriberlistclass_wiki Subscriber Descriptionc3sF|]\}}tjtt|t||drdnddVqdS)r3oddevenrN)rtrtdcode)r7rnameitemsrrr9s  z3SubscriberListMacro.expand_macro..)stripr rrFrZr[ startswithr5rdivtabletheadrthrtbody enumeraterd)r)rrcontent name_filter subscriberrrr expand_macros&       z SubscriberListMacro.expand_macroN)r[rr_domainr _descriptionrrrrrrs  rN)#operatorr pkg_resourcesr trac.corerrrtrac.notification.apirr r r trac.notification.modelr trac.prefs.apir trac.utilrtrac.util.htmlrtrac.util.translationrrtrac.web.chromerrrtrac.web.sessionrtrac.wiki.macrosrr r!rrrrrs        )