Emmanuel Blot wrote:
> Hi,
>
> This is probably a stupid question, but I'd like to obtain the current
> version of the rendered wiki page from a new-style macro.
>
> I initially thought that I could obtain in from the context
>
> def render_macro(self, formatter, name, args):
> version = formatter.context.version
>
> but version is None, such as in the following example (wiki/SandBox)
>
> formatter.context: {'realm': 'wiki', 'parent': None, '_db': , 'req': ,
> 'abs_urls': False, 'version': None, 'env': , 'id': u'SandBox'}
>
> How could I get this version number ? [and when does the version
> parameter get filled?]
>
The parameter gets filled during request processing, from the request
parameters. In a way, the Context is a kind of "normalization" of the
request, a way to /specify/ what resource is accessed and how it is
accessed.
In that light, it's easy to see that "context.version == None" means
"we're talking about the /last/ version of that resource", with the
usual meaning of 'head' or 'latest' associated to None, as in the
versioncontrol subsystem.
So the context doesn't spare you (yet) the need to retrieve the actual
resource from the db, and query more precise information from the data
model (in this case, get the actual number corresponding to the latest
version).
The security branch makes this a bit easier, your example would read:
def render_macro(self, formatter, name, args):
version = formatter.context.resource.version
context.resource retrieves the data model object specified by the
context (at the appropriate revision, see
http://trac.edgewall.org/browser/sandbox/security/trac/wiki/api.py#L153).
Another example where you can see both ways:
http://trac-hacks.org/browser/tocmacro/0.11/tractoc/macro.py?rev=1894#L97
-- Christian
PS: keep in mind that render_macro will soon be format_macro ;)
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Trac
Development" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/trac-dev?hl=en
-~----------~----~----~----~------~----~------~--~---