Esempio n. 1
0
    def get(self, post_id):
        if not self.user:
            return self.redirect('/login')
        else:
            key = db.Key.from_path('Post', int(post_id), parent=blog_key())
            post = db.get(key)
            author = post.author
            loggedUser = self.user.name

            if author == loggedUser:
                key = db.Key.from_path('Post', int(post_id), parent=blog_key())
                post = db.get(key)
                post.delete()
                self.render("delete.html")
            else:
                self.redirect("/")
Esempio n. 2
0
  def get(self):
    query = Post.query(ancestor=blog_key(DB_NAME)).order(-Post.date)
    posts = query.fetch()

    self.generate("admin/blog_all.html", {
      "posts": posts,
    })
Esempio n. 3
0
    def get(self, post_id):
        key = db.Key.from_path('Post', int(post_id), parent=blog_key())
        post = db.get(key)

        if not post:
            self.error(404)
            return

        self.render("permalink.html", post=post)
Esempio n. 4
0
    def get(self, post_id):
        if not self.user:
            return self.redirect('/login')
        else:
            key = db.Key.from_path('Post', int(post_id), parent=blog_key())
            post = db.get(key)
            author = post.author
            loggedUser = self.user.name

            if author == loggedUser:
                key = db.Key.from_path('Post', int(post_id), parent=blog_key())
                post = db.get(key)
                error = ""
                self.render("edit.html", subject=post.subject,
                            content=post.content, error=error)
            else:
                error = "you can't edit this"
                self.redirect("/error", error=error)
Esempio n. 5
0
 def post(self, post_id):
     if not self.user:
         return self.redirect("/login")
     else:
         key = db.Key.from_path('Post', int(post_id), parent=blog_key())
         p = db.get(key)
         p.subject = self.request.get('subject')
         p.content = self.request.get('content')
         p.put()
         self.redirect('/blog/%s' % str(p.key().id()))
Esempio n. 6
0
 def get(self, post_id):
     if not self.user:
         return self.redirect("/login")
     post = Post.get_by_id(int(post_id), parent=blog_key())
     subject = post.subject
     content = post.content
     comment = self.request.get('comment')
     author = self.request.get('author')
     self.render("comments.html", subject=subject, content=content,
                 author=author, comment=comment, pkey=post.key())
Esempio n. 7
0
    def post(self, post_id):
        """
        Loops through the posts
        """
        key = ndb.Key('Post', int(post_id), parent=models.blog_key())
        post = key.get()

        if not post:
            self.error(404)
            return
        self.render("post.html", posts=posts)
Esempio n. 8
0
 def get(self, post_id):
     key = ndb.Key('Post', int(post_id), parent=models.blog_key())
     post = key.get()
     if not post:
         self.error(404)
         return
     if self.user:
         self.render('deletepost.html', post=post)
     else:
         error = "In order to delete post, please login into the site"
         self.render('login.html', error=error)
Esempio n. 9
0
    def get(self, post_id):
        """
        Renders Posts to home page
        """
        key = ndb.Key('Post', int(post_id), parent=models.blog_key())
        post = key.get()
        like_obj = Like.query(Like.post == post.key)

        if not post:
            self.error(404)
            return
        self.render("permalink.html", post=post)
Esempio n. 10
0
 def get(self, post_id, comment_id):
     if not self.user:
         return self.redirect('/login')
     error = ""
     post = Post.get_by_id(int(post_id), parent=blog_key())
     comment = Comment.get_by_id(int(comment_id), parent=self.user.key())
     if comment:
         comment.delete()
         self.redirect('/blog/%s' % str(post_id))
     else:
         error = "Please only delete your own comment"
         self.render('permalink.html', error=error, post=post)
