1
0
Fork 1
mirror of https://github.com/coddingtonbear/django-mailbox.git synced 2026-07-09 22:38:19 +02:00

add DJANGO_MAILBOX_MESSAGE_UPLOAD_TO to settings, change utils.get_attachment_save_path to utils.get_save_path, change eml upload_to in model

This commit is contained in:
Ilya Tleukenov 2020-01-31 13:31:04 +07:00
parent 6004a2286f
commit 2824cde5e9
3 changed files with 17 additions and 5 deletions

View file

@ -512,7 +512,7 @@ class Message(models.Model):
eml = models.FileField(
_('Raw message contents'),
null=True,
upload_to="messages",
upload_to=utils.get_save_path(setting='message_upload_to'),
help_text=_('Original full content of message')
)
objects = models.Manager()
@ -752,7 +752,7 @@ class MessageAttachment(models.Model):
document = models.FileField(
_('Document'),
upload_to=utils.get_attachment_save_path,
upload_to=utils.get_save_path(setting='attachment_upload_to'),
)
def delete(self, *args, **kwargs):

View file

@ -66,7 +66,13 @@ def get_settings():
settings,
'DJANGO_MAILBOX_default_charset',
'iso8859-1',
),
'message_upload_to': getattr(
settings,
'DJANGO_MAILBOX_MESSAGE_UPLOAD_TO',
'messages/'
)
}
@ -138,14 +144,14 @@ def get_body_from_message(message, maintype, subtype):
return body
def get_attachment_save_path(instance, filename):
def get_save_path(instance, filename, setting):
settings = get_settings()
path = settings['attachment_upload_to']
path = settings[setting]
if '%' in path:
path = datetime.datetime.utcnow().strftime(path)
return os.path.join(
path,
filename,
)
)

View file

@ -80,3 +80,9 @@ Settings
* Default: ``False``
* Type: ``boolean``
* Controls whether or not we store original messages in ``eml`` field
* ``DJANGO_MAILBOX_MESSAGE_UPLOAD_TO``
* Default: ``messages/``
* Type: ``string``
* Original message will be saved to this location.