Emmanuel Blot wrote:
> Hi,
>
> I'm a bit lost within the Context and Resource space ;-)
>
> I'd like to retrieve the files attached to a Wiki page, based on the
> name of the page.
> I need to obtain the list of attached files, then the content of one
> of these files - from a plugin.
>
> I'm not sure to understand which "context" the AttachementModule
> expects as the argument of attachment_data() for example.
>
> I guess I should use "WikiPage('name')" to retrieve the proper
> WikiPage instance, but from there, I'm not sure what to do to provide
> a "context".
>
> The attachment retrieval should not be tied to a web request for my needs.
>
Well, the attachment retrieval per se is not tied to a web request, but
the AttachmentModule.attachment_data(context) method is specialized for
retrieving attachment data in a form suitable for the actual templates
(attachment.html and macros.html).
So if what you need is the lists of all attachments for a resource,
nothing more, then use Attachment.select(env, parent_realm, parent_id),
which will give you back a list of Attachment instances. It's then up to
you to do the right thing with them.
If you plan to use the list_of_attachments macro from macros.html, then
you can use the AttachmentModule.attachment_data(context) helper method,
in which case the given Context has to contain at least the Resource
corresponding to the parent resource, the PermissionCache object that
will be used to restrict the list of attachment to those which are
actually viewable and a Href that will be used for creating URLs to the
attachments (note that the Request itself is not needed).
-- Christian
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---