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

Commit

Permalink
Merge pull request #103 from blodone/master
Browse files Browse the repository at this point in the history
fix Attachment File on other storage without path
  • Loading branch information
dstegelman authored Sep 11, 2017
2 parents 9288c88 + dcd283c commit 621899d
Showing 1 changed file with 13 additions and 2 deletions.
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

0 comments on commit 621899d

Please sign in to comment.