mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-12-25 10:54:18 +00:00
Make models in package work
This commit is contained in:
parent
a1e5bd61e0
commit
55a62053b0
@ -22,6 +22,8 @@ db = SQLAlchemy()
|
|||||||
docker_client = DockerClient()
|
docker_client = DockerClient()
|
||||||
hashids = Hashids()
|
hashids = Hashids()
|
||||||
login = LoginManager()
|
login = LoginManager()
|
||||||
|
login.login_view = 'auth.login'
|
||||||
|
login.login_message = 'Please log in to access this page.'
|
||||||
ma = Marshmallow()
|
ma = Marshmallow()
|
||||||
mail = Mail()
|
mail = Mail()
|
||||||
migrate = Migrate(compare_type=True)
|
migrate = Migrate(compare_type=True)
|
||||||
@ -55,6 +57,9 @@ def create_app(config: Config = Config) -> Flask:
|
|||||||
scheduler.init_app(app)
|
scheduler.init_app(app)
|
||||||
socketio.init_app(app, message_queue=app.config['NOPAQUE_SOCKETIO_MESSAGE_QUEUE_URI']) # noqa
|
socketio.init_app(app, message_queue=app.config['NOPAQUE_SOCKETIO_MESSAGE_QUEUE_URI']) # noqa
|
||||||
|
|
||||||
|
from .models.event_listeners import register_event_listeners
|
||||||
|
register_event_listeners()
|
||||||
|
|
||||||
from .admin import bp as admin_blueprint
|
from .admin import bp as admin_blueprint
|
||||||
default_breadcrumb_root(admin_blueprint, '.admin')
|
default_breadcrumb_root(admin_blueprint, '.admin')
|
||||||
app.register_blueprint(admin_blueprint, url_prefix='/admin')
|
app.register_blueprint(admin_blueprint, url_prefix='/admin')
|
||||||
@ -102,11 +107,4 @@ def create_app(config: Config = Config) -> Flask:
|
|||||||
from .workshops import bp as workshops_blueprint
|
from .workshops import bp as workshops_blueprint
|
||||||
app.register_blueprint(workshops_blueprint, url_prefix='/workshops')
|
app.register_blueprint(workshops_blueprint, url_prefix='/workshops')
|
||||||
|
|
||||||
login.login_view = 'auth.login'
|
|
||||||
login.login_message = 'Please log in to access this page.'
|
|
||||||
from .models.user import User
|
|
||||||
@login.user_loader
|
|
||||||
def load_user(user_id):
|
|
||||||
return User.query.get(int(user_id))
|
|
||||||
|
|
||||||
return app
|
return app
|
||||||
|
1819
app/models.py
1819
app/models.py
File diff suppressed because it is too large
Load Diff
@ -1,2 +1,18 @@
|
|||||||
from .avatar import Avatar
|
from .avatar import *
|
||||||
from .corpus_file import CorpusFile
|
from .corpus_file import *
|
||||||
|
from .corpus_follower_association import *
|
||||||
|
from .corpus_follower_role import *
|
||||||
|
from .corpus import *
|
||||||
|
from .job_input import *
|
||||||
|
from .job_result import *
|
||||||
|
from .job import *
|
||||||
|
from .role import *
|
||||||
|
from .spacy_nlp_pipeline_model import *
|
||||||
|
from .tesseract_ocr_pipeline_model import *
|
||||||
|
from .token import *
|
||||||
|
from .user import *
|
||||||
|
|
||||||
|
|
||||||
|
@login.user_loader
|
||||||
|
def load_user(user_id):
|
||||||
|
return User.query.get(int(user_id))
|
||||||
|
@ -2,24 +2,39 @@ from datetime import datetime
|
|||||||
from enum import Enum
|
from enum import Enum
|
||||||
from app import db, mail, socketio
|
from app import db, mail, socketio
|
||||||
from app.email import create_message
|
from app.email import create_message
|
||||||
from .corpus import Corpus
|
|
||||||
from .corpus_file import CorpusFile
|
from .corpus_file import CorpusFile
|
||||||
from .corpus_follower_association import CorpusFollowerAssociation
|
from .corpus_follower_association import CorpusFollowerAssociation
|
||||||
from .job import Job, JobStatus
|
from .corpus import Corpus
|
||||||
from .job_input import JobInput
|
from .job_input import JobInput
|
||||||
from .job_result import JobResult
|
from .job_result import JobResult
|
||||||
|
from .job import Job, JobStatus
|
||||||
from .spacy_nlp_pipeline_model import SpaCyNLPPipelineModel
|
from .spacy_nlp_pipeline_model import SpaCyNLPPipelineModel
|
||||||
from .tesseract_ocr_pipeline_model import TesseractOCRPipelineModel
|
from .tesseract_ocr_pipeline_model import TesseractOCRPipelineModel
|
||||||
from .user import UserSettingJobStatusMailNotificationLevel
|
from .user import UserSettingJobStatusMailNotificationLevel
|
||||||
|
|
||||||
|
|
||||||
@db.event.listens_for(Corpus, 'after_delete')
|
def register_event_listeners():
|
||||||
@db.event.listens_for(CorpusFile, 'after_delete')
|
resources = [
|
||||||
@db.event.listens_for(Job, 'after_delete')
|
Corpus,
|
||||||
@db.event.listens_for(JobInput, 'after_delete')
|
CorpusFile,
|
||||||
@db.event.listens_for(JobResult, 'after_delete')
|
Job,
|
||||||
@db.event.listens_for(SpaCyNLPPipelineModel, 'after_delete')
|
JobInput,
|
||||||
@db.event.listens_for(TesseractOCRPipelineModel, 'after_delete')
|
JobResult,
|
||||||
|
SpaCyNLPPipelineModel,
|
||||||
|
TesseractOCRPipelineModel
|
||||||
|
]
|
||||||
|
|
||||||
|
for resource in resources:
|
||||||
|
db.event.listen(resource, 'after_delete', resource_after_delete)
|
||||||
|
db.event.listen(resource, 'after_insert', resource_after_insert)
|
||||||
|
db.event.listen(resource, 'after_update', resource_after_update)
|
||||||
|
|
||||||
|
db.event.listen(CorpusFollowerAssociation, 'after_delete', cfa_after_delete)
|
||||||
|
db.event.listen(CorpusFollowerAssociation, 'after_insert', cfa_after_insert)
|
||||||
|
|
||||||
|
db.event.listen(Job, 'after_update', job_after_update)
|
||||||
|
|
||||||
|
|
||||||
def resource_after_delete(mapper, connection, resource):
|
def resource_after_delete(mapper, connection, resource):
|
||||||
jsonpatch = [
|
jsonpatch = [
|
||||||
{
|
{
|
||||||
@ -31,8 +46,7 @@ def resource_after_delete(mapper, connection, resource):
|
|||||||
socketio.emit('PATCH', jsonpatch, room=room)
|
socketio.emit('PATCH', jsonpatch, room=room)
|
||||||
|
|
||||||
|
|
||||||
@db.event.listens_for(CorpusFollowerAssociation, 'after_delete')
|
def cfa_after_delete(mapper, connection, cfa):
|
||||||
def cfa_after_delete_handler(mapper, connection, cfa):
|
|
||||||
jsonpatch_path = f'/users/{cfa.corpus.user.hashid}/corpora/{cfa.corpus.hashid}/corpus_follower_associations/{cfa.hashid}'
|
jsonpatch_path = f'/users/{cfa.corpus.user.hashid}/corpora/{cfa.corpus.hashid}/corpus_follower_associations/{cfa.hashid}'
|
||||||
jsonpatch = [
|
jsonpatch = [
|
||||||
{
|
{
|
||||||
@ -44,14 +58,7 @@ def cfa_after_delete_handler(mapper, connection, cfa):
|
|||||||
socketio.emit('PATCH', jsonpatch, room=room)
|
socketio.emit('PATCH', jsonpatch, room=room)
|
||||||
|
|
||||||
|
|
||||||
@db.event.listens_for(Corpus, 'after_insert')
|
def resource_after_insert(mapper, connection, resource):
|
||||||
@db.event.listens_for(CorpusFile, 'after_insert')
|
|
||||||
@db.event.listens_for(Job, 'after_insert')
|
|
||||||
@db.event.listens_for(JobInput, 'after_insert')
|
|
||||||
@db.event.listens_for(JobResult, 'after_insert')
|
|
||||||
@db.event.listens_for(SpaCyNLPPipelineModel, 'after_insert')
|
|
||||||
@db.event.listens_for(TesseractOCRPipelineModel, 'after_insert')
|
|
||||||
def resource_after_insert_handler(mapper, connection, resource):
|
|
||||||
jsonpatch_value = resource.to_json_serializeable()
|
jsonpatch_value = resource.to_json_serializeable()
|
||||||
for attr in mapper.relationships:
|
for attr in mapper.relationships:
|
||||||
jsonpatch_value[attr.key] = {}
|
jsonpatch_value[attr.key] = {}
|
||||||
@ -66,8 +73,7 @@ def resource_after_insert_handler(mapper, connection, resource):
|
|||||||
socketio.emit('PATCH', jsonpatch, room=room)
|
socketio.emit('PATCH', jsonpatch, room=room)
|
||||||
|
|
||||||
|
|
||||||
@db.event.listens_for(CorpusFollowerAssociation, 'after_insert')
|
def cfa_after_insert(mapper, connection, cfa):
|
||||||
def cfa_after_insert_handler(mapper, connection, cfa):
|
|
||||||
jsonpatch_value = cfa.to_json_serializeable()
|
jsonpatch_value = cfa.to_json_serializeable()
|
||||||
jsonpatch_path = f'/users/{cfa.corpus.user.hashid}/corpora/{cfa.corpus.hashid}/corpus_follower_associations/{cfa.hashid}'
|
jsonpatch_path = f'/users/{cfa.corpus.user.hashid}/corpora/{cfa.corpus.hashid}/corpus_follower_associations/{cfa.hashid}'
|
||||||
jsonpatch = [
|
jsonpatch = [
|
||||||
@ -81,14 +87,7 @@ def cfa_after_insert_handler(mapper, connection, cfa):
|
|||||||
socketio.emit('PATCH', jsonpatch, room=room)
|
socketio.emit('PATCH', jsonpatch, room=room)
|
||||||
|
|
||||||
|
|
||||||
@db.event.listens_for(Corpus, 'after_update')
|
def resource_after_update(mapper, connection, resource):
|
||||||
@db.event.listens_for(CorpusFile, 'after_update')
|
|
||||||
@db.event.listens_for(Job, 'after_update')
|
|
||||||
@db.event.listens_for(JobInput, 'after_update')
|
|
||||||
@db.event.listens_for(JobResult, 'after_update')
|
|
||||||
@db.event.listens_for(SpaCyNLPPipelineModel, 'after_update')
|
|
||||||
@db.event.listens_for(TesseractOCRPipelineModel, 'after_update')
|
|
||||||
def resource_after_update_handler(mapper, connection, resource):
|
|
||||||
jsonpatch = []
|
jsonpatch = []
|
||||||
for attr in db.inspect(resource).attrs:
|
for attr in db.inspect(resource).attrs:
|
||||||
if attr.key in mapper.relationships:
|
if attr.key in mapper.relationships:
|
||||||
@ -114,8 +113,7 @@ def resource_after_update_handler(mapper, connection, resource):
|
|||||||
socketio.emit('PATCH', jsonpatch, room=room)
|
socketio.emit('PATCH', jsonpatch, room=room)
|
||||||
|
|
||||||
|
|
||||||
@db.event.listens_for(Job, 'after_update')
|
def job_after_update(mapper, connection, job):
|
||||||
def job_after_update_handler(mapper, connection, job):
|
|
||||||
for attr in db.inspect(job).attrs:
|
for attr in db.inspect(job).attrs:
|
||||||
if attr.key != 'status':
|
if attr.key != 'status':
|
||||||
continue
|
continue
|
||||||
|
@ -59,7 +59,8 @@ class SpaCyNLPPipelineModel(FileMixin, HashidMixin, db.Model):
|
|||||||
nopaque_user = User.query.filter_by(username='nopaque').first()
|
nopaque_user = User.query.filter_by(username='nopaque').first()
|
||||||
defaults_file = os.path.join(
|
defaults_file = os.path.join(
|
||||||
os.path.dirname(os.path.abspath(__file__)),
|
os.path.dirname(os.path.abspath(__file__)),
|
||||||
'SpaCyNLPPipelineModel.defaults.yml'
|
'default_records',
|
||||||
|
'spacy_nlp_pipeline_model.yml'
|
||||||
)
|
)
|
||||||
with open(defaults_file, 'r') as f:
|
with open(defaults_file, 'r') as f:
|
||||||
defaults = yaml.safe_load(f)
|
defaults = yaml.safe_load(f)
|
||||||
|
@ -57,7 +57,8 @@ class TesseractOCRPipelineModel(FileMixin, HashidMixin, db.Model):
|
|||||||
nopaque_user = User.query.filter_by(username='nopaque').first()
|
nopaque_user = User.query.filter_by(username='nopaque').first()
|
||||||
defaults_file = os.path.join(
|
defaults_file = os.path.join(
|
||||||
os.path.dirname(os.path.abspath(__file__)),
|
os.path.dirname(os.path.abspath(__file__)),
|
||||||
'TesseractOCRPipelineModel.defaults.yml'
|
'default_records',
|
||||||
|
'tesseract_ocr_pipeline_model.yml'
|
||||||
)
|
)
|
||||||
with open(defaults_file, 'r') as f:
|
with open(defaults_file, 'r') as f:
|
||||||
defaults = yaml.safe_load(f)
|
defaults = yaml.safe_load(f)
|
||||||
|
Loading…
Reference in New Issue
Block a user