diff --git a/app/__init__.py b/app/__init__.py index 81766262..d9311c9a 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -1,6 +1,7 @@ from config import Config from flask import Flask from flask_apscheduler import APScheduler +from flask_assets import Environment from flask_login import LoginManager from flask_mail import Mail from flask_migrate import Migrate @@ -8,10 +9,9 @@ from flask_paranoid import Paranoid from flask_socketio import SocketIO from flask_sqlalchemy import SQLAlchemy from flask_hashids import Hashids -import flask_assets -assets: flask_assets.Environment = flask_assets.Environment() +assets: Environment = Environment() db: SQLAlchemy = SQLAlchemy() hashids: Hashids = Hashids() login: LoginManager = LoginManager() @@ -38,10 +38,7 @@ def create_app(config: Config = Config) -> Flask: mail.init_app(app) migrate.init_app(app, db) paranoid.init_app(app) - socketio.init_app( - app, - message_queue=app.config['NOPAQUE_SOCKETIO_MESSAGE_QUEUE_URI'] - ) + socketio.init_app(app, message_queue=app.config['NOPAQUE_SOCKETIO_MESSAGE_QUEUE_URI']) # noqa from app import socketio_event_listeners from app import sqlalchemy_event_listeners diff --git a/app/models.py b/app/models.py index 7604d82c..f5cd0009 100644 --- a/app/models.py +++ b/app/models.py @@ -869,7 +869,7 @@ class Corpus(HashidMixin, db.Model): cascade='all, delete-orphan' ) # "static" attributes - max_num_tokens = 2147483647 + max_num_tokens = 2_147_483_647 def __repr__(self): return f'' diff --git a/app/socketio_event_listeners.py b/app/socketio_event_listeners.py index c432687b..92cfc1fa 100644 --- a/app/socketio_event_listeners.py +++ b/app/socketio_event_listeners.py @@ -1,6 +1,6 @@ from app import hashids, socketio from app.decorators import socketio_login_required -from app.models import User +from app.models import TesseractOCRModel, TranskribusHTRModel, User from flask_login import current_user from flask_socketio import join_room @@ -11,14 +11,31 @@ def users_user_get(user_hashid): user_id = hashids.decode(user_hashid) user = User.query.get(user_id) if user is None: - response = {'code': 404, 'msg': 'Not found'} - elif not (user == current_user or current_user.is_administrator): - response = {'code': 403, 'msg': 'Forbidden'} - else: - response = { - 'code': 200, - 'msg': 'OK', - 'payload': user.to_dict(backrefs=True, relationships=True) - } - join_room(f'users.{user.hashid}') - return response + return {'code': 404, 'msg': 'Not found'} + if not (user == current_user or current_user.is_administrator): + return {'code': 403, 'msg': 'Forbidden'} + # corpora = [x.to_dict() for x in user.corpora] + # jobs = [x.to_dict() for x in user.jobs] + # transkribus_htr_models = TranskribusHTRModel.query.filter( + # (TranskribusHTRModel.shared == True) | (TranskribusHTRModel.user == user) + # ).all() + # tesseract_ocr_models = TesseractOCRModel.query.filter( + # (TesseractOCRModel.shared == True) | (TesseractOCRModel.user == user) + # ).all() + # response = { + # 'code': 200, + # 'msg': 'OK', + # 'payload': { + # 'user': user.to_dict(), + # 'corpora': corpora, + # 'jobs': jobs, + # 'transkribus_htr_models': transkribus_htr_models, + # 'tesseract_ocr_models': tesseract_ocr_models + # } + # } + join_room(f'users.{user.hashid}') + return { + 'code': 200, + 'msg': 'OK', + 'payload': user.to_dict(backrefs=True, relationships=True) + }