diff options
author | René 'Necoro' Neumann <necoro@necoro.net> | 2017-03-12 15:39:32 +0100 |
---|---|---|
committer | René 'Necoro' Neumann <necoro@necoro.net> | 2017-03-12 15:39:32 +0100 |
commit | 909f202136fd2f235b923ea2a9c480106d92f517 (patch) | |
tree | 537f05a7849ead22d38c56ffda41d49ac0febd96 /archivist/cli.py | |
parent | e0ad97c128fd31ea316f80ab17bda380c8c0f80a (diff) | |
download | archivist-909f202136fd2f235b923ea2a9c480106d92f517.tar.gz archivist-909f202136fd2f235b923ea2a9c480106d92f517.tar.bz2 archivist-909f202136fd2f235b923ea2a9c480106d92f517.zip |
Split document content into its own table to avoid having to load it each time. Move document creation into the model
Diffstat (limited to '')
-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) |