Opened 8 years ago

Last modified 3 years ago

#4703 assigned enhancement

IncludeMacro personalized targets based on config

Reported by: christer@… Owned by: Ryan J Ollos
Priority: normal Component: IncludeMacro
Severity: normal Keywords:
Cc: Trac Release: 0.11


Possible additional functionality.

I added the following to my 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:

custom_source_format = google,yahoo = =



    4747                dest_format = self.default_formats[source_format]
    4848            except KeyError:
    4949                pass
     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
    5159        if source_format in ('http', 'https', 'ftp'):
    5260            # Since I can't really do recursion checking, and because this
    8492            ctxt = Context.from_request(req, 'source', source_obj)
    8593        # RFE: Add ticket: and comment: sources. <NPK>
    8694        # 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 =
     102                except urllib2.URLError, e:
     103                    return system_message('Error while retrieving file. Format: "param1=value1&param2=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&param2=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&param2=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
    87110        else:
    88111            return system_message('Unsupported include source %s'%source)

Attachments (0)

Change History (1)

comment:1 Changed 3 years ago by Ryan J Ollos

Owner: changed from Noah Kantrowitz to Ryan J Ollos
Status: newassigned

Modify Ticket

Change Properties
Set your email in Preferences
as assigned The owner will remain Ryan J Ollos.

Add Comment

E-mail address and name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.