nopaque/app/test/events.py
2020-01-22 16:14:00 +01:00

25 lines
890 B
Python

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):
filename = secure_filename(data['file']['name'])
stream = io.BytesIO(data['file']['bytes'])
file = FileStorage(stream=stream, filename=filename)
data['file'] = file
test_form = TestForm(data=data)
if test_form.validate():
logger.warning('test_form is ok!')
socketio.emit('submit-test-form', {'status': 'success',
'msg': 'test_form is ok!'})
else:
logger.warning('test_form is not ok!')
socketio.emit('submit-test-form', {'status': 'error',
'msg': test_form.errors})