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_login import LoginManager
from flask_mail import Mail
from flask_socketio import SocketIO
from flask_sqlalchemy import SQLAlchemy
@ -11,6 +12,7 @@ login_manager = LoginManager()
login_manager.login_view = 'auth.login'
mail = Mail()
scheduler = APScheduler()
socketio = SocketIO()
def create_app(config_name):
@ -23,6 +25,7 @@ def create_app(config_name):
mail.init_app(app)
scheduler.init_app(app)
scheduler.start()
socketio.init_app(app)
from .api import api as api_blueprint
app.register_blueprint(api_blueprint, url_prefix='/api')

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 ..models import Corpus, User
from ..tables import AdminUserTable, AdminUserItem
from . import main
from .forms import CreateCorpusForm
from ..decorators import admin_required
from .. import db
from .. import db, socketio
from ..models import Corpus
import os
@ -15,6 +13,12 @@ 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))
@main.route('/corpora/<int:corpus_id>')
@login_required
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/polls.js') }}"></script>
{% 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/utils.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 dotenv import load_dotenv
from flask_migrate import Migrate
import os
load_dotenv()
app = create_app(os.getenv('FLASK_CONFIG') or 'default')
migrate = Migrate(app, db)
if __name__ == '__main__':
socketio.run(app)
@app.shell_context_processor
def make_shell_context():
return dict(db=db,

View File

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