def match(data): matched_user = User.find_closest_rating(data['choice'], data['rating'], data['username']) if matched_user.is_authenticated: print("He is online!") new_question = Question(data['question'], "", current_user.name, data['choice']) new_question.save() for value in data['tags']: if value is not None: print(value) new_tag = Tag(value) new_tag.save() new_question_tag = Question_tag(new_question.id, new_tag.id) new_question_tag.save() chat_id = str(uuid.uuid1()) print("NEW CHAT ID IS {}".format(chat_id)) print("You are {}".format(matched_user.name)) print("I am {}".format(current_user.name)) emit('question_match', { 'question': data['question'], 'user_id': current_user.id, 'matched_user_id': matched_user.id, 'chat_id': chat_id }, room=matched_user.room_id) else: flash('No matches available. Try again!') print("No luck today!")