Move socketio event handlers in seperate file.

This commit is contained in:
Patrick Jentsch 2019-08-27 10:40:29 +02:00
parent fcd797b28d
commit d34447686b
3 changed files with 21 additions and 25 deletions

View File

@ -3,7 +3,7 @@ from flask import Blueprint
main = Blueprint('main', __name__)
from . import views, errors
from . import errors, events, views
from ..models import Permission

19
app/main/events.py Normal file
View File

@ -0,0 +1,19 @@
from flask_login import current_user, login_required
from flask_socketio import emit
from .. import socketio
import json
@socketio.on('connect')
@login_required
def connect():
corpora = []
jobs = []
for corpus in current_user.corpora:
corpora.append(corpus.to_dict())
for job in current_user.jobs:
jobs.append(job.to_dict())
emit('corpora', {'data': json.dumps(corpora)})
emit('jobs', {'data': json.dumps(jobs)})

View File

@ -1,12 +1,10 @@
from flask import (abort, current_app, flash, redirect, request,
render_template, url_for, send_from_directory)
from flask_login import current_user, login_required
from flask_socketio import emit
from . import main
from .forms import CreateCorpusForm
from .. import db, socketio
from .. import db
from ..models import Corpus
import json
import os
@ -15,27 +13,6 @@ def index():
return render_template('main/index.html.j2', title='Opaque')
@socketio.on('my event')
@login_required
def handle_message(message):
print('received message: ' + str(message))
@socketio.on('connect')
@login_required
def connect():
corpora = []
jobs = []
for corpus in current_user.corpora:
corpora.append(corpus.to_dict())
for job in current_user.jobs:
jobs.append(job.to_dict())
emit('corpora', {'data': json.dumps(corpora)})
emit('jobs', {'data': json.dumps(jobs)})
@main.route('/corpora/<int:corpus_id>')
@login_required
def corpus(corpus_id):