From bd0185bb6e66fd1c41c2062544d5738f7a30a4fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Tue, 12 Apr 2016 13:32:27 +0200 Subject: [PATCH] mail: make it possible to specify a category when feeding mails --- .../mail/management/commands/feed_mail.py | 10 +++++++++- .../migrations/0009_mail_scanner_category.py | 19 +++++++++++++++++++ welco/sources/mail/models.py | 2 ++ 3 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 welco/sources/mail/migrations/0009_mail_scanner_category.py diff --git a/welco/sources/mail/management/commands/feed_mail.py b/welco/sources/mail/management/commands/feed_mail.py index d7f134e..64568aa 100644 --- a/welco/sources/mail/management/commands/feed_mail.py +++ b/welco/sources/mail/management/commands/feed_mail.py @@ -14,6 +14,7 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . +from optparse import make_option import os from django.core.files import File @@ -22,7 +23,13 @@ from django.core.management.base import BaseCommand, CommandError from ...models import Mail class Command(BaseCommand): - args = ['...'] + args = ['category', '...'] + + option_list = BaseCommand.option_list + ( + make_option('--category', + dest='category', + default=None), + ) def handle(self, *args, **kwargs): count = 0 @@ -30,6 +37,7 @@ class Command(BaseCommand): if not os.path.exists(filepath): continue mail = Mail(content=File(open(filepath))) + mail.scanner_category = kwargs.get('category') mail.save() count += 1 if count == 0: diff --git a/welco/sources/mail/migrations/0009_mail_scanner_category.py b/welco/sources/mail/migrations/0009_mail_scanner_category.py new file mode 100644 index 0000000..e41d8e3 --- /dev/null +++ b/welco/sources/mail/migrations/0009_mail_scanner_category.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('mail', '0008_remove_mail_mail_number'), + ] + + operations = [ + migrations.AddField( + model_name='mail', + name='scanner_category', + field=models.CharField(max_length=100, null=True, blank=True), + ), + ] diff --git a/welco/sources/mail/models.py b/welco/sources/mail/models.py index bcb7837..3b58da3 100644 --- a/welco/sources/mail/models.py +++ b/welco/sources/mail/models.py @@ -40,6 +40,8 @@ class Mail(models.Model): null=True, max_length=50) note = models.TextField(_('Note'), null=True) + scanner_category = models.CharField(max_length=100, blank=True, null=True) + # common to all source types: status = models.CharField(_('Status'), blank=True, max_length=50) contact_id = models.CharField(max_length=50, null=True)