mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-11-15 01:05:42 +00:00
prepare vrt file in background thread.
This commit is contained in:
parent
69387ee183
commit
29183b8763
@ -1,3 +1,4 @@
|
||||
from app.utils import background_prepare_corpus_file
|
||||
from flask import (abort, current_app, flash, redirect, request,
|
||||
render_template, url_for, send_from_directory)
|
||||
from flask_login import current_user, login_required
|
||||
@ -115,6 +116,11 @@ def add_corpus_file(corpus_id):
|
||||
title=add_corpus_file_form.title.data)
|
||||
db.session.add(corpus_file)
|
||||
db.session.commit()
|
||||
background_thread = threading.Thread(
|
||||
args=(current_app._get_current_object(), corpus_file.id),
|
||||
target=background_prepare_corpus_file
|
||||
)
|
||||
background_thread.start()
|
||||
flash('Corpus file added!')
|
||||
return redirect(url_for('corpora.corpus', corpus_id=corpus_id))
|
||||
return render_template('corpora/add_corpus_file.html.j2',
|
||||
|
@ -24,7 +24,8 @@ def delete_job(job_id):
|
||||
if not (job.creator == current_user or current_user.is_administrator()):
|
||||
abort(403)
|
||||
delete_thread = threading.Thread(target=background_delete_job,
|
||||
args=(current_app, job_id))
|
||||
args=(current_app._get_current_object(),
|
||||
job_id))
|
||||
delete_thread.start()
|
||||
flash('Job has been deleted!')
|
||||
return redirect(url_for('main.dashboard'))
|
||||
|
@ -1,14 +1,14 @@
|
||||
from datetime import datetime
|
||||
from flask import current_app
|
||||
from flask_login import UserMixin, AnonymousUserMixin
|
||||
from itsdangerous import BadSignature, TimedJSONWebSignatureSerializer
|
||||
from werkzeug.security import generate_password_hash, check_password_hash
|
||||
import xml.etree.ElementTree as ET
|
||||
from . import db
|
||||
from . import login_manager
|
||||
from datetime import datetime
|
||||
import os
|
||||
import shutil
|
||||
import logging
|
||||
import xml.etree.ElementTree as ET
|
||||
|
||||
|
||||
class Permission:
|
||||
@ -411,18 +411,6 @@ class CorpusFile(db.Model):
|
||||
title = db.Column(db.String(64))
|
||||
corpus_id = db.Column(db.Integer, db.ForeignKey('corpora.id'))
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
super(CorpusFile, self).__init__(**kwargs)
|
||||
file = os.path.join(current_app.config['OPAQUE_STORAGE_DIRECTORY'],
|
||||
self.dir,
|
||||
self.filename)
|
||||
element_tree = ET.parse(file)
|
||||
text_node = element_tree.find('text')
|
||||
text_node.set('author', self.author)
|
||||
text_node.set('publishing_year', str(self.publishing_year))
|
||||
text_node.set('title', self.title)
|
||||
element_tree.write(file)
|
||||
|
||||
def delete(self):
|
||||
logger = logging.getLogger(__name__)
|
||||
logger.warning('Called CorpusFile.delete')
|
||||
@ -437,6 +425,17 @@ class CorpusFile(db.Model):
|
||||
db.session.delete(self)
|
||||
db.session.commit()
|
||||
|
||||
def insert_metadata(self):
|
||||
file = os.path.join(current_app.config['OPAQUE_STORAGE_DIRECTORY'],
|
||||
self.dir,
|
||||
self.filename)
|
||||
element_tree = ET.parse(file)
|
||||
text_node = element_tree.find('text')
|
||||
text_node.set('author', self.author)
|
||||
text_node.set('publishing_year', str(self.publishing_year))
|
||||
text_node.set('title', self.title)
|
||||
element_tree.write(file)
|
||||
|
||||
|
||||
class Corpus(db.Model):
|
||||
"""
|
||||
|
@ -1,5 +1,5 @@
|
||||
from .models import Job, User, Corpus, CorpusFile
|
||||
from . import db
|
||||
from .models import Job, User, Corpus, CorpusFile
|
||||
import logging
|
||||
|
||||
|
||||
@ -69,3 +69,4 @@ def background_delete_corpus(app, corpus_id):
|
||||
def background_prepare_corpus_file(app, corpus_file_id):
|
||||
with app.app_context():
|
||||
corpus_file = CorpusFile.query.filter_by(id=corpus_file_id).first()
|
||||
corpus_file.insert_metadata()
|
||||
|
Loading…
Reference in New Issue
Block a user