Forum attachments

The forum_attachments application handles all the attachments that can be associated with forum posts.

Abstract models

Forum attachments abstract models

This module defines abstract models provided by the forum_attachments application.

class machina.apps.forum_conversation.forum_attachments.abstract_models.AbstractAttachment(*args, **kwargs)

Bases: django.db.models.base.Model

Represents a post attachment. An attachment is always linked to a post.


Returns the filename of the considered attachment.


Returns the path to upload the associated file to.

machina.apps.forum_conversation.forum_attachments.abstract_models.get_attachment_file_upload_to(instance, filename)

Returns a valid upload path for the file of an attachment.


Forum attachments cache

This module defines an abstraction allowing to put forum attachments into cache when users are creating forum posts and topics.

class machina.apps.forum_conversation.forum_attachments.cache.AttachmentCache

Bases: object

The attachments cache.

This one should be used with a FileBasedCache backend. But this can be overriden. The attachments cache acts as a wrapper and ensure that the states (name, size, content type, charset and content) of all files from any request.FILES dict are saved inside the considered backend when calling the ‘set’ method. Conversely, the ‘get’ method will populate a dictionary of InMemoryUploadedFile instances or TemporaryUploadedFile instancesby using these states.


Deletes a file associated with a specific key.


Regenerates a MultiValueDict instance containing the files related to all file states stored for the given key.


Returns the associated cache backend.

set(key, files)

Stores the state of each file embedded in the request.FILES MultiValueDict instance.

This instance is assumed to be passed as the ‘files’ argument. Each state stored in the cache is a dictionary containing the following values:

The name of the uploaded file.
The size of the uploaded file.
The content type of the uploaded file.
The content length of the uploaded file.
The charset of the uploaded file.
The content of the uploaded file.


Forum attachments views

This module defines views provided by the forum_attachments application.

class machina.apps.forum_conversation.forum_attachments.views.AttachmentView(**kwargs)

Bases: machina.apps.forum_permission.viewmixins.PermissionRequiredMixin, django.views.generic.detail.DetailView

Allows to retrieve a forum attachment.


Returns the controlled object.


alias of machina.core.db.models.Attachment

perform_permissions_check(user, obj, perms)

Performs the permission check.

render_to_response(context, **response_kwargs)

Generates the appropriate response.