From afac42464a32323f522452f801ccf060771bec6e Mon Sep 17 00:00:00 2001 From: Stephan Porada Date: Wed, 23 Oct 2019 11:22:29 +0200 Subject: [PATCH] Add CurpusFile result relation to Corpus --- app/main/views.py | 10 +++++++++- app/models.py | 3 +++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/app/main/views.py b/app/main/views.py index 3650e31f..52dce8d4 100644 --- a/app/main/views.py +++ b/app/main/views.py @@ -5,7 +5,7 @@ from flask_login import current_user, login_required from . import main from .forms import CreateCorpusForm from .. import db -from ..models import Corpus, Job +from ..models import Corpus, CorpusFile, Job import os import threading @@ -86,6 +86,14 @@ def dashboard(): else: for file in create_corpus_form.files.data: file.save(os.path.join(dir, file.filename)) + dir = os.path.join(str(corpus.user_id), + 'corpora', + str(corpus.id)) + corpus_file = CorpusFile(filename=file.filename, + corpus_id=corpus.id, + dir=dir) + db.session.add(corpus_file) + db.session.commit() flash('Corpus created!') return redirect(url_for('main.dashboard')) diff --git a/app/models.py b/app/models.py index 7a2fe19b..cc143f8b 100644 --- a/app/models.py +++ b/app/models.py @@ -258,6 +258,7 @@ class JobInput(db.Model): # Primary key id = db.Column(db.Integer, primary_key=True) filename = db.Column(db.String(255)) + dir = db.Column(db.String(255)) job_id = db.Column(db.Integer, db.ForeignKey('jobs.id')) # Relationships results = db.relationship('JobResult', @@ -285,6 +286,7 @@ class JobResult(db.Model): # Primary key id = db.Column(db.Integer, primary_key=True) filename = db.Column(db.String(255)) + dir = db.Column(db.String(255)) job_id = db.Column(db.Integer, db.ForeignKey('jobs.id')) job_input_id = db.Column(db.Integer, db.ForeignKey('job_inputs.id')) @@ -398,6 +400,7 @@ class CorpusFile(db.Model): # Primary key id = db.Column(db.Integer, primary_key=True) filename = db.Column(db.String(255)) + dir = db.Column(db.String(255)) corpus_id = db.Column(db.Integer, db.ForeignKey('corpora.id'))