def view_all_polls(): return flask.render_template('admin.html', c={ 'user': auth.get_user_context( auth.current_user_id()), })
def view_user_polls(target_user_id): target_user = auth.get_user_context(target_user_id) polls = data.get_polls(auth.current_user_id(), target_user_id=target_user_id) for poll in polls: poll['choices'] = list(poll['choices'].values()) poll['choices'].sort(key=lambda x: x['vote_count'], reverse=True) return flask.render_template('profile_polls.html', c={ 'user': auth.get_user_context( auth.current_user_id()), 'target_user': target_user, 'polls': polls })
def view_user_favs(target_user_id): target_user = auth.get_user_context(target_user_id) # 404 if the use doesnt exist if target_user is None: return flask.abort(404) # get the target users favourite movies movies = data.get_fav_movies(target_user_id) movies = data.add_fav_count(movies) # flag our own favourite status for each of them movies = data.flag_fav_movies(movies, auth.current_user_id()) # render the profile page return flask.render_template('profile_favourites.html', c={ 'user': auth.get_user_context( auth.current_user_id()), 'target_user': target_user, 'movies': movies[:50] })
def view_rankings(): # get the top movies by our users favourites # TODO: add different sorting methods movies = data.get_top_favourited_movies(auth.current_user_id()) return flask.render_template('rankings.html', c={ 'user': auth.get_user_context( auth.current_user_id()), 'movies': movies[:50] })
def view_search(): # split the search terms up term_str = flask.request.args.get('q') terms = term_str.split(' ') # search the database for movies movies = data.search_movies(terms, auth.current_user_id()) # render the results page return flask.render_template('search.html', c={ 'user': auth.get_user_context( auth.current_user_id()), 'movies': movies[:50], 'search_query': term_str })
def view_index(): # prompt the user to log in with facebook oauth2 auth.try_login_user() # get movie db popular movies movies = data.get_popular_movies(auth.current_user_id()) all_movies = data.get_all_movies() # render the index template with user and movies contexts return flask.render_template('index.html', c={ 'user': auth.get_user_context( auth.current_user_id()), 'all_movies': all_movies, 'movies': movies[:50], })
def view_poll(poll_id): poll = data.get_poll(poll_id, current_user_id=auth.current_user_id()) if not poll: return flask.redirect('/polls') # sort poll choices by vote count poll['choices'] = list(poll['choices'].values()) poll['choices'].sort(key=lambda x: x['vote_count'], reverse=True) # get comments for the poll comments = data.get_poll_comments(poll_id) comments.sort(key=lambda x: x['timestamp'], reverse=True) return flask.render_template('poll.html', c={ 'user': auth.get_user_context( auth.current_user_id()), 'poll': poll, 'comments': comments })