Add CurpusFile result relation to Corpus

This commit is contained in:
Stephan Porada 2019-10-23 11:22:29 +02:00
parent 488baf0b67
commit afac42464a
2 changed files with 12 additions and 1 deletions

View File

@ -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'))

View File

@ -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'))