From b6339cc01653c28acc4c498b3663641a0672efe5 Mon Sep 17 00:00:00 2001 From: Tony Zhu Date: Tue, 19 Nov 2013 21:24:52 +0000 Subject: [PATCH] Fix the bug of handling attachments when Django DEFAULT_FILE_STORAGE is not FileSystemStorage --- helpdesk/forms.py | 6 +++++- helpdesk/models.py | 5 +++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/helpdesk/forms.py b/helpdesk/forms.py index 672ae38b..545f60a7 100644 --- a/helpdesk/forms.py +++ b/helpdesk/forms.py @@ -11,6 +11,7 @@ from StringIO import StringIO from django import forms from django.forms import extras +from django.core.files.storage import default_storage from django.conf import settings from django.contrib.auth.models import User from django.utils.translation import ugettext as _ @@ -305,7 +306,10 @@ class TicketForm(forms.Form): if file.size < getattr(settings, 'MAX_EMAIL_ATTACHMENT_SIZE', 512000): # Only files smaller than 512kb (or as defined in # settings.MAX_EMAIL_ATTACHMENT_SIZE) are sent via email. - files.append(a.file.path) + try: + files.append(a.file.path) + except NotImplementedError: + pass context = safe_template_context(t) context['comment'] = f.comment diff --git a/helpdesk/models.py b/helpdesk/models.py index ef30b1cf..15946286 100644 --- a/helpdesk/models.py +++ b/helpdesk/models.py @@ -604,8 +604,9 @@ def attachment_path(instance, filename): os.umask(0) path = 'helpdesk/attachments/%s/%s' % (instance.followup.ticket.ticket_for_url, instance.followup.id ) att_path = os.path.join(settings.MEDIA_ROOT, path) - if not os.path.exists(att_path): - os.makedirs(att_path, 0777) + if settings.DEFAULT_FILE_STORAGE == "django.core.files.storage.FileSystemStorage": + if not os.path.exists(att_path): + os.makedirs(att_path, 0777) return os.path.join(path, filename)