Merge branch 'socketio' into 'development'

Socketio

See merge request sfb1288inf/opaque!1
This commit is contained in:
Patrick Jentsch 2019-08-22 15:16:55 +02:00
commit 3d8b8e9182
6 changed files with 48 additions and 15 deletions

View File

@ -3,6 +3,7 @@ from flask import Flask
from flask_apscheduler import APScheduler from flask_apscheduler import APScheduler
from flask_login import LoginManager from flask_login import LoginManager
from flask_mail import Mail from flask_mail import Mail
from flask_socketio import SocketIO
from flask_sqlalchemy import SQLAlchemy from flask_sqlalchemy import SQLAlchemy
@ -11,6 +12,7 @@ login_manager = LoginManager()
login_manager.login_view = 'auth.login' login_manager.login_view = 'auth.login'
mail = Mail() mail = Mail()
scheduler = APScheduler() scheduler = APScheduler()
socketio = SocketIO()
def create_app(config_name): def create_app(config_name):
@ -23,6 +25,7 @@ def create_app(config_name):
mail.init_app(app) mail.init_app(app)
scheduler.init_app(app) scheduler.init_app(app)
scheduler.start() scheduler.start()
socketio.init_app(app)
from .api import api as api_blueprint from .api import api as api_blueprint
app.register_blueprint(api_blueprint, url_prefix='/api') app.register_blueprint(api_blueprint, url_prefix='/api')

View File

@ -1,12 +1,10 @@
from flask import (abort, current_app, flash, redirect, request, from flask import (abort, current_app, flash, redirect, request,
render_template, url_for, send_from_directory) render_template, url_for, send_from_directory)
from flask_login import current_user, login_required from flask_login import current_user, login_required
from ..models import Corpus, User
from ..tables import AdminUserTable, AdminUserItem
from . import main from . import main
from .forms import CreateCorpusForm from .forms import CreateCorpusForm
from ..decorators import admin_required from .. import db, socketio
from .. import db from ..models import Corpus
import os import os
@ -15,6 +13,12 @@ def index():
return render_template('main/index.html.j2', title='Opaque') return render_template('main/index.html.j2', title='Opaque')
@socketio.on('my event')
@login_required
def handle_message(message):
print('received message: ' + str(message))
@main.route('/corpora/<int:corpus_id>') @main.route('/corpora/<int:corpus_id>')
@login_required @login_required
def corpus(corpus_id): def corpus(corpus_id):

File diff suppressed because one or more lines are too long

View File

@ -27,6 +27,13 @@
<script src="{{ url_for('static', filename='js/jsondiffpatch.umd.js') }}"></script> <script src="{{ url_for('static', filename='js/jsondiffpatch.umd.js') }}"></script>
<script src="{{ url_for('static', filename='js/polls.js') }}"></script> <script src="{{ url_for('static', filename='js/polls.js') }}"></script>
{% endif %} {% endif %}
<script src="{{ url_for('static', filename='js/socket.io.js') }}"></script>
<script type="text/javascript" charset="utf-8">
var socket = io();
socket.on('connect', function() {
socket.emit('my event', {data: 'I\'m connected!'});
});
</script>
<script src="{{ url_for('static', filename='js/list.min.js') }}"></script> <script src="{{ url_for('static', filename='js/list.min.js') }}"></script>
<script src="{{ url_for('static', filename='js/utils.js') }}"></script> <script src="{{ url_for('static', filename='js/utils.js') }}"></script>
<script src="{{ url_for('static', filename='js/CorpusList.js') }}"></script> <script src="{{ url_for('static', filename='js/CorpusList.js') }}"></script>

View File

@ -1,13 +1,21 @@
from app import create_app, db from app import create_app, db, socketio
from app.models import Corpus, User, Role, Permission, Job from app.models import Corpus, User, Role, Permission, Job
from dotenv import load_dotenv
from flask_migrate import Migrate from flask_migrate import Migrate
import os import os
load_dotenv()
app = create_app(os.getenv('FLASK_CONFIG') or 'default') app = create_app(os.getenv('FLASK_CONFIG') or 'default')
migrate = Migrate(app, db) migrate = Migrate(app, db)
if __name__ == '__main__':
socketio.run(app)
@app.shell_context_processor @app.shell_context_processor
def make_shell_context(): def make_shell_context():
return dict(db=db, return dict(db=db,

View File

@ -1,10 +1,12 @@
docker==4.0.2 docker
Flask==1.0.3 eventlet
Flask-APScheduler==1.11.0 Flask
Flask-Login==0.4.1 Flask-APScheduler
Flask-Mail==0.9.1 Flask-Login
Flask-Migrate==2.5.2 Flask-Mail
Flask-SQLAlchemy==2.4.0 Flask-Migrate
Flask-Table==0.5.0 Flask-SocketIO
Flask-WTF==0.14.2 Flask-SQLAlchemy
python-dotenv==0.10.3 Flask-Table
Flask-WTF
python-dotenv