Add the option to enable or disable parsing when uploading a document for each document type. Add a new setting option to enable automatic parsing for each new document type created.

Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
This commit is contained in:
Roberto Rosario
2018-04-10 04:02:41 -04:00
parent 74628ab04b
commit b5d79f42a9
13 changed files with 199 additions and 15 deletions

View File

@@ -0,0 +1,55 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.11 on 2018-04-10 06:39
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
def create_parsing_setting_for_existing_document_types(apps, schema_editor):
DocumentType = apps.get_model('documents', 'DocumentType')
DocumentTypeSettings = apps.get_model('document_parsing', 'DocumentTypeSettings')
for document_type in DocumentType.objects.all():
try:
DocumentTypeSettings.objects.create(document_type=document_type)
except DocumentTypeSettings.DoesNotExist:
pass
def delete_parsing_setting_for_existing_document_types(apps, schema_editor):
DocumentType = apps.get_model('documents', 'DocumentType')
DocumentTypeSettings = apps.get_model('document_parsing', 'DocumentTypeSettings')
for document_type in DocumentType.objects.all():
try:
DocumentTypeSettings.objects.get(document_type=document_type).delete()
except DocumentTypeSettings.DoesNotExist:
pass
class Migration(migrations.Migration):
dependencies = [
('documents', '0042_auto_20180403_0702'),
('document_parsing', '0002_auto_20170827_1617'),
]
operations = [
migrations.CreateModel(
name='DocumentTypeSettings',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('auto_parsing', models.BooleanField(default=True, verbose_name='Automatically queue newly created documents for parsing.')),
('document_type', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='parsing_settings', to='documents.DocumentType', verbose_name='Document type')),
],
options={
'verbose_name': 'Document type settings',
'verbose_name_plural': 'Document types settings',
},
),
migrations.RunPython(
code=create_parsing_setting_for_existing_document_types,
reverse_code=delete_parsing_setting_for_existing_document_types,
)
]