From 1a040871590142bec96225c7450bdbe496995b6b Mon Sep 17 00:00:00 2001 From: eupharis Date: Mon, 22 Jun 2015 17:07:51 -0600 Subject: [PATCH] add DJANGO_MAILBOX_ATTACHMENT_UPLOAD_TO setting --- django_mailbox/models.py | 8 +++++++- django_mailbox/runtests.py | 0 django_mailbox/tests/__init__.py | 1 + django_mailbox/tests/test_settings.py | 10 ++++++++++ docs/topics/appendix/settings.rst | 10 +++++++++- 5 files changed, 27 insertions(+), 2 deletions(-) mode change 100644 => 100755 django_mailbox/runtests.py create mode 100644 django_mailbox/tests/test_settings.py diff --git a/django_mailbox/models.py b/django_mailbox/models.py index 23d5c04..0ef088b 100644 --- a/django_mailbox/models.py +++ b/django_mailbox/models.py @@ -71,6 +71,12 @@ ATTACHMENT_INTERPOLATION_HEADER = getattr( 'X-Django-Mailbox-Interpolate-Attachment' ) +ATTACHMENT_UPLOAD_TO = getattr( + settings, + 'DJANGO_MAILBOX_ATTACHMENT_UPLOAD_TO', + 'mailbox_attachments/%Y/%m/%d/' +) + STORE_ORIGINAL_MESSAGE = getattr( settings, 'DJANGO_MAILBOX_STORE_ORIGINAL_MESSAGE', @@ -717,7 +723,7 @@ class MessageAttachment(models.Model): document = models.FileField( _(u'Document'), - upload_to='mailbox_attachments/%Y/%m/%d/' + upload_to=ATTACHMENT_UPLOAD_TO, ) def delete(self, *args, **kwargs): diff --git a/django_mailbox/runtests.py b/django_mailbox/runtests.py old mode 100644 new mode 100755 diff --git a/django_mailbox/tests/__init__.py b/django_mailbox/tests/__init__.py index 4d393ed..e30b827 100644 --- a/django_mailbox/tests/__init__.py +++ b/django_mailbox/tests/__init__.py @@ -3,3 +3,4 @@ from .test_message_flattening import * from .test_process_email import * from .test_transports import * from .test_integration_imap import * +from .test_settings import * diff --git a/django_mailbox/tests/test_settings.py b/django_mailbox/tests/test_settings.py new file mode 100644 index 0000000..c183cf2 --- /dev/null +++ b/django_mailbox/tests/test_settings.py @@ -0,0 +1,10 @@ +from django.test import TestCase +from django.conf import settings +from django_mailbox.models import ATTACHMENT_UPLOAD_TO + + +class TestSettings(TestCase): + def test_default_attachment_upload_to(self): + user_setting = getattr(settings, 'DJANGO_MAILBOX_ATTACHMENT_UPLOAD_TO', False) + self.assertFalse(user_setting) + self.assertEqual(ATTACHMENT_UPLOAD_TO, 'mailbox_attachments/%Y/%m/%d/') diff --git a/docs/topics/appendix/settings.rst b/docs/topics/appendix/settings.rst index 13fdde6..4a412ec 100644 --- a/docs/topics/appendix/settings.rst +++ b/docs/topics/appendix/settings.rst @@ -12,7 +12,7 @@ Settings * Default: ``False`` * Type: ``boolean`` - * Controls whether or not we remove mimetypes not specified in + * Controls whether or not we remove mimetypes not specified in ``DJANGO_MAILBOX_PRESERVED_MIMETYPES`` from the message prior to storage. * ``DJANGO_MAILBOX_ALLOWED_MIMETYPES`` @@ -59,6 +59,14 @@ Settings this field is the primary key of the ``django_mailbox.MessageAttachment`` instance currently storing this payload component's contents. +* ``DJANGO_MAILBOX_ATTACHMENT_UPLOAD_TO`` + + * Default: ``mailbox_attachments/%Y/%m/%d/`` + * Type: ``string`` + * Attachments will be saved to this location. Specifies the ``upload_to`` setting + for the attachment FileField. For more on FileFields and upload_to, see the + `Django docs `__ + * ``DJANGO_MAILBOX_MAX_MESSAGE_SIZE`` * Default: ``False``