def upload(): sidelinks = [ Sidelink('My Lectures', 'lecture.my', 'View lectures.'), Sidelink('Notes', 'note.view', 'See the work classmates have shared.'), Sidelink('Chat', 'discussion.board', 'Chat with classmates.') ] sidebar = [ Sidebar('My Lectures', 'lecture.my'), Sidebar('Github', 'https://github.com/poiley/take-note', True), Sidebar('Sign Out', 'auth.signout') ] return render_template('note/upload.html', sidelinks=sidelinks, sidebar=sidebar)
def view(): sidelinks = [ Sidelink('My Lectures', 'lecture.my', 'View lectures.'), Sidelink('Upload', 'note.upload', 'Upload notes.'), Sidelink('Chat', 'discussion.board', 'Chat with classmates.') ] sidebar = [ Sidebar('My Lectures', 'lecture.my'), Sidebar('Github', 'https://github.com/poiley/take-note', True), Sidebar('Sign Out', 'auth.signout') ] return render_template('note/view.html', sidelinks=sidelinks, sidebar=sidebar)
def signup(): form = SignupForm(request.form) if request.method == 'POST' and form.validate(): user = User(form.data['username'], form.data['displayname'], generate_password_hash(form.data['password'])) db.session.add(user) db.session.commit() login_user(user, remember=True) return redirect(url_for('lecture.my')) sidelinks = [Sidelink('Sign Up', "javascript:document.getElementById('signup').submit()", 'submit', True)] sidebar = [Sidebar('Home', 'home.home'), Sidebar('Sign In', 'auth.signin'), Sidebar('Github', 'https://github.com/poiley/take-note', True)] return render_template('auth/signup.html', sidelinks=sidelinks, sidebar=sidebar, form=form)
def home(): if current_user.is_authenticated: return redirect(url_for('lecture.my')) sidelinks = [Sidelink('Sign In', 'auth.signin', 'sign in'), Sidelink('Sign Up', 'auth.signup', 'sign up') ] sidebar = [Sidebar('Github', 'https://github.com/poiley/take-note', True)] return render_template('home/index.html', sidelinks=sidelinks, sidebar=sidebar)
def signin(): if current_user.is_authenticated: return redirect(url_for('home.home')) form = SigninForm(request.form) if request.method == 'POST' and form.validate(): user = User.query.filter_by(username=form.data['username']).first() if not user or not user.check_password(form.data['password']): flash('Invalid Username or Password.') return redirect(url_for('auth.signin')) login_user(user, remember=True) return redirect(url_for('home.home')) sidelinks = [Sidelink('Sign In', "javascript:document.getElementById('signin').submit()", 'submit', True)] sidebar = [Sidebar('Home', 'home.home'), Sidebar('Github', 'https://github.com/poiley/take-note', True)] return render_template('auth/signin.html', sidelinks=sidelinks, sidebar=sidebar, form=form)
def search(): form = SearchForm(request.form) if request.method == 'POST' and form.validate(): results = Lecture.query.filter_by(dept=form.dept.data) if form.course_num.data is not '': results = results.filter_by(course_num=form.course_num.data) if form.title.data is not '': results = results.filter_by(title=form.title.data) if len(results.all()) == 0: return redirect(url_for('lecture.search')) elif len(results.all()) == 1: return redirect(url_for('lecture.add', id=[results.all()[0].id])) lecture_ids = [] for result in results.all(): lecture_ids.append(result.id) return search_results(lecture_ids) sidelinks = [ Sidelink('Search', "javascript:document.getElementById('searchform').submit()", 'Submit query', True), Sidelink('Locate', "lecture.locate", 'Get a list of classes currently in session near you') ] sidebar = [ Sidebar('My Lectures', 'lecture.my'), Sidebar('Github', 'https://github.com/poiley/take-note', True), Sidebar('Sign Out', 'auth.signout') ] return render_template('lecture/search.html', sidelinks=sidelinks, sidebar=sidebar, form=form)
def my(): u = User.get(current_user.get_id()) sidelinks = [ Sidelink('Add A Lecture', 'lecture.search', 'Add a lecture to your schedule.'), Sidelink('View Class', '#', 'View the selected lecture.', True, onclick="viewClass()") ] sidebar = [ Sidebar('My Lectures', 'lecture.my'), Sidebar('Github', 'https://github.com/poiley/take-note', True), Sidebar('Sign Out', 'auth.signout') ] return render_template('lecture/my.html', sidelinks=sidelinks, sidebar=sidebar, user=u, lectures=u.lecture)
def board(): if not request.args.get('id'): return redirect(url_for('lecture.my')) lect = Lecture.query.filter_by(id=request.args.get('id')).first() if not lect: return redirect(url_for('lecture.my')) sidelinks = [ Sidelink('My Lectures', 'lecture.my', 'View lectures.'), Sidelink('Chat', '#', 'Chat with classmates.', True), Sidelink('Notes', 'note.view', 'See the work classmates have shared.') ] sidebar = [ Sidebar('My Lectures', 'lecture.my'), Sidebar('Github', 'https://github.com/poiley/take-note', True), Sidebar('Sign Out', 'auth.signout') ] return render_template('discussion/board.html', lecture=lect, sidelinks=sidelinks, sidebar=sidebar)
def search_results(ids): results = [] for i in ids: results.append(Lecture.get(i)) sidelinks = [ Sidelink('Add', '#', 'Add the selected lecture', True, css_classes='sidelink add', onclick="addClass()"), Sidelink('Search Again', 'lecture.search', 'Try a different search') ] sidebar = [ Sidebar('My Lectures', 'lecture.my'), Sidebar('Github', 'https://github.com/poiley/take-note', True), Sidebar('Sign Out', 'auth.signout') ] return render_template('lecture/results.html', sidelinks=sidelinks, sidebar=sidebar, results=results)