core.models.Attachment module¶
Module with the Attachment model class.
- class core.models.Attachment.Attachment(*args, **kwargs)[source]¶
Bases:
ExportModelOperationsMixin('attachment'),DownloadMixin,ThumbnailMixin,URLMixin,FavoriteModelMixin,FilePathModelMixin,TimestampModelMixin,ModelDatabase model for an attachment file in a mail.
- BASENAME = 'attachment'¶
- DELETE_NOTICE = 'This will only delete the record of this attachment, not of the email.'¶
- DELETE_NOTICE_PLURAL = 'This will only delete the records of these attachments, not of their emails.'¶
- file_name¶
The filename of the attachment.
- content_disposition¶
The disposition of the file. Typically ‘attachment’, ‘inline’ or ‘’.
- content_id¶
The MIME subtype of the file.
- content_maintype¶
The MIME maintype of the file.
- content_subtype¶
The MIME subtype of the file.
- datasize¶
The filesize of the attachment.
- email: ForeignKey¶
The mail that the attachment was found in. Deletion of that email deletes this attachment.
- save(*args, **kwargs)[source]¶
Extended :django:
django.models.Model.save()method.Saves the data to storage if configured.
Sends this attachment to the Paperless server of its user.
- Return type:
- Returns:
The uuid string of the Paperless consumer task for the document.
- Raises:
FileNotFoundError – If the attachment file was not found in the storage.
RuntimeError – If the users Paperless URL is not or improperly set.
ConnectionError – If connecting to Paperless failed.
PermissionError – If authentication to Paperless failed.
ValueError – If uploading the file to Paperless resulted in a bad response.
- exception DoesNotExist¶
Bases:
ObjectDoesNotExist
- exception MultipleObjectsReturned¶
Bases:
MultipleObjectsReturned
- _meta = <Options for Attachment>¶
- created¶
The datetime the model instance was created. Is set automatically.
- email_id¶
- file_path¶
The relative path in the storage where the file is stored. Can be null if no file has been saved (null does not collide with the unique constraint.).
- get_next_by_created(*, field=<django.db.models.fields.DateTimeField: created>, is_next=True, **kwargs)¶
- get_next_by_updated(*, field=<django.db.models.fields.DateTimeField: updated>, is_next=True, **kwargs)¶
- get_previous_by_created(*, field=<django.db.models.fields.DateTimeField: created>, is_next=False, **kwargs)¶
- get_previous_by_updated(*, field=<django.db.models.fields.DateTimeField: updated>, is_next=False, **kwargs)¶
- id¶
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- is_favorite¶
Flags favorite accounts. False by default.
- objects = <django.db.models.manager.Manager object>¶
Sends this attachment to the Immich server of its user.
- Return type:
- Returns:
The response by Immich with the id string of the stored immich image.
- Raises:
FileNotFoundError – If the attachment file was not found in the storage.
RuntimeError – If the users Immich URL is not or improperly set.
ConnectionError – If connecting to Immich failed.
PermissionError – If authentication to Immich failed.
ValueError – If uploading the file to Immich resulted in a bad response.
- updated¶
The datetime the model instance entry was last updated. Is set automatically.
- property has_thumbnail: bool¶
Whether the attachment has a mimetype that can be embedded into html.
References
https://stackoverflow.com/questions/51107683/which-mime-types-can-be-displayed-in-browser
- property thumbnail: str[source]¶
Builds the html thumbnail for the attachment.
- Returns:
The html for the thumbnail. The empty string if the attachment has no thumbnail.
- property content_type: str¶
Reconstructs the full MIME content type of the attachment.
- Returns:
The attachments content type if known, else “”.
Whether the attachment has a mimetype that can be processed by a paperless server.
References
https://docs.paperless-ngx.com/faq/#what-file-types-does-paperless-ngx-support
Whether the attachment has a mimetype that can be processed by a Immich server.
References
- classmethod create_from_email_message(email_message, email)[source]¶
Creates :class:`core.models.Attachment`s from an email message.
- Parameters:
email_message (
EmailMessage) – The email_message to get and create all attachments from.email (
Email) – The email model created from the email_message.
- Return type:
- Returns:
A list of
core.models.Attachmentin the email message.
- static queryset_as_file(queryset)[source]¶
Processes the files of the emails in the queryset into a temporary file.
- Parameters:
queryset (
QuerySet) – The email queryset to compile into a file.- Return type:
_TemporaryFileWrapper- Returns:
The temporary file wrapper.
- Raises:
Attachment.DoesNotExist – If the
querysetis empty.