mail: make it possible to specify a category when feeding mails

This commit is contained in:
Frédéric Péters 2016-04-12 13:32:27 +02:00
parent 95714fe50d
commit bd0185bb6e
3 changed files with 30 additions and 1 deletions

View File

@ -14,6 +14,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
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:

View File

@ -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),
),
]

View File

@ -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)