mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-12-24 10:34:17 +00:00
Add corpus to database after creation.
This commit is contained in:
parent
4ec0acc080
commit
5a67164dbe
@ -1,11 +1,12 @@
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from flask import current_app, flash, redirect, render_template, url_for
|
from flask import current_app, flash, redirect, render_template, url_for
|
||||||
from flask_login import current_user, login_required
|
from flask_login import current_user, login_required
|
||||||
from ..models import User
|
from ..models import User, Corpus
|
||||||
from ..tables import AdminUserTable, AdminUserItem
|
from ..tables import AdminUserTable, AdminUserItem
|
||||||
from . import main
|
from . import main
|
||||||
from .forms import CreateCorpusForm
|
from .forms import CreateCorpusForm
|
||||||
from ..decorators import admin_required
|
from ..decorators import admin_required
|
||||||
|
from .. import db
|
||||||
import hashlib
|
import hashlib
|
||||||
import os
|
import os
|
||||||
|
|
||||||
@ -27,15 +28,17 @@ def dashboard():
|
|||||||
|
|
||||||
if create_corpus_form.validate_on_submit():
|
if create_corpus_form.validate_on_submit():
|
||||||
app = current_app._get_current_object()
|
app = current_app._get_current_object()
|
||||||
id = hashlib.md5(
|
|
||||||
(current_user.username + '_' + datetime.now().isoformat()).encode()
|
|
||||||
).hexdigest()
|
|
||||||
corpus = {'description': create_corpus_form.description.data,
|
corpus = {'description': create_corpus_form.description.data,
|
||||||
'id': id,
|
'id': id,
|
||||||
'creator': current_user.id,
|
'creator': current_user.id,
|
||||||
'title': create_corpus_form.title.data
|
'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:
|
try:
|
||||||
os.makedirs(dir)
|
os.makedirs(dir)
|
||||||
|
@ -260,7 +260,7 @@ class Corpus(db.Model):
|
|||||||
user_id = db.Column(db.Integer, db.ForeignKey('users.id'))
|
user_id = db.Column(db.Integer, db.ForeignKey('users.id'))
|
||||||
|
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
super(Job, self).__init__(**kwargs)
|
super(Corpus, self).__init__(**kwargs)
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
"""
|
"""
|
||||||
|
Loading…
Reference in New Issue
Block a user