Esempio n. 11
0
    def get(self, post_id):
        key = ndb.Key('Post', int(post_id), parent=models.blog_key())
        post = key.get()

        if self.user:
            if post.author.id() != self.user.key.id():
                self.redirect('/blog/%s' % str(post.key.id()))
            else:
                self.render("editpost.html",
                            subject=post.subject,
                            content=post.content)
        else:
            error = 'You must login to view the post'
            self.render('login.html', error=error)
    def post(self, post_id):
        key = ndb.Key("Post", int(post_id), parent=blog_key())
        post = key.get()

        uid = self.read_secure_cookie("user_id")
        user = uid and User.by_id(int(uid))

        subject = self.request.get("subject")
        content = self.request.get("content")

        if user and (post.submitter_id == int(uid)):
            post.subject, post.content = subject, content
            post.put()
            self.redirect("/blog/{}".format(str(post.key.integer_id())))
        else:
            self.redirect("/login")
    def get(self, post_id):
        key = ndb.Key("Post", int(post_id), parent=blog_key())
        post = key.get()

        if not post:
            self.error(404)
            return

        uid = self.read_secure_cookie("user_id")
        user = uid and User.by_id(int(uid))

        if user:
            username = user.name
            self.render("edit_post.html", username=username, post=post)
        else:
            self.render("edit_post.html", post=post)
Esempio n. 14
0
    def post(self):
        if not self.user:
            return self.redirect('/login')

        subject = self.request.get('subject')
        content = self.request.get('content')
        author = self.request.get('author')
        comment = self.request.get('comment')
        if subject and content:
            p = Post(parent=blog_key(), subject=subject,
                     content=content, author=author, comment=comment, likes=0, liked_by=[])
            p.put()
            self.redirect('/blog/%s' % str(p.key().id()))
        else:
            error = "subject and content, please!"
            self.render("newpost.html", subject=subject,
                        content=content, error=error, comment=comment)
    def post(self, comment_id):

        uid = self.read_secure_cookie("user_id")
        user = uid and User.by_id(int(uid))

        post_id = self.request.get("post_id")
        key = ndb.Key("Post", int(post_id), parent=blog_key())
        post = key.get()

        if user:
            if int(uid) == post.submitter_id:
                key.delete()
                self.redirect("/blog/")
            else:
                error = "You can only delete your post, please understand..."
                self.render("permalink.html", post=post, error=error)
        else:
            error = "Please login to delete your post..."
            self.redirect("/login")
Esempio n. 16
0
    def post(self, post_id):

        key = db.Key.from_path('Post', int(post_id), parent=blog_key())
        post = db.get(key)

        if not post:
            self.error(404)
            return
        if not self.user:
            return self.redirect('login')
        author = self.request.get('author')
        comment = self.request.get('comment')
        if comment:
            c = Comment(comment=comment, post=post_id,
                        author=author, parent=self.user.key())
            c.put()
            self.redirect('/blog/%s' % str(post_id))
        else:
            self.render("permalink.html", post=post,
                        content=content, author=author, error=error)
    def get(self, post_id):
        key = ndb.Key("Post", int(post_id), parent=blog_key())
        post = key.get()
        comments = Comment.query(
            Comment.post_id_comment_belongs == int(post_id))

        if not post:
            self.error(404)
            return

        uid = self.read_secure_cookie("user_id")
        user = uid and User.by_id(int(uid))

        if user:
            username = user.name
            self.render("permalink.html",
                        username=username,
                        post=post,
                        comments=comments)
        else:
            self.render("permalink.html", post=post, comments=comments)
Esempio n. 18
0
    def get(self, post_id):
        if not self.user:
            return self.redirect('/login')
        else:
            key = db.Key.from_path('Post', int(post_id), parent=blog_key())
            post = db.get(key)
            author = post.author
            logged_user = self.user.name

            if author == logged_user:
                error = "You can't like your own post"
                self.render('error.html', error=error)

            elif logged_user in post.liked_by:
                error = "You can only like this once!"
                self.render('error.html', error=error)
            else:
                post.likes += 1
                post.liked_by.append(logged_user)
                post.put()
                self.redirect("/blog")
Esempio n. 19
0
    def post(self):
        if not self.user:
            return self.redirect('/login')

        subject = self.request.get('subject')
        content = self.request.get('post_text')

        if subject and content:
            p = Post(parent=models.blog_key(),
                     subject=subject,
                     content=content,
                     author=self.user.key)
            p.put()
            self.redirect('/')
            self.redirect('/blog/%s' % str(p.key.integer_id()))
        else:
            error = "Please enter Subject and Content"
            self.render("newpost.html",
                        subject=subject,
                        content=content,
                        error=error)
Esempio n. 20
0
    def post(self, post_id):
        """
        Creates the new comment on single page
        """
        if not self.user:
            return self.redirect('/login')

        key = ndb.Key('Post', int(post_id), parent=models.blog_key())
        post = key.get()

        if not post:
            return self.redirect('/')

        content = self.request.get('comment')
        if content:
            c = Comment(post=post.key, content=content, author=self.user.key)
            c.put()
            time.sleep(0.1)
            self.redirect('/blog/%s' % str(post_id))
        else:
            error = "enter valid comment"
            self.render("editcomment.html", content=content, error=error)
Esempio n. 21
0
    def post(self, post_id):
        if not self.user:
            return self.redirect('/login')

        key = ndb.Key('Post', int(post_id), parent=models.blog_key())
        post = key.get()
        userid = self.read_secure_cookie('user_id')
        subject = self.request.get('subject')
        content = self.request.get('post_text')

        if subject and content:
            post.subject = subject
            post.content = content
            post.put()
            time.sleep(0.1)
            self.redirect('/')
        else:
            error = "Please enter Subject and Content"
            self.render("editpost.html",
                        subject=subject,
                        content=content,
                        error=error)
    def post(self, post_id):
        posts = Post.query().order(-Post.created)
        posts = posts.fetch(10)

        uid = self.read_secure_cookie("user_id")
        user = uid and User.by_id(int(uid))

        key = ndb.Key("Post", int(post_id), parent=blog_key())
        post = key.get()

        like_for_post = LikeForPost.query(
            LikeForPost.like_post_id == int(post_id)).get()
        logging.warning("like for post is set.")

        if user:
            if like_for_post and (not (int(uid) in like_for_post.liked_user_id_list)) \
                    and (post.submitter_id != int(uid)):

                like_for_post.number_of_liked += 1
                like_for_post.liked_user_id_list.append(int(uid))
                like_for_post.put()
                self.redirect("/blog")

            elif post.submitter_id == int(uid):
                self.redirect("/blog")

            elif like_for_post:
                self.redirect("/blog")

            # create new like for certain post if above condition not match.
            else:
                l = LikeForPost(number_of_liked=1,
                                like_post_id=int(post_id),
                                liked_user_id_list=[int(uid)])
                l.put()
                self.redirect("/blog")
        else:
            self.redirect("/blog")
Esempio n. 23
0
    def post(self):
        """
        Takes the subject and content strings. If there's data in
        both, creates the post and navigates to the static post page.
        Otherwise, renders the page with the error.
        """
        subject = self.request.get("subject")
        content = self.request.get("content")

        self.check_cancel_edit()

        if subject and content:
            post = models.BlogPosts(parent=models.blog_key(),
                                    subject=subject,
                                    content=content,
                                    created_user_id=(str(
                                        self.user.key().id())))
            post.put()

            self.redirect("/%s" % post.key().id())
        else:
            error = "We need both a subject and some content!"
            self.render_new_post(subject, content, error)
    def post(self):
        subject = self.request.get("subject")
        content = self.request.get("content")

        uid = self.read_secure_cookie("user_id")
        user = uid and User.by_id(int(uid))

        if user:
            if subject and content:
                p = Post(parent=blog_key(),
                         subject=subject,
                         content=content,
                         submitter_id=int(uid))
                p.put()
                self.redirect("/blog/{}".format(str(p.key.integer_id())))
            else:
                error = "subject and content please!"
                self.render("newpost.html",
                            subject=subject,
                            content=content,
                            error=error)
        else:
            error = "Please login to post new..."
            self.redirect("/login")
Esempio n. 25
0
 def post(self):
   post = Post(parent=blog_key(DB_NAME))
   post.title = self.request.get('title')
   post.content = self.request.get('content')
   post.put()
   self.redirect('/admin/blog')