def upload_image(files, app): image = files['image-upload'] if image.filename != '' and data_manager.allowed_file(image.filename): image.save(os.path.join(app.config['UPLOAD_FOLDER'], image.filename)) else: image = 'No image' return image.filename if image != 'No image' else image
def route_add_answer(question_id): global update_views update_views = False if request.method == 'POST': random_file_name = util.random_string() message = util.make_compat_display(request.form['message']) message = message.replace("'", "''") file = request.files['file'] filename = secure_filename(file.filename) if file and data_manager.allowed_file(file.filename): extension = filename[-4:] filename = str(random_file_name) + extension file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename)) data_manager.add_answer(question_id, message, filename) return redirect(url_for('route_question', question_id=question_id)) return render_template('add_answer.html', question_id=question_id)
def route_add_question(): global update_views if request.method == 'POST': random_file_name = util.random_string() title = request.form['title'] message = util.make_compat_display(request.form['message']) file = request.files['file'] filename = secure_filename(file.filename) if file and data_manager.allowed_file(file.filename): # filename = secure_filename(file.filename) extension = filename[-4:] filename = str(random_file_name) + extension file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename)) data_manager.add_question(title, message, filename) update_views = False return redirect(url_for("route_index")) else: return render_template('add_question.html')