Add corpus to database after creation.

This commit is contained in:
Patrick Jentsch 2019-08-06 13:25:27 +02:00
parent 4ec0acc080
commit 5a67164dbe
2 changed files with 9 additions and 6 deletions

View File

@ -1,11 +1,12 @@
from datetime import datetime
from flask import current_app, flash, redirect, render_template, url_for
from flask_login import current_user, login_required
from ..models import User
from ..models import User, Corpus
from ..tables import AdminUserTable, AdminUserItem
from . import main
from .forms import CreateCorpusForm
from ..decorators import admin_required
from .. import db
import hashlib
import os
@ -27,15 +28,17 @@ def dashboard():
if create_corpus_form.validate_on_submit():
app = current_app._get_current_object()
id = hashlib.md5(
(current_user.username + '_' + datetime.now().isoformat()).encode()
).hexdigest()
corpus = {'description': create_corpus_form.description.data,
'id': id,
'creator': current_user.id,
'title': create_corpus_form.title.data
}
dir = os.path.join(app.config['OPAQUE_FILES'], 'corpora', id)
corpus = Corpus(description=create_corpus_form.description.data,
title=create_corpus_form.title.data,
user_id=current_user.id)
db.session.add(corpus)
db.session.commit()
dir = os.path.join(app.config['OPAQUE_STORAGE'], 'corpora', str(corpus.id))
try:
os.makedirs(dir)

View File

@ -260,7 +260,7 @@ class Corpus(db.Model):
user_id = db.Column(db.Integer, db.ForeignKey('users.id'))
def __init__(self, **kwargs):
super(Job, self).__init__(**kwargs)
super(Corpus, self).__init__(**kwargs)
def __repr__(self):
"""