Skip to content
This repository has been archived by the owner on Feb 16, 2023. It is now read-only.

Commit

Permalink
added migration step to create initial classifier, silences consumpti…
Browse files Browse the repository at this point in the history
…on warnings
  • Loading branch information
Jonas Winkler committed Nov 3, 2020
1 parent 28ba634 commit ebac10b
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/documents/migrations/1000_update_paperless.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,21 @@ def restore_filenames(apps, schema_editor):
pass


def initialize_document_classifier(apps, schema_editor):
try:
print("Initalizing document classifier...")
from documents.classifier import DocumentClassifier
classifier = DocumentClassifier()
try:
classifier.train()
classifier.save_classifier()
except Exception as e:
print("Classifier error: {}".format(e))
except ImportError:
print("Document classifier not found, skipping")



class Migration(migrations.Migration):

dependencies = [
Expand All @@ -50,6 +65,7 @@ class Migration(migrations.Migration):
operations = [
migrations.RunPython(make_index, migrations.RunPython.noop),
migrations.RunPython(restore_filenames),
migrations.RunPython(initialize_document_classifier, migrations.RunPython.noop),
migrations.RemoveField(
model_name='document',
name='filename',
Expand Down

0 comments on commit ebac10b

Please sign in to comment.