mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-12-24 10:34:17 +00:00
Move socketio event handlers in seperate file.
This commit is contained in:
parent
fcd797b28d
commit
d34447686b
@ -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
19
app/main/events.py
Normal 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)})
|
@ -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):
|
||||
|
Loading…
Reference in New Issue
Block a user