Skip to content

Commit 2824cde

Browse files
Ilya TleukenovIlya Tleukenov
Ilya Tleukenov
authored and
Ilya Tleukenov
committed
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
1 parent 6004a22 commit 2824cde

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

django_mailbox/models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ class Message(models.Model):
512512
eml = models.FileField(
513513
_('Raw message contents'),
514514
null=True,
515-
upload_to="messages",
515+
upload_to=utils.get_save_path(setting='message_upload_to'),
516516
help_text=_('Original full content of message')
517517
)
518518
objects = models.Manager()
@@ -752,7 +752,7 @@ class MessageAttachment(models.Model):
752752

753753
document = models.FileField(
754754
_('Document'),
755-
upload_to=utils.get_attachment_save_path,
755+
upload_to=utils.get_save_path(setting='attachment_upload_to'),
756756
)
757757

758758
def delete(self, *args, **kwargs):

django_mailbox/utils.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,13 @@ def get_settings():
6666
settings,
6767
'DJANGO_MAILBOX_default_charset',
6868
'iso8859-1',
69+
),
70+
'message_upload_to': getattr(
71+
settings,
72+
'DJANGO_MAILBOX_MESSAGE_UPLOAD_TO',
73+
'messages/'
6974
)
75+
7076
}
7177

7278

@@ -138,14 +144,14 @@ def get_body_from_message(message, maintype, subtype):
138144
return body
139145

140146

141-
def get_attachment_save_path(instance, filename):
147+
def get_save_path(instance, filename, setting):
142148
settings = get_settings()
143149

144-
path = settings['attachment_upload_to']
150+
path = settings[setting]
145151
if '%' in path:
146152
path = datetime.datetime.utcnow().strftime(path)
147153

148154
return os.path.join(
149155
path,
150156
filename,
151-
)
157+
)

docs/topics/appendix/settings.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,9 @@ Settings
8080
* Default: ``False``
8181
* Type: ``boolean``
8282
* Controls whether or not we store original messages in ``eml`` field
83+
84+
* ``DJANGO_MAILBOX_MESSAGE_UPLOAD_TO``
85+
86+
* Default: ``messages/``
87+
* Type: ``string``
88+
* Original message will be saved to this location.

0 commit comments

Comments
 (0)