Codestyle enhancements

This commit is contained in:
Patrick Jentsch 2022-05-05 15:10:03 +02:00
parent 0a8b32e57e
commit 7362bb5514
3 changed files with 33 additions and 19 deletions

View File

@ -1,6 +1,7 @@
from config import Config from config import Config
from flask import Flask from flask import Flask
from flask_apscheduler import APScheduler from flask_apscheduler import APScheduler
from flask_assets import Environment
from flask_login import LoginManager from flask_login import LoginManager
from flask_mail import Mail from flask_mail import Mail
from flask_migrate import Migrate from flask_migrate import Migrate
@ -8,10 +9,9 @@ from flask_paranoid import Paranoid
from flask_socketio import SocketIO from flask_socketio import SocketIO
from flask_sqlalchemy import SQLAlchemy from flask_sqlalchemy import SQLAlchemy
from flask_hashids import Hashids from flask_hashids import Hashids
import flask_assets
assets: flask_assets.Environment = flask_assets.Environment() assets: Environment = Environment()
db: SQLAlchemy = SQLAlchemy() db: SQLAlchemy = SQLAlchemy()
hashids: Hashids = Hashids() hashids: Hashids = Hashids()
login: LoginManager = LoginManager() login: LoginManager = LoginManager()
@ -38,10 +38,7 @@ def create_app(config: Config = Config) -> Flask:
mail.init_app(app) mail.init_app(app)
migrate.init_app(app, db) migrate.init_app(app, db)
paranoid.init_app(app) paranoid.init_app(app)
socketio.init_app( socketio.init_app(app, message_queue=app.config['NOPAQUE_SOCKETIO_MESSAGE_QUEUE_URI']) # noqa
app,
message_queue=app.config['NOPAQUE_SOCKETIO_MESSAGE_QUEUE_URI']
)
from app import socketio_event_listeners from app import socketio_event_listeners
from app import sqlalchemy_event_listeners from app import sqlalchemy_event_listeners

View File

@ -869,7 +869,7 @@ class Corpus(HashidMixin, db.Model):
cascade='all, delete-orphan' cascade='all, delete-orphan'
) )
# "static" attributes # "static" attributes
max_num_tokens = 2147483647 max_num_tokens = 2_147_483_647
def __repr__(self): def __repr__(self):
return f'<Corpus {self.title}>' return f'<Corpus {self.title}>'

View File

@ -1,6 +1,6 @@
from app import hashids, socketio from app import hashids, socketio
from app.decorators import socketio_login_required 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_login import current_user
from flask_socketio import join_room from flask_socketio import join_room
@ -11,14 +11,31 @@ def users_user_get(user_hashid):
user_id = hashids.decode(user_hashid) user_id = hashids.decode(user_hashid)
user = User.query.get(user_id) user = User.query.get(user_id)
if user is None: if user is None:
response = {'code': 404, 'msg': 'Not found'} return {'code': 404, 'msg': 'Not found'}
elif not (user == current_user or current_user.is_administrator): if not (user == current_user or current_user.is_administrator):
response = {'code': 403, 'msg': 'Forbidden'} return {'code': 403, 'msg': 'Forbidden'}
else: # corpora = [x.to_dict() for x in user.corpora]
response = { # jobs = [x.to_dict() for x in user.jobs]
'code': 200, # transkribus_htr_models = TranskribusHTRModel.query.filter(
'msg': 'OK', # (TranskribusHTRModel.shared == True) | (TranskribusHTRModel.user == user)
'payload': user.to_dict(backrefs=True, relationships=True) # ).all()
} # tesseract_ocr_models = TesseractOCRModel.query.filter(
join_room(f'users.{user.hashid}') # (TesseractOCRModel.shared == True) | (TesseractOCRModel.user == user)
return response # ).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)
}