diff options
Diffstat (limited to 'archivist/cli.py')
-rw-r--r-- | archivist/cli.py | 14 |
1 files changed, 4 insertions, 10 deletions
diff --git a/archivist/cli.py b/archivist/cli.py index b10e11b..31646aa 100644 --- a/archivist/cli.py +++ b/archivist/cli.py @@ -237,8 +237,10 @@ def doc(): def add_doc(file, tags, create_tags, ignore_missing_tags): """Add a new document together with the given tags.""" - from .model import Document, Tag, db, DocumentTag + from .model import db, Document + import magic + mimetype = magic.from_file(file.name, mime=True) with db.atomic(): if tags: @@ -247,15 +249,7 @@ def add_doc(file, tags, create_tags, ignore_missing_tags): else: tags = fetch_tags(tags, ignore_missing_tags) - mimetype = magic.from_file(file.name, mime=True) - - doc = Document.create(content = file.read(), - file_type = mimetype, - original_path = file.name, - direction = Document.Direction.IN) - - for t in tags: - DocumentTag.create(document = doc, tag = t) + Document.create_from_file(file, tags, direction = Document.Direction.IN, file_type = mimetype) @doc.command('find') @click.argument('tags', type=TAG, nargs=-1) |