trac.attachment – Attachments for Trac resources¶
This module contains the Attachment model class and the
AttachmentModule component which manages file attachments for any
kind of Trac resources. Currently, the wiki pages, tickets and
milestones all support file attachments. You can use the same utility
methods from the AttachmentModule as they do for easily adding
attachments to other kinds of resources.
See also the
attach_file_form.html
and
attachment.html templates
which can be used to display the attachments.
Interfaces¶
-
class
trac.attachment.IAttachmentChangeListener¶ Extension point interface for components that require notification when attachments are created or deleted.
See also trac.attachment.IAttachmentChangeListener extension point
-
attachment_added()¶ Called when an attachment is added.
-
attachment_deleted()¶ Called when an attachment is deleted.
-
attachment_reparented(old_parent_realm, old_parent_id)¶ Called when an attachment is reparented.
-
-
class
trac.attachment.IAttachmentManipulator¶ Extension point interface for components that need to manipulate attachments.
Unlike change listeners, a manipulator can reject changes being committed to the database.
See also trac.attachment.IAttachmentManipulator extension point
-
prepare_attachment(attachment, fields)¶ Not currently called, but should be provided for future compatibility.
-
validate_attachment(attachment)¶ Validate an attachment after upload but before being stored in Trac environment.
Must return a list of
(field, message)tuples, one for each problem detected.fieldcan be any ofdescription,username,filename,content, orNoneto indicate an overall problem with the attachment. Therefore, a return value of[]means everything is OK.
-
-
class
trac.attachment.ILegacyAttachmentPolicyDelegate¶ Interface that can be used by plugins to seamlessly participate to the legacy way of checking for attachment permissions.
This should no longer be necessary once it becomes easier to setup fine-grained permissions in the default permission store.
See also trac.attachment.ILegacyAttachmentPolicyDelegate extension point
Classes¶
-
class
trac.attachment.Attachment(env, parent_realm_or_attachment_resource, parent_id=None, filename=None, db=None)¶ Represents an attachment (new or existing).
Since 1.0.5: ipnris deprecated and will be removed in 1.3.1-
delete(db=None)¶ Delete the attachment, both the record in the database and the file itself.
Changed in version 1.0: the
dbparameter is no longer needed (will be removed in version 1.1.1)
-
insert(filename, fileobj, size, t=None, db=None)¶ Create a new Attachment record and save the file content.
Changed in version 1.0: the
dbparameter is no longer needed (will be removed in version 1.1.1)
-
classmethod
select(env, parent_realm, parent_id, db=None)¶ Iterator yielding all
Attachmentinstances attached to resource identified byparent_realmandparent_id.Returns: a tuple containing the filename,description,size,time,authorandipnr.Since 1.0: the dbparameter is deprecated and will be removed in 1.1.1Since 1.0.5: use of ipnris deprecated and will be removed in 1.3.1
-
classmethod
delete_all(env, parent_realm, parent_id, db=None)¶ Delete all attachments of a given resource.
Changed in version 1.0: the
dbparameter is no longer needed (will be removed in version 1.1.1)
-
classmethod
reparent_all(env, parent_realm, parent_id, new_realm, new_id)¶ Reparent all attachments of a given resource to another resource.
-
-
exception
trac.attachment.InvalidAttachment(message, title=None, show_traceback=False)¶ Exception raised when attachment validation fails.
If message is a genshi.builder.tag object, everything up to the first <p> will be displayed in the red box, and everything after will be displayed below the red box. If title is given, it will be displayed as the large header above the error message.
Components¶
-
class
trac.attachment.AttachmentModule¶ -
change_listeners¶ List of components that implement
IAttachmentChangeListener
-
manipulators¶ List of components that implement
IAttachmentManipulator
-
max_size¶ Maximum allowed file size (in bytes) for attachments.
-
max_zip_size¶ Maximum allowed total size (in bytes) for an attachment list to be downloadable as a
zip. Set this to -1 to disable download aszip. (‘’since 1.0’’)
-
render_unsafe_content¶ Whether attachments should be rendered in the browser, or only made downloadable.
Pretty much any file may be interpreted as HTML by the browser, which allows a malicious user to attach a file containing cross-site scripting attacks.
For public sites where anonymous users can create attachments it is recommended to leave this option disabled (which is the default).
-
viewable_attachments(context)¶ Return the list of viewable attachments in the given context.
Parameters: context – the RenderingContextcorresponding to the parentResourcefor the attachments
-
attachment_data(context)¶ Return a data dictionary describing the list of viewable attachments in the current context.
-
get_history(start, stop, realm)¶ Return an iterable of tuples describing changes to attachments on a particular object realm.
The tuples are in the form (change, realm, id, filename, time, description, author).
changecan currently only becreated.FIXME: no iterator
-
get_timeline_events(req, resource_realm, start, stop)¶ Return an event generator suitable for ITimelineEventProvider.
Events are changes to attachments on resources of the given
resource_realm.realm.
-
get_search_results(req, resource_realm, terms)¶ Return a search result generator suitable for ISearchSource.
Search results are attachments on resources of the given
resource_realm.realmwhose filename, description or author match the given terms.
-
-
class
trac.attachment.AttachmentAdmin¶ trac-admin command provider for attachment administration.