diff --git a/.travis.yml b/.travis.yml index 4d29532..63add2a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,6 +8,7 @@ env: - DJANGO_VERSION=Django==1.8 - DJANGO_VERSION=Django==1.9 - DJANGO_VERSION=Django==1.10 + - DJANGO_VERSION=Django==1.11 # command to install dependencies install: diff --git a/mailqueue/admin.py b/mailqueue/admin.py index f10201f..4568d1a 100644 --- a/mailqueue/admin.py +++ b/mailqueue/admin.py @@ -14,6 +14,7 @@ class MailerAdmin(admin.ModelAdmin): search_fields = ['to_address', 'subject', 'app', 'cc_address', 'bcc_address', 'reply_to'] actions = ['send_failed'] inlines = [AttachmentInline] + date_hierarchy = "created" def send_failed(self, request, queryset): emails = queryset.filter(sent=False) diff --git a/mailqueue/models.py b/mailqueue/models.py index 6344d70..81dfa5b 100644 --- a/mailqueue/models.py +++ b/mailqueue/models.py @@ -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 @@ -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): """