Beispiel #1
0
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)
Beispiel #2
0
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)
Beispiel #3
0
 def delete_expired_posts(self):
     posts = Post.from_mongo(self._id)
     for post in posts:
         request = requests.get(post.url)
         content = request.content
         if post.type == "kijiji":
             soup = BeautifulSoup(content, "html.parser")
             expired_container = soup.find(
                 "div", {"class": "expired-ad-container"})
             if expired_container is not None:
                 post.delete_post()
         elif post.type == "autotrader":
             soup = BeautifulSoup(content, "html.parser")
             expired_container = soup.find("div",
                                           {"id": "pageNotFoundContainer"})
             if expired_container is not None:
                 post.delete_post()
Beispiel #4
0
def update_post(post_id, blog_id):
    if request.method == 'GET':
        return render_template('update_post.html',
                               blog_id=blog_id,
                               post_id=post_id)
    else:
        title = request.form['title']
        content = request.form['content']
        # user = User.get_by_email(session['email'])
        existing_post = Post.from_mongo(post_id)
        if str.strip(title) == "":
            title = existing_post.title
        if str.strip(content) == "":
            content = existing_post.content
        updated_post = Post(existing_post.blog_id, title, content,
                            existing_post.author, existing_post.created_date,
                            existing_post._id)
        updated_post.update_post(post_id)
    return make_response(blog_posts(blog_id))
Beispiel #5
0
 def get_posts(self):
     return Post.from_mongo(self.id)
Beispiel #6
0
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)
Beispiel #7
0
def load_posts(pull_id):
    pull = Pull.from_mongo(pull_id)
    posts = Post.from_mongo(pull_id)
    return render_template('posts.html', pull=pull, posts=posts)