mirror of
https://github.com/django-helpdesk/django-helpdesk.git
synced 2024-12-13 10:21:05 +01:00
Allow file attachments in storages other than local files (eg S3). Fixes GH-249.
This commit is contained in:
parent
1aed98463a
commit
4c901880bc
@ -268,7 +268,7 @@ class TicketForm(CustomFieldMixin, forms.Form):
|
||||
# Only files smaller than 512kb (or as defined in
|
||||
# settings.MAX_EMAIL_ATTACHMENT_SIZE) are sent via email.
|
||||
try:
|
||||
files.append(a.file.path)
|
||||
files.append([a.filename, a.file])
|
||||
except NotImplementedError:
|
||||
pass
|
||||
|
||||
@ -441,7 +441,7 @@ class PublicTicketForm(CustomFieldMixin, 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)
|
||||
files.append([a.filename, a.file])
|
||||
|
||||
context = safe_template_context(t)
|
||||
|
||||
|
@ -45,8 +45,8 @@ def send_templated_mail(template_name, email_context, recipients, sender=None, b
|
||||
fail_silently is passed to Django's mail routine. Set to 'True' to ignore
|
||||
any errors at send time.
|
||||
|
||||
files can be a list of file paths to be attached, or it can be left blank.
|
||||
eg ('/tmp/file1.txt', '/tmp/image.png')
|
||||
files can be a list of tuple. Each tuple should be a filename to attach,
|
||||
along with the File objects to be read. files can be blank.
|
||||
|
||||
"""
|
||||
from django.conf import settings
|
||||
@ -123,11 +123,11 @@ def send_templated_mail(template_name, email_context, recipients, sender=None, b
|
||||
msg.attach_alternative(html_part, "text/html")
|
||||
|
||||
if files:
|
||||
if type(files) != list:
|
||||
files = [files,]
|
||||
|
||||
for file in files:
|
||||
msg.attach_file(file)
|
||||
for attachment in files:
|
||||
file_to_attach = attachment[1]
|
||||
file_to_attach.open()
|
||||
msg.attach(filename=attachment[0], content=file_to_attach.read())
|
||||
file_to_attach.close()
|
||||
|
||||
return msg.send(fail_silently)
|
||||
|
||||
|
@ -410,7 +410,7 @@ def update_ticket(request, ticket_id, public=False):
|
||||
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)
|
||||
files.append([a.filename, a.file])
|
||||
|
||||
|
||||
if title != ticket.title:
|
||||
|
Loading…
Reference in New Issue
Block a user