nopaque/app/test/events.py

24 lines
826 B
Python
Raw Normal View History

from app import logger, socketio
from flask_login import login_required
from werkzeug.datastructures import FileStorage
from werkzeug.utils import secure_filename
from .forms import TestForm
import io
@socketio.on('submit-test-form')
@login_required
def recv_test_form(data):
2020-01-23 10:19:37 +00:00
logger.warning("data_received")
filename = secure_filename(data['file-wrapper']['name'])
stream = io.BytesIO(data['file-wrapper']['bytes'])
file = FileStorage(filename=filename, stream=stream)
data['file'] = file
test_form = TestForm(data=data)
if test_form.validate():
2020-01-23 10:19:37 +00:00
socketio.emit('submit-test-form', {'msg': {},
'status': 201})
else:
2020-01-23 10:19:37 +00:00
socketio.emit('submit-test-form', {'msg': test_form.errors,
'status': 400})