def topic_add(): if request.method == "POST": new_post = models.post(request.form["title"], request.form["content"]) post_store.add(new_post) return redirect(url_for("home")) else: return render_template("topic_add.html")
def send_message(data): user_ = User.query.filter_by(username=data['username']).first() thread_ = thread.query.filter_by(subject=data['room']).first() p = post(message=data['message'], user_id=user_.id, thread_id=thread_.id) db.session.add(p) db.session.commit() p = post.query.filter_by(message=data['message'], user_id=user_.id, thread_id=thread_.id).first() socketio.emit('received_message', { 'room': data['room'], 'user_id': p.user_id, 'username': user_.username, 'msg': p.message, 'post_id': p.id, 'thread_id': thread_.id }, room=data['room'], dif_user=p.user_id)
from app import models dummy_members = [ models.member("Mohammed", 20), models.member("Mohammed", 22), models.member("Abdo", 25), ] dummy_posts = [ models.post("Agriculture", "Agriculture is amazing", dummy_members[0].id), models.post("Engineering", "I love engineering", dummy_members[0].id), models.post("Medicine", "Medicine is great", dummy_members[1].id), models.post("Architecture", "Spectacular art", dummy_members[1].id), models.post("Astronomy", "Space is awesome", dummy_members[1].id), models.post("Geology", "Earth is our friend", dummy_members[2].id), models.post("ComputerSci", "Our passion", dummy_members[2].id), models.post("Algorithms", "Yeah, more of that", dummy_members[2].id), models.post("Operating Systems", "Ewww", dummy_members[2].id), ] def seed_stores(member_store, post_store): for member in dummy_members: member_store.add(member) for post in dummy_posts: post_store.add(post)
def api_topic_add(): request_data = request.get_json() new_post = models.post(request_data["title"], request_data["content"]) post_store.add(new_post) return jsonify(new_post.__dict__())