Ejemplo n.º 1
0
 def _user_has_account(self):
     blog = Database.find_one(collection='blogs',
                              query={'author': self.user})
     if blog is not None:
         self.user_blog = Blog.from_mongo(blog['_id'])
         return True
     return False
Ejemplo n.º 2
0
 def new_post(blog_id, title, content, date=datetime.datetime.utcnow()):
     # title, content, date = datetime.datetime.utcnow()
     blog = Blog.from_mongo(
         blog_id
     )  # We need to consider the blog the user is writing to, blog_id sent
     # by website
     blog.new_post(title=title, content=content, date=date)
Ejemplo n.º 3
0
def posts(blog_id):
    blog = Blog.from_mongo(blog_id)
    posts = blog.get_posts()
    return render_template('posts.html',
                           posts=posts,
                           blog_id=blog._id,
                           blog_title=blog.title)
Ejemplo n.º 4
0
def get_posts(blog_id):
    blog = Blog.from_mongo(blog_id)
    posts = blog.get_posts()
    return render_template("posts.html",
                           blog_title=blog.title,
                           posts=posts,
                           blog_id=blog_id)
Ejemplo n.º 5
0
def blog_posts(blog_id):
    print("blog_id {}".format(blog_id))
    blog = Blog.from_mongo(blog_id)
    posts = blog.get_posts()

    return render_template('posts.html', posts=posts, blog_title=blog.title,
                           blog_id=blog._id)
Ejemplo n.º 6
0
 def _user_has_account(self):
     blog = Database.find_one('blogs', {'author': self.user})
     if blog is not None:
         self.user_blog = Blog.from_mongo(blog['id'])
         return True
     else:
         return False
Ejemplo n.º 7
0
 def new_post(self,
              blog_id,
              title,
              comment,
              date=datetime.datetime.utcnow()):
     blog = Blog.from_mongo(blog_id)
     blog.new_post(title=title, comment=comment, date=date)
Ejemplo n.º 8
0
def list_post(blog_id):
    blog = Blog.from_mongo(blog_id)
    posts = blog.get_all_posts()
    return render_template('user_posts.html',
                           posts=posts,
                           name_of_blog=blog.title,
                           blog_id=blog._id)
Ejemplo n.º 9
0
def blog_posts(blog_id):
    """Load posts from the selected blog"""
    blog = Blog.from_mongo(blog_id)

    posts = blog.get_posts()

    return render_template('posts.html', posts=posts, blog_title=blog.title, blog_id=blog._id)
Ejemplo n.º 10
0
def view_post(blog_id, post_id):
    blog = Blog.from_mongo(blog_id)
    post = blog.get_post(post_id)

    return render_template("view_post.html",
                           blog_title=blog.title,
                           blog_id=blog._id,
                           post=post)
Ejemplo n.º 11
0
def blog_posts(blog_id):
    blog = Blog.from_mongo(blog_id)
    # get all the posts of the current blog
    posts = blog.get_posts()
    return render_template('posts.html',
                           posts=posts,
                           blog_title=blog.title,
                           blog_id=blog._id)
Ejemplo n.º 12
0
 def _view_blog(self):
     blog_to_see = input("Enter the ID of the blog you'd like to read: ")
     blog = Blog.from_mongo(blog_to_see)
     posts = blog.get_posts()
     for post in posts:
         print(
             f"> > > >   < < < <\nDate: {post['created_date']}\nTitle: {post['title']}\n<\n{post['content']}\n>"
         )
 def _user_has_account(self):
     blog = Database.find_one('blogs', {'author': self.user})
     if blog is not None:
         #self.user_blog = blog #This would work however returning the object is better for this case
         self.user_blog = Blog.from_mongo(blog['id'])
         return True
     else:
         return False
Ejemplo n.º 14
0
def readblog_posts(blog_id):
    blog = Blog.from_mongo(blog_id)
    posts = blog.get_posts()

    return render_template("posts-readonly.html",
                           posts=posts,
                           blog_title=blog.title,
                           blog_id=blog._id)
Ejemplo n.º 15
0
 def new_post(self,
              blog_id,
              title,
              content,
              date=datetime.datetime.utcnow()):
     #title, content, author, created_date=datetime.datetime.utcnow()
     blog = Blog.from_mongo(blog_id)
     blog.new_post(title=title, content=content, date=date)
Ejemplo n.º 16
0
 def _view_blog(self):
     id_blog_to_view = input('Enter the ID of the blog')
     blog = Blog.from_mongo(id_blog_to_view)
     posts = blog.get_posts()
     for post in posts:
         print("Date: {}, title: {}\n\n{}".format(post['created_date'],
                                                  post['title'],
                                                  post['content']))
Ejemplo n.º 17
0
 def _view_blog(self):
     blog_to_see = input("Enter the ID of blog you'd like to read: ")
     blog = Blog.from_mongo(blog_to_see)
     posts = blog.get_posts()
     for post in posts:
         print("Date: {}, title: {}\n\n{}".format(post['created_date'],
                                                  post['title'],
                                                  post['content']))
Ejemplo n.º 18
0
def view_blog_posts(blog_id):
    blog = Blog.from_mongo(blog_id)
    posts = blog.get_posts()
    return render_template('view_posts.html',
                           posts=posts,
                           blog_id=blog._id,
                           blog_title=blog.title,
                           blog_description=blog.description)
Ejemplo n.º 19
0
    def new_post(self,blog_id,title,content,date=datetime.datetime.utcnow()):

        blog=Blog.from_mongo(blog_id)

        blog.new_post(title=title,
                      content=content,
                      date=date
                   )
Ejemplo n.º 20
0
def blog_posts(blog_id):
    if request.method == 'POST':
        return redirect(url_for('blog_posts', blog_id=blog_id))
    blog = Blog.from_mongo(blog_id)
    posts = blog.get_posts()
    return render_template('posts.html',
                           posts=posts,
                           blog_title=blog.title,
                           blog_id=blog._id)
Ejemplo n.º 21
0
 def _view_blogs(self):
     blog_to_see = input(
         "Enter the id of the block you would like to read: ")
     blog = Blog.from_mongo(blog_to_see)
     posts = blog.get_posts()
     for post in posts:
         print("Date: {}, Title: {}\n\n{}".format(post['creation_date'],
                                                  post['title'],
                                                  post['content']))
Ejemplo n.º 22
0
def blog_posts(blog_id):
    blog = Blog.from_mongo(blog_id)
    posts = blog.get_post()
    print(posts)

    return render_template('posts.html',
                           posts=posts,
                           blog_title=blog.title,
                           blog_id=blog_id)
Ejemplo n.º 23
0
def new_posts(blog_id):
    if request.method == "GET":
        return render_template("new_posts.html", blog_id=blog_id)
    else:
        blog = Blog.from_mongo(blog_id)

        blog.new_post(title=request.form['title'],
                      content=request.form['content'])
        print(request.form['title'])
        return make_response(get_posts(blog_id))
Ejemplo n.º 24
0
def blog_posts(blog_id):
    print(blog_id)
    blog = Blog.from_mongo(blog_id)
    posts = blog.get_posts()
    print(str(posts) + "posts")
    #length = print(len(posts))
    return render_template('posts.html',
                           posts=posts,
                           blog_title=blog.title,
                           blog_id=blog_id)
Ejemplo n.º 25
0
def blog_posts(blog_id):
    blog = Blog.from_mongo(blog_id)
    posts = blog.get_posts()
    about = About.get_by_user_id(blog.author_id)

    return render_template('posts.html',
                           posts=posts,
                           blog_title=blog.title,
                           blog_id=blog_id,
                           about=about)
Ejemplo n.º 26
0
    def new_post(self,
                 blog_id,
                 title,
                 content,
                 created_date=datetime.datetime.utcnow()):

        blog = Blog.from_mongo(blog_id)

        # pass args to blog method
        blog.new_post(title=title, content=content, created_date=created_date)
Ejemplo n.º 27
0
 def _user_has_account(self):  # Verify if user have already got an account
     blog = Database.find_one(
         'blogs',
         {'author': self.user})  # Find blog with author=self.author <- usr
     if blog is not None:
         self.user_blog = Blog.from_mongo(
             blog['_id']
         )  # self.blog = objeto Blog passando o id do blog que foi encontrado para esse usr
         return True
     else:
         return False  # Não existe Blog para esse nome de usr
Ejemplo n.º 28
0
def blog_posts(blog_id):

    blog = Blog.from_mongo(blog_id)

    posts = blog.get_posts()

    # need to pass in blog_id so that create_new_post.html has access
    return render_template('posts.html',
                           posts=posts,
                           blog_title=blog.title,
                           blog_id=blog_id)
Ejemplo n.º 29
0
def blog_posts(blog_id):
    # print("@app.py::blog_posts::blog_id: {}".format(blog_id))
    blog = Blog.from_mongo(blog_id)
    # print("@app.py::blog_posts::blog: {}".format(blog))
    posts = blog.get_posts()
    # print('@app.py::blog_posts::posts: {}'.format(posts))

    return render_template('posts.html',
                           posts=posts,
                           blog_title=blog.title,
                           blog_id=blog._id)
Ejemplo n.º 30
0
def new_post(blog_id):
    if request.method == 'GET':
        return render_template('new_post.html', blog_id=blog_id)
    else:
        title = request.form['title']
        abstract = request.form['abstract']
        content = request.form['content']

        blog = Blog.from_mongo(blog_id)
        blog.new_post(title, abstract, content)

        return redirect(f'/posts/{blog_id}')
Ejemplo n.º 31
0
def blog_posts(blog_id):
    blog = Blog.from_mongo(blog_id)
    user = User.get_by_id(blog.author_id)
    if user.email == session['email']:
        myPage = True
    else:
        myPage = False
    posts = blog.get_posts()

    return render_template('posts.html',
                           posts=posts,
                           blog_title=blog.title,
                           blog_id=blog._id,
                           myPage=myPage)
Ejemplo n.º 32
0
def update_blog(blog_id):
    if request.method == 'GET':
        return render_template('update_blog.html', blog_id=blog_id)
    else:
        title = request.form['title']
        description = request.form['description']
        existing_blog = Blog.from_mongo(blog_id)
        if str.strip(title) == "":
            title = existing_blog.title
        if str.strip(description) == "":
            description = existing_blog.description
        updated_blog = Blog(existing_blog.author, existing_blog.author_id,
                            title, description, existing_blog._id)
        updated_blog.update_blog(blog_id)
    return make_response(user_blogs())
Ejemplo n.º 33
0
def blog_posts(blog_id):
    blog = Blog.from_mongo(blog_id)
    posts = blog.get_posts()
    return render_template('posts.html', posts=posts, blog_title=blog.title, blog_id=blog._id)
 def _view_blog(self):
     blog_to_see = input("Enter the ID of the blog you'd like to read: ")
     blog= Blog.from_mongo(blog_to_see)
     posts = blog.get_posts()
     for post in posts:
         print("Date: {}, title:{}\n\n{}".format(post['created_date'], post['title'], post['content']))
Ejemplo n.º 35
0
 def new_post(blog_id, title, content, date=datetime.datetime.utcnow()): #blog_id to know which blog to save to. This is automated no need to input from user.
     # title, content, date=datetime.utcnow()
     blog = Blog.from_mongo(blog_id)
     blog.new_post(title=title,
                   content=content,
                   date=date) #This has save to mongodb so we do not need to add save here.