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

fix valuerror of wrapper in get_save_path

This commit is contained in:
rokfordchez 2020-02-08 22:57:45 +07:00
parent 02acef8ede
commit 804d91f2ad
4 changed files with 50 additions and 28 deletions

View file

@ -1,9 +1,9 @@
from django.db import migrations, models
from functools import partial
import django_mailbox.utils
class Migration(migrations.Migration):
dependencies = [
('django_mailbox', '0004_bytestring_to_unicode'),
]
@ -12,6 +12,8 @@ class Migration(migrations.Migration):
migrations.AlterField(
model_name='messageattachment',
name='document',
field=models.FileField(upload_to=django_mailbox.utils.get_save_path(setting='attachment_upload_to'), verbose_name='Document'),
field=models.FileField(
upload_to=partial(django_mailbox.utils.get_save_path, setting='attachment_upload_to'),
verbose_name='Document'),
),
]

View file

@ -0,0 +1,20 @@
# Generated by Django 2.2.4 on 2020-02-08 09:53
from django.db import migrations, models
import django_mailbox.utils
import functools
class Migration(migrations.Migration):
dependencies = [
('django_mailbox', '0008_auto_20190219_1553'),
]
operations = [
migrations.AlterField(
model_name='message',
name='eml',
field=models.FileField(help_text='Original full content of message', null=True, upload_to=functools.partial(django_mailbox.utils.get_save_path, *(), **{'setting': 'message_upload_to'}), verbose_name='Raw message contents'),
),
]

View file

@ -10,6 +10,7 @@ from email.utils import formatdate, parseaddr
from urllib.parse import parse_qs, unquote, urlparse
from quopri import encode as encode_quopri
from io import BytesIO
from functools import partial
import base64
import email
import logging
@ -368,7 +369,7 @@ class Mailbox(models.Model):
except KeyError as exc:
# email.message.replace_header may raise 'KeyError' if the header
# 'content-transfer-encoding' is missing
logger.warning("Failed to parse message: %s", exc,)
logger.warning("Failed to parse message: %s", exc, )
return None
msg.set_body(body)
if message['in-reply-to']:
@ -512,7 +513,7 @@ class Message(models.Model):
eml = models.FileField(
_('Raw message contents'),
null=True,
upload_to=utils.get_save_path(setting='message_upload_to'),
upload_to=partial(utils.get_save_path, setting='message_upload_to'),
help_text=_('Original full content of message')
)
objects = models.Manager()
@ -752,7 +753,7 @@ class MessageAttachment(models.Model):
document = models.FileField(
_('Document'),
upload_to=utils.get_save_path(setting='attachment_upload_to'),
upload_to=partial(utils.get_save_path, setting='attachment_upload_to'),
)
def delete(self, *args, **kwargs):

View file

@ -3,6 +3,7 @@ import email.header
import logging
import os
from django.utils.deconstruct import deconstructible
from django.conf import settings
logger = logging.getLogger(__name__)
@ -143,8 +144,7 @@ def get_body_from_message(message, maintype, subtype):
return body
def get_save_path(setting):
def _tmp(instance, filename):
def get_save_path(instance, filename, setting):
settings = get_settings()
path = settings[setting]
@ -155,4 +155,3 @@ def get_save_path(setting):
path,
filename,
)
return _tmp