Modify ↓
Opened 16 years ago
Last modified 5 years ago
#4703 new enhancement
IncludeMacro personalized targets based on config
Reported by: | Owned by: | ||
---|---|---|---|
Priority: | normal | Component: | IncludeMacro |
Severity: | normal | Keywords: | |
Cc: | Trac Release: | 0.11 |
Description
Possible additional functionality.
I added the following to my macros.py to allow for adding new targets behind the scenes for includes (other people can just use the usual wiki target nomenclature and need not know the target paths). I am using this for including HTML produced by a different system that requires a token to be used for certain requests - this allows me to hide the token from users of my Trac.
Note that I am not using the INCLUDE_URL or any other checks in this code (because it would fail intermittently on my system). This is based on [3693] of includemacro/0.11.
conf.ini example:
[include] custom_source_format = google,yahoo google.target = http://www.google.com/? yahoo.target = http://www.yahoo.com/?
Patch:
-
macros.py
47 47 dest_format = self.default_formats[source_format] 48 48 except KeyError: 49 49 pass 50 51 ######## config BOF 52 try: 53 conf_source_format_string = self.config.get('include', 'custom_source_format') 54 conf_source_format = conf_source_format_string.split(',', 10) 55 except ValueError: # only one configured 56 pass 57 ######## config EOF 50 58 51 59 if source_format in ('http', 'https', 'ftp'): 52 60 # Since I can't really do recursion checking, and because this … … 84 92 ctxt = Context.from_request(req, 'source', source_obj) 85 93 # RFE: Add ticket: and comment: sources. <NPK> 86 94 # RFE: Add attachment: source. <NPK> 95 ######## config BOF 96 elif source_format in conf_source_format: 97 if source_format in conf_source_format: 98 custom_target = self.config.get('include', source_format+'.target') 99 try: 100 urlf = urllib2.urlopen(custom_target+source_obj) 101 out = urlf.read() 102 except urllib2.URLError, e: 103 return system_message('Error while retrieving file. Format: "param1=value1¶m2=value2" (the base URL is configured under the "include" section: "custom_source_format", "[custom_source_format].target".', str(e)) 104 except TracError, e: 105 return system_message('Error while previewing. Format: "param1=value1¶m2=value2" (the base URL is configured under the "include" section: "custom_source_format", "[custom_source_format].target".', str(e)) 106 ctxt = Context.from_request(req) 107 else: 108 return system_message('Unsupported include source %s. If you were trying to use a custom target, format: "[custom_target]:param1=value1¶m2=value2" (the base URL is configured under the "include" section: "custom_source_format", "[custom_source_format].target". Specified [custom_target]: "'%source+source_format+'". Configured values: '+conf_source_format_string) 109 ######## config EOF 87 110 else: 88 111 return system_message('Unsupported include source %s'%source) 89 112
Attachments (0)
Change History (2)
comment:1 Changed 11 years ago by
Owner: | changed from Noah Kantrowitz to Ryan J Ollos |
---|---|
Status: | new → assigned |
comment:2 Changed 5 years ago by
Owner: | Ryan J Ollos deleted |
---|---|
Status: | assigned → new |
Note: See
TracTickets for help on using
tickets.