def messages(section_id, id): section = SectionRepository.find_by_id(section_id) if not section: abort(404) thread = MessageRepository.find_by_id(id) if not thread: abort(404) if thread.section_id != section.id: abort(404) messages = MessageRepository.find_messages_of_thread(id) form = NewMessageForm() if form.validate_on_submit(): message = Message() message.course_id = section.course_id message.section_id = section.id message.user_id = current_user.id message.section_only = thread.section_only message.title = thread.title message.thread_id = thread.id message.message = form.message.data message = MessageRepository.create(message) return redirect( url_for('section.messages', section_id=section_id, id=id)) return render_template("section/messages.html", section=section, messages=messages, form=form, current_user=current_user, thread=thread)
def threads(id): section = SectionRepository.find_by_id(id) if not section: abort(404) threads = MessageRepository.find_threads_of_section(section.id) form = NewThreadForSectionForm() if form.validate_on_submit(): message = Message() message.course_id = section.course_id message.section_id = section.id message.user_id = current_user.id message.section_only = form.section_only.data message.title = form.title.data message.message = form.message.data message = MessageRepository.create(message) return redirect(url_for('section.threads', id=id)) return render_template("section/threads.html", section=section, threads=threads, form=form, current_user=current_user)