def get_all_posts(): user = User.get_by_email(session['email']) pulls = Pull.find_by_author_id(user.id) posts = [] for pull in pulls: posts = posts + Post.from_mongo(pull._id) return render_template('all_posts.html', posts=posts)
def refresh(): posts = request.args.get('post') pull = request.args.get('pull') template = 'pulls.html' user = User.get_by_email(session['email']) pulls = Pull.find_by_author_id(user.id) ScheduledTasks.update_posts(pulls) return render_template(template, posts=posts, pull=pull, pulls=pulls)
def price_drops(): user = User.get_by_email(session['email']) pulls = Pull.find_by_author_id(user.id) posts_list = [] for pull in pulls: posts = Post.from_mongo(pull._id) for post in posts: if len(post.prices) > 1: posts_list.append(post) return render_template('price_drops.html', posts=posts_list)
def starred_posts(): user = User.get_by_email(session['email']) pulls = Pull.find_by_author_id(user.id) posts = [] for pull in pulls: try: posts = posts + Post.get_starred_posts(pull._id) except TypeError: continue return render_template('starred_posts.html', posts=posts)
def start_pull(): user = User.get_by_email(session['email']) pulls = Pull.find_by_author_id(user.id) return render_template('pulls.html', pulls=pulls)
def change_flags(variable, flag, post_id, template): post = Post.from_mongo_post_id(post_id) if flag == 'True': flag = True else: flag = False if variable == 'star': post.update_post({ "_id": post._id, "location": post.location, "kms": post.kms, "image": post.image, "title": post.title, "date_posted": post.date_posted, "seller": post.seller, "prices": post.prices, "transmission": post.transmission, "description": post.description, "url": post.url, "pull_id": post.pull_id, "hide": post.hide, "star": flag, "type": post.type }) else: post.update_post({ "_id": post._id, "location": post.location, "kms": post.kms, "image": post.image, "title": post.title, "date_posted": post.date_posted, "seller": post.seller, "prices": post.prices, "transmission": post.transmission, "description": post.description, "url": post.url, "pull_id": post.pull_id, "hide": flag, "star": post.star, "type": post.type }) if template == 'starred_posts.html': user = User.get_by_email(session['email']) pulls = Pull.find_by_author_id(user.id) posts = [] for pull in pulls: try: posts = posts + Post.get_starred_posts(pull._id) except TypeError: continue else: pull = Pull.from_mongo(post.pull_id) posts = Post.from_mongo(pull._id) if template == 'posts.html': return make_response(load_posts(pull._id)) elif template == 'all_posts.html': return make_response(get_all_posts()) elif template == 'starred_posts.html': make_response(starred_posts()) elif template == 'price_drops.html': make_response(price_drops()) else: return render_template(template, pull=pull, posts=posts)