mirror of
				https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
				synced 2025-11-03 20:02:47 +00:00 
			
		
		
		
	Use Flask-Hashids package
This commit is contained in:
		@@ -6,14 +6,13 @@ from flask_migrate import Migrate
 | 
			
		||||
from flask_paranoid import Paranoid
 | 
			
		||||
from flask_socketio import SocketIO
 | 
			
		||||
from flask_sqlalchemy import SQLAlchemy
 | 
			
		||||
from hashids import Hashids
 | 
			
		||||
from flask_hashids import Hashids
 | 
			
		||||
import flask_assets
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
assets: flask_assets.Environment = flask_assets.Environment()
 | 
			
		||||
db: SQLAlchemy = SQLAlchemy()
 | 
			
		||||
# TODO: Add 'SECRET_KEY' from as 'salt' kwarg
 | 
			
		||||
hashids: Hashids = Hashids(min_length=32)
 | 
			
		||||
hashids: Hashids = Hashids()
 | 
			
		||||
login: LoginManager = LoginManager()
 | 
			
		||||
login.login_view: str = 'auth.login'
 | 
			
		||||
login.login_message: str = 'Please log in to access this page.'
 | 
			
		||||
@@ -24,14 +23,15 @@ paranoid.redirect_view: str = '/'
 | 
			
		||||
socketio: SocketIO = SocketIO()
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def create_app(config_class: Config = Config) -> Flask:
 | 
			
		||||
def create_app(config: Config = Config) -> Flask:
 | 
			
		||||
    ''' Creates an initialized Flask (WSGI Application) object. '''
 | 
			
		||||
    app: Flask = Flask(__name__)
 | 
			
		||||
    app.config.from_object(config_class)
 | 
			
		||||
    app.config.from_object(config)
 | 
			
		||||
 | 
			
		||||
    assets.init_app(app)
 | 
			
		||||
    config_class.init_app(app)
 | 
			
		||||
    config.init_app(app)
 | 
			
		||||
    db.init_app(app)
 | 
			
		||||
    hashids.init_app(app)
 | 
			
		||||
    login.init_app(app)
 | 
			
		||||
    mail.init_app(app)
 | 
			
		||||
    migrate.init_app(app, db)
 | 
			
		||||
@@ -39,8 +39,8 @@ def create_app(config_class: Config = Config) -> Flask:
 | 
			
		||||
    socketio.init_app(
 | 
			
		||||
        app, message_queue=app.config['NOPAQUE_SOCKETIO_MESSAGE_QUEUE_URI'])
 | 
			
		||||
 | 
			
		||||
    from .utils import HashidConverter
 | 
			
		||||
    app.url_map.converters['hashid'] = HashidConverter
 | 
			
		||||
    # from .utils import HashidConverter
 | 
			
		||||
    # app.url_map.converters['hashid'] = HashidConverter
 | 
			
		||||
 | 
			
		||||
    from .events import socketio as socketio_events
 | 
			
		||||
    from .events import sqlalchemy as sqlalchemy_events
 | 
			
		||||
 
 | 
			
		||||
@@ -57,7 +57,7 @@ from .cqi import *  # noqa
 | 
			
		||||
def connect(auth):
 | 
			
		||||
    # the auth variable is used in a hacky way. It contains the corpus id for
 | 
			
		||||
    # which a corpus analysis session should be started.
 | 
			
		||||
    corpus_id = hashids.decode(auth['corpus_id'])[0]
 | 
			
		||||
    corpus_id = hashids.decode(auth['corpus_id'])
 | 
			
		||||
    corpus = Corpus.query.get(corpus_id)
 | 
			
		||||
    if corpus is None:
 | 
			
		||||
        # return {'code': 404, 'msg': 'Not Found'}
 | 
			
		||||
 
 | 
			
		||||
@@ -12,7 +12,7 @@ from ..models import User
 | 
			
		||||
@socketio.on('users.user.get')
 | 
			
		||||
@socketio_login_required
 | 
			
		||||
def users_user_get(user_hashid):
 | 
			
		||||
    user_id = hashids.decode(user_hashid)[0]
 | 
			
		||||
    user_id = hashids.decode(user_hashid)
 | 
			
		||||
    user = User.query.get(user_id)
 | 
			
		||||
    if user is None:
 | 
			
		||||
        response = {'code': 404, 'msg': 'Not found'}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user