Skip to content
This repository has been archived by the owner on Sep 17, 2019. It is now read-only.

fix Attachment File on other storage without path #103

Merged
merged 3 commits into from
Sep 11, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions mailqueue/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@


from django.conf import settings
from django.core.files.base import ContentFile
from django.core.mail import EmailMultiAlternatives
from django.db import models
from django.utils.encoding import python_2_unicode_compatible
Expand Down Expand Up @@ -69,8 +70,18 @@ def add_attachment(self, attachment):
if self.pk is None:
self._save_without_sending()

Attachment.objects.create(email=self, file_attachment=attachment,
original_filename=attachment.file.name.split('/')[-1])
original_filename = attachment.file.name.split('/')[-1]
file_content = ContentFile(attachment.read())

new_attachment = Attachment()
new_attachment.file_attachment.save(original_filename, file_content, save=False)
new_attachment.email = self
new_attachment.original_filename = original_filename
try:
new_attachment.save()
except Exception as e:
logger.error(e)
new_attachment.file_attachment.delete()

def _save_without_sending(self, *args, **kwargs):
"""
Expand Down