def messages_create(channel_id): messageform = MessageForm(request.form) channel = Channel.query.get(channel_id) if not messageform.validate() or messageform.body.data.isspace(): return render_template( "channels/channel.html", messageform=MessageForm(), channel=channel, que=Message.count_how_many_comments_get_first(channel_id), my_channels=Channel.get_my_channels(current_user.id), all_channels=Channel.get_channels_where_not_in(current_user.id), allready_join=Channel.is_joined(channel_id, current_user.id), error="message must be 2 character length", public_channels=Channel.get_all_publics()) message = Message(messageform.body.data, current_user.username) message.account_id = current_user.id message.channel_id = channel_id db.session().add(message) db.session().commit() return redirect( url_for("one_channel_index", channel_id=channel_id, sort='first'))
def thread(thread_id, thread_edit=None, message_create=Message("", None, None), show_errors=False, message_edit=None, message_edit_id=None): if message_edit_id: message_edit_id = int(message_edit_id) message_edit = Message.query.get(message_edit_id) thread = Thread.query.get(thread_id) thread.user = User.query.get(thread.account_id) if current_user.is_authenticated: Read.mark_as_read(current_user.id, thread_id) return render_template("thread.html", thread=thread, thread_edit=thread_edit, tags=Tag.find_thread_id(thread_id), other_tags=Tag.find_not_thread_id(thread_id), messages=Message.find_thread_id(thread_id), message_create=message_create, show_errors=show_errors, message_edit=message_edit)
def threads_create(): categories = [(c.id, c.name) for c in Category.query.all()] if request.method == "GET": form = ThreadForm() form.categories.choices = categories return render_template("threads/new.html", form=form) form = ThreadForm(request.form) form.categories.choices = categories if not form.validate(): return render_template("threads/new.html", form=form) t = Thread(form.title.data) t.account_id = current_user.id categories = form.categories.data for c_id in categories: c = Category.query.get(c_id) t.categories.append(c) db.session().add(t) db.session().flush() m = Message(form.content.data) m.thread_id = t.id m.account_id = current_user.id db.session().add(m) db.session().commit() return redirect(url_for("threads_index"))
def messages_create(thread_id): form = MessageForm(request.form) if not form.validate(): thread = Thread.query.filter_by(id=thread_id).first() title = thread.title return render_template( "messages/list.html", messages=Message.query.filter_by(thread_id=thread_id).order_by( Message.date_created), thread_id=thread_id, title=title, form=form) m = Message(form.content.data) m.thread_id = thread_id m.account_id = current_user.id db.session().add(m) db.session().commit() t = Thread.query.filter_by(id=thread_id).first() t.date_modified = datetime.utcnow() db.session().commit() return redirect(url_for("get_messages_from_thread_id", thread_id=thread_id))
def messages_delete(message_id): if not _is_auth(message_id): abort(403) msg = Message.get(message_id) chat_id = ChatUser.get(msg.chat_user_id).chat_id Message.delete(message_id) return redirect(url_for("chats_view", chat_id=chat_id))
def users_get_one(user_id): message_count = Message.message_count(user_id) latest = Message.find_latest(user_id) return render_template("users/one_user.html", count=message_count, latest=latest, user=User.query.get(user_id))
def message_delete(param): toDelete = Message.query.filter_by(id=param).first() d = Discussion.query.filter_by(id=toDelete.discussion_id).first() check_ban(d.group_id) g = Groups.query.filter_by(id=d.group_id) d_id = toDelete.discussion_id if toDelete.sender_id == current_user.get_id( ) or g.owner_id == current_user.get_id(): Message.delete_message_with_id(param) return redirect(url_for("discussion_home", target=d_id, page=1))
def message_create(thread_id): text = request.form.get("text") message = Message(text, current_user.id, thread_id) if not message.validate(new=True): return thread(thread_id=thread_id, message_create=message, show_errors=True) db.session().add(message) db.session().commit() return redirect(url_for('thread', thread_id=thread_id))
def messages_create(topic_id): form = MessageForm(request.form) if not form.validate(): return render_template("messages/new.html", form = form, topic_id=topic_id) m = Message(form.message.data) m.account_id = current_user.id m.topic_id = topic_id db.session().add(m) db.session().commit() return redirect(url_for("messages_index", topic_id=topic_id))
def message_new(group_id): form = MessageForm(request.form) if not form.validate(): return render_template("messages/newMessage.html", form=form) m = Message(form.name.data) m.text = m.text m.account_id = current_user.id m.group_id = group_id db.session().add(m) db.session().commit() return redirect(url_for("group_messages", group_id=group_id))
def messages_create(): form = MessageForm(request.form) if not form.validate(): return render_template("messages/new.html", form = form) t = Message(form.name.data, form.messagetext.data) t.account_id = current_user.id t.category_id = request.form['category_id'] db.session().add(t) db.session().commit() return redirect(url_for("messages_index"))
def thread_delete(thread_id): thread = Thread.query.get(thread_id) if not (current_user.admin or current_user.id == thread.account_id): return redirect(url_for('thread', thread_id=thread_id)) Message.thread_delete_messages(thread_id) Tagging.thread_delete_taggings(thread_id) db.session().add(thread) db.session().delete(thread) db.session().commit() return redirect(url_for("thread_index"))
def render_messages_edit(message_id, form): m = Message.query.get(message_id) auction_id = m.auction_id html_file = "auctions/view.html" a = Auction.query.get(auction_id) seller = User.query.get(a.account_id) bids = Bid.find_bids(auction_id) highest_bid = Bid.highest_bid(auction_id) messages = Message.get_messages(auction_id) ended = 0 if a.date_ends < datetime.datetime.now(): ended = 1 time_to_go = a.date_ends - datetime.datetime.now() return render_template(html_file, form=form, edit_mode=1, edit_message_id=m.id, seller=seller, bids=bids, highest_bid=highest_bid, ended=ended, days_to_go=time_to_go.days, messages=messages, auction=a)
def message_add(club_id): club = Club.query.get(club_id) if not club or current_user.id != club.leader_id: return redirect(url_for("clubs_index")) form = MessageForm(request.form) if not form.validate(): return render_template("clubs/club.html", club=club) message = Message(form.message.data) message.club_id = club.id db.session().add(message) db.session().commit() return redirect(url_for("club_page", club_id=club.id))
def search_topic(): topics = [] messages = [] results = [] form = SearchForm(request.form) search_term = form.search_phrase.data if not form.validate(): return render_template("search/search.html", form=form) searching_for = form.searching_for.data if searching_for == "topic": topics = Topic.query.filter( Topic.title.like("%" + search_term + "%")).order_by( Topic.date_created.desc()).limit(30).all() elif searching_for == "author": messages = Message.query.filter( Message.author.like("%" + search_term + "%")).order_by( Message.date_created.desc()).limit(30).all() elif searching_for == "all": results = Message.find_all(search_term) return render_template("search/search.html", topics=topics, messages=messages, results=results, form=SearchForm())
def topics_create(): form = TopicForm(request.form) if form.title.validate(form) and form.message.validate(form): place = db.session.query(Place).get(form.place.data) if form.place.data == 0: place_id = 0 else: place_id = place.id topic = Topic(form.title.data, place_id) db.session().add(topic) db.session().commit() topic_timefix = Topic.query.get(topic.id) topic_timefix.date_created = datetime.now().replace(microsecond=0, second = 0) db.session().commit message = Message(form.message.data, topic.id, current_user.id) db.session().add(message) db.session().commit() message_timefix = Message.query.get(message.id) message_timefix.date_created = datetime.now().replace(microsecond=0, second = 0) db.session().commit() newTopicAccount = topicAccount.insert().values(topic_id=topic.id, account_id=current_user.id) db.session().execute(newTopicAccount) db.session.commit() return redirect(url_for("topics_index")) places = db.session.query(Place) form=TopicForm() form.place.choices = [("0", "---")] + [(i.id, i.name) for i in places] return render_template("topics/new.html", form = form, error="topic name must be between 1-100 characters and message between 1-1000 characters")
def messages_index(topic_id): t = Topic.find_topic_with_creator_info(topic_id) # will be form [{ "name": '', "id": '', "date_created": row[2], "date_modified": row[3], "desription": row[4], "category_id": row[5], "account": {"id": row[6], "username": row[7]} }] c = Category.query.get(t[0]["category_id"]) topic_messages = Message.find_messages_for_topic_with_users(topic_id) # will be form { message: { message: '', id: '' }, account: { username: '', id: '' } } return render_template("messages/list.html", messages = topic_messages, topic = t[0], category = c)
def can_delete(self, user_id, message_id): if self.is_admin(user_id): return True user = User.find_id(user_id) if user.is_admin(): return True cu = ChatUser.find(user_id, self.id) return cu.id == Message.get(message_id).chat_user_id
def thread_respond(thread_id): form = MessageForm(request.form) if not form.validate(): return render_template("message_response_form.html", form = form) new_message = Message(title=form.title.data, content=form.content.data, time_of_sending=datetime.now(), author_id=current_user.id, thread_id=thread_id) db.session.add(new_message) db.session.commit() return render_template("thread_details.html", thread=Thread.query.get(thread_id))
def messages_create(): f = MessageForm() if not f.validate(): return render_template("messages/new.html", form=f) m = Message(f.subject.data, f.body.data) m.account_id = current_user.id for c in f.categories.data: cat = Category.query.get(c) m.categories.append(cat) db.session.add(m) db.session.commit() return redirect(url_for("messages_index"))
def profile_show(account_id): user = User.query.get(account_id) latest_messages = Message.find_ten_latest_messages_by_user_id(user.id) latest_topics = Topic.find_ten_latest_topics_by_user_id(user.id) return render_template("auth/show.html", user=user, latest_messages=latest_messages, latest_topics=latest_topics)
def messages_create(target): check_ban(target) form = MessageForm(request.form) if not form.validate(): return redirect(url_for("discussion_home", target=target, page=1)) m = Message(request.form.get("message"), target, current_user.get_id()) db.session().add(m) db.session().commit() return redirect(url_for("discussion_home", target=target, page=1))
def messages_view(message_id): message = Message.get(message_id) cu = ChatUser.get(message.chat_user_id) chat = Chat.get(cu.chat_id) user = User.find_id(cu.user_id) return render_template("messages/view.html", chat=chat, user=user, message=message)
def create_thread(title, message_text, user_id, category_id): t = Thread(title=title, category_id=category_id) db.session.add(t) db.session.flush() m = Message(message_text=message_text, thread_id=t.id, user_id=user_id, original_post=True) db.session.add(m) db.session.commit()
def post_reply(thread_id, message_text, user_id): m = Message(message_text, thread_id=thread_id, user_id=user_id) t = Thread.query.get(thread_id) t.date_modified = db.func.current_timestamp() db.session.add(m) db.session.commit()
def mark_as_read(user_id, thread_id): messages = Message.find_thread_id(thread_id) for message in messages: read = Read(user_id, message.id) if read.exists(): continue db.session().add(read) db.session().commit()
def chats_view(chat_id): if not _member_of(current_user.id, chat_id): abort(403) chat = Chat.get(chat_id) if not chat: return redirect(url_for('chats_all')) return render_template("chats/view.html", chat=chat, messages=Message.find_all_in_chat(chat_id), form=MessageForm())
def users_view(user_id): user = User.find_id(user_id) if user is None: abort(404) chats = Chat.find_by_user(user_id) messages = Message.find_by_user(user_id) return render_template("users/view.html", user=user, chats=chats, messages=messages)
def messages_edit(message_id): if not _is_sender(message_id): abort(403) form = MessageForm() msg = Message.get(message_id) if form.validate_on_submit(): msg.edit(form.text.data) return redirect(url_for("index")) return render_template("messages/edit.html", form=form, message=msg)
def one_channel_index(channel_id, sort): query = [] account_count = Channel.count_accounts(channel_id) if sort == 'first': query = Message.count_how_many_comments_get_first(channel_id) elif sort == 'last': query = Message.count_how_many_comments_get_last(channel_id) return render_template( "channels/channel.html", messageform=MessageForm(), channel=Channel.query.get(channel_id), que=query, my_channels=Channel.get_my_channels(current_user.id), all_channels=Channel.get_channels_where_not_in(current_user.id), allready_join=Channel.is_joined(channel_id, current_user.id), public_channels=Channel.get_all_publics(), account_count=account_count)