Ejemplo n.º 1
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
        """
            On posting comment, new comment tuple is created and stored,
            with relationship data of user and post.
        """
        c = ""
        if (self.user):
            # On clicking like, post-like value increases.
            if (self.request.get('like')
                    and self.request.get('like') == "update"):
                likes = db.GqlQuery("select * from Like where post_id = " +
                                    post_id + " and user_id = " +
                                    str(self.user.key().id()))

                if self.user.key().id() == post.user_id:
                    self.redirect("/blog/" + post_id +
                                  "?error=You cannot like your " + "post.!!")
                    return
                elif likes.count() == 0:
                    l = Like(parent=blog_key(),
                             user_id=self.user.key().id(),
                             post_id=int(post_id))
                    l.put()

            # On commenting, it creates new comment tuple
            if (self.request.get('comment')):
                c = Comment(parent=blog_key(),
                            user_id=self.user.key().id(),
                            post_id=int(post_id),
                            comment=self.request.get('comment'))
                c.put()
        else:
            self.redirect("/login?error=You need to login before " +
                          "performing edit, like or commenting.!!")
            return

        comments = db.GqlQuery("select * from Comment where post_id = " +
                               post_id + "order by created desc")

        likes = db.GqlQuery("select * from Like where post_id=" + post_id)

        self.render("permalink.html",
                    post=post,
                    comments=comments,
                    noOfLikes=likes.count(),
                    new=c)
Ejemplo n.º 2
0
    def post(self, post_id):
        if self.user:
            if 'main' in self.request.POST:
                self.redirect('/blog/%s' % str(post_id))
            elif 'sub' in self.request.POST:
                comment_text = self.request.get('comment')
                comment_elem = Comment(comment=comment_text,
                                       post_id=post_id,
                                       made_by=self.user.name)
                comment_elem.put()

                self.redirect('/blog/%s' % str(post_id))
        else:
            self.redirect('/blog/login')
Ejemplo n.º 3
0
	def post(self):
		p = Post.get(self.params['post_key'])
		spam = self.params.get('spam_breaker', None)
		if not spam or spam.lower().find("purple") == -1:
			self.redirect('/blog/view/%s/%s' % (p.posted_on.strftime("%Y%m%d"), p.slug))
			return
			
		c = Comment(post=p,
					author=self.params['author'],
					email=self.params.get('email', None),
					url=self.params.get('url', None),
					content=self.params['comment'])
		c.put()
		mailer.new_comment(p, c)
		self.redirect('/blog/view/%s/%s' % (p.posted_on.strftime("%Y%m%d"), p.slug))
Ejemplo n.º 4
0
 def post(self):
     book = Book.get_by_key_name("Book_" + self.request.get('book'))
     if not book: return
     body = self.request.get('body')
     if not body: return
     comment = Comment(
         book = book,
         body = body
         )
     comment.put()
     Activity(type='comment', book=book).put()
     user = users.get_current_user()
     template_values = {
         'comment': comment,
         'user': user,
         }
     path = os.path.join(os.path.dirname(__file__), '..', 'view', 'comment/index.html')
     result = template.render(path, template_values)
     self.response.out.write(result)
Ejemplo n.º 5
0
 def post(self):
     media=self.getMedia(self.request.get('key'))
     if media:
         comment=Comment()
         comment.title=self.request.get('title')
         u=users.get_current_user()
         if u:
             comment.by=u.nickname()
         else:
             comment.by="Mr. I'm too good to log in"
         comment.text=self.request.get('text')
         commentkey=self.request.get('commentkey')
         if commentkey:
             comment.op=Comment.get(commentkey)
         else:
             comment.media=media
         comment.put()
             
         template_values = {"media":media}
         path = os.path.join(os.path.dirname(__file__), '../html/details.html')
         shared.render(self, path, template_values)
Ejemplo n.º 6
0
            if post is None:
                raise TypeError
        # Respond with 404 - Not Found if we can't construct or get entity by the provided key
        # (Catch all errors, because it really doesn't matter what error we get when trying to construct
        # the key, since everything means that they provided key is invalid and fetching entity is not possible)
        except Exception, e:
            self.error(404)
            return
            
        # Create the comment entity
        comment = Anna_Comment(user_id = user.user_id(),
                               post_id = new_comment['post_id'],
                               content = new_comment['content'])

        # Push the comment to the database
        comment.put()
        
        # Create the list inside comments if this is the first comment
        if post.comments is None:
            post.comments = [comment.key]
        # Append the comment to the list if the list already exists
        else:
            post.comments.append(comment.key)
        
        # Push the comment with its list to the database
        post.put()

        # Respond with the created comments data
        self.response.headers['Content-type'] = 'application/json'
        self.response.out.write(json.dumps(comment.to_dict()))