示例#1
0
    def post(self, post_id):
        if self.login_check():
            self.login_handler('permalink.html', post=Post.by_id(post_id))
        elif self.request.get('comment-form'):
            post = Post.by_id(post_id)
            comments = Comment.all_comments(post)
            if self.user:
                content = self.request.get('content')

                if not content:
                    self.render('permalink.html',
                                post=post,
                                comments=comments,
                                number_comments=post.comments,
                                content_error=True)
                else:
                    post = Post.by_id(post_id)
                    comment = Comment(author=self.user.username,
                                      content=content,
                                      parent=post)
                    comment.put()
                    post.comments += 1
                    post.put()
                    self.redirect('/post/%s#comments-section' % post_id)
            else:
                self.render('permalink.html',
                            post=post,
                            comments=comments,
                            number_comments=post.comments,
                            comment_error=True)
示例#2
0
    def post(self):
        subject = self.request.get('subject')
        content = self.request.get('content')

        subject_error = ''
        content_error = ''

        if not subject:
            subject_error = 'Please enter a subject.'
        if not content:
            content_error = 'Please enter content for the post.'
        if subject_error or content_error:
            self.render('newpost.html',
                        subject_error=subject_error,
                        content_error=content_error,
                        subject=subject,
                        content=content,
                        new_post=True)
        else:
            post = Post(author=self.user.username,
                        subject=subject,
                        content=content,
                        likes=0,
                        comments=0)
            post.put()
            self.redirect('/post/%s?new_post=true' % post.key().id())
示例#3
0
    def post(self, post_id):
        subject = self.request.get('subject')
        content = self.request.get('content')
        post = Post.by_id(post_id)

        subject_error = ''
        content_error = ''

        if not subject:
            subject_error = 'Please enter a subject.'
        if not content:
            content_error = 'Please enter content for the post.'
        if subject_error or content_error:
            self.render('newpost.html',
                        subject_error=subject_error,
                        content_error=content_error,
                        subject=subject,
                        content=content,
                        edit_post=True,
                        author=post.author,
                        created=post.created,
                        post_id=post_id,
                        original_subject=post.subject)
        else:
            if subject:
                post.subject = subject
            if content:
                post.content = content

            post.modified = datetime.datetime.now()
            post.put()
            self.redirect('/post/%s?edited_post=true' % post.key().id())
示例#4
0
	def get(self, post_id):
		post = Post.by_id(post_id)
		comment_id = self.request.get('comment')
		comment = Comment.by_id(comment_id, post)
		comment.delete()
		post.comments -= 1
		post.put()
		self.redirect('/post/%s#comments-section' % post_id)
示例#5
0
	def post(self):
		comment_id = int(self.request.get('commentId'))
		post_id = int(self.request.get('postId'))
		post = Post.by_id(post_id)
		comment = Comment.by_id(comment_id, post)

		if self.user.username == comment.author:
			comment.content = self.request.get('newContent')
			comment.put()
		else:
			self.redirect('/')
示例#6
0
    def get(self, post_id):
        new_post = self.request.get('new_post')
        edited_post = self.request.get('edited_post')
        post = Post.by_id(post_id)
        comments = Comment.all_comments(post)

        self.render('permalink.html',
                    post=post,
                    new_post=new_post,
                    edited_post=edited_post,
                    comments=comments,
                    number_comments=post.comments)
示例#7
0
 def get(self, post_id):
     post = Post.by_id(post_id)
     if self.user:
         if post.author == self.user.username:
             self.render('newpost.html',
                         edit_post=True,
                         author=post.author,
                         original_subject=post.subject,
                         content=post.content,
                         created=post.created,
                         post_id=post_id,
                         subject=post.subject)
         else:
             self.redirect('/')
     else:
         self.redirect('/')
示例#8
0
 def get(self, post_id):
     if self.user:
         post = Post.by_id(post_id)
         subject = post.subject
         if post.author == self.user.username:
             comments = Comment.all_comments(post)
             for comment in comments:
                 comment.delete()
             likes = Like.all_likes(post)
             for like in likes:
                 like.delete()
             self.render('delete.html', subject=subject, delete_post=True)
             post.delete()
         else:
             self.redirect('/')
     else:
         self.redirect('/')
示例#9
0
    def post(self):
        post_id = int(self.request.get('postId'))
        vote_value = int(self.request.get('voteValue'))
        post = Post.by_id(post_id)
        new_like_value = post.likes + vote_value

        if self.user:
            user_id = int(self.user.key().id())
            if self.user.username == post.author:
                self.write(
                    json.dumps({'error': "You can't like your own posts."}))
            elif Like.check_previous_likes(user_id, post):
                self.write(
                    json.dumps(
                        {'error': "You can't like a post multiple times."}))
            else:
                new_like = Like(user_id=user_id, value=vote_value, parent=post)
                new_like.put()
                post.likes = new_like_value
                post.put()
                self.write(json.dumps({'likes': new_like_value}))
        else:
            self.write(
                json.dumps({'error': "You must be logged in to like a post."}))
示例#10
0
 def post(self):
     self.login_handler('mainpage.html', posts=Post.most_recent())
示例#11
0
 def get(self):
     self.render('mainpage.html', posts=Post.most_recent())