mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-11-15 09:15:41 +00:00
25 lines
890 B
Python
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})
|