Modify

Opened 16 years ago

Last modified 5 years ago

#4703 new enhancement

IncludeMacro personalized targets based on config

Reported by: christer@… 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

     
    4747                dest_format = self.default_formats[source_format]
    4848            except KeyError:
    4949                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
    5058       
    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 = urlf.read()
     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)
    89112           

Attachments (0)

Change History (2)

comment:1 Changed 11 years ago by Ryan J Ollos

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

comment:2 Changed 5 years ago by Ryan J Ollos

Owner: Ryan J Ollos deleted
Status: assignednew

Modify Ticket

Change Properties
Set your email in Preferences
Action
as new The ticket will remain with no owner.

Add Comment


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

 
Note: See TracTickets for help on using tickets.