Repository: django-helpdesk/django-helpdesk

Issue:
Error trying to attach a file when using django-storages
Hello,

I'm receiving this error when I try to attach a file

```
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/exception.py", line 41, in inner
    response = get_response(request)
  File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", line 187, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", line 185, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/opt/apps/project/.local/lib/python2.7/site-packages/helpdesk/decorators.py", line 21, in _wrapped_view
    return view_func(request, *args, **kwargs)
  File "/opt/apps/project/.local/lib/python2.7/site-packages/helpdesk/views/public.py", line 51, in homepage
    ticket = form.save()
  File "/opt/apps/project/.local/lib/python2.7/site-packages/helpdesk/forms.py", line 399, in save
    files=files)
  File "/opt/apps/project/.local/lib/python2.7/site-packages/helpdesk/forms.py", line 250, in _send_messages
    files=files,
  File "/opt/apps/project/.local/lib/python2.7/site-packages/helpdesk/lib.py", line 135, in send_templated_mail
    with open(filefield.path, 'rb') as attachedfile:
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/fields/files.py", line 65, in path
    return self.storage.path(self.name)
  File "/usr/local/lib/python2.7/dist-packages/django/core/files/storage.py", line 111, in path
    raise NotImplementedError("This backend doesn't support absolute paths.")
NotImplementedError: This backend doesn't support absolute paths.
```
In the admin section I can create a new ticket and attach a file without a problem, but when I try to send a ticket outside the admin section is when the error occur.
This is pretty similar to this issue #249, since I'm using django-storages


Discussion:
I'm getting this error too, and I don't understand what is causing it given that the ticket is actually created and even the attachment exists. So I really don't get where the error is occurring.
`django-storages` does some stuff to abstract the layer but it can run into trouble. I looked into it a little the other day but don't have a solution yet. We might have to re-do how attachments are handled first.
I managed to fix it by changing the way how the file is opened, so I used this (in lib.py):
```
    if files:
        for filename, filefield in files:
            mime = mimetypes.guess_type(filename)
            if mime[0] is not None and mime[0] == "text/plain":
                filefield.open(mode='r')
                msg.attach(filename=filename, content=filefield.read())
                filefield.close()
            else:
                if six.PY3:
                    msg.attach_file(filefield.path)
                else:
                    filefield.open(mode='rb')
                    msg.attach(filename=filename, content=filefield.read())
                    filefield.close()
```
What is basically a copy paste of this 4c901880bca5b4e8cd4b3aa68fb86133e622c375.
I didn't do a pull request, because I don't know how to properly test this.

Resolving patch:
diff --git a/helpdesk/templated_email.py b/helpdesk/templated_email.py
--- a/helpdesk/templated_email.py
+++ b/helpdesk/templated_email.py
@@ -100,13 +100,10 @@ def send_templated_mail(template_name,
 
     if files:
         for filename, filefield in files:
-            mime = mimetypes.guess_type(filename)
-            if mime[0] is not None and mime[0] == "text/plain":
-                with open(filefield.path, 'r') as attachedfile:
-                    content = attachedfile.read()
-                    msg.attach(filename, content)
-            else:
-                msg.attach_file(filefield.path)
+            filefield.open('rb')
+            content = filefield.read()
+            msg.attach(filename, content)
+            filefield.close()
     logger.debug('Sending email to: {!r}'.format(recipients))
 
     try:


Test patch: