Exemple #1
0
    def post(self, post_id):
        if not self.user:
            self.redirect('/blog/login')
            return

        if self.request.POST.get('save_post'):
            post_bundle = PostService.get_post_bundle(
                post_id=int(post_id),
                user=self.user
            )

            new_post, error_msg = PostService.update_post(
                post_id=int(post_id),
                user_id=int(self.user.key().id()),
                subject=self.request.get('subject'),
                content=self.request.get('content')
            )

            if error_msg:
                self.render('editpost.html',
                            error=error_msg,
                            **post_bundle._asdict()
                            )
                return

        self.redirect('/blog/' + post_id)
Exemple #2
0
 def get(self, post_id):
     post_bundle = PostService.get_post_bundle(  # getting the data bundle required to render the page
         post_id=int(post_id),
         user=self.user)
     self.render("showpost.html",
                 **post_bundle._asdict()
                 )
Exemple #3
0
 def get(self, post_id):
     post_bundle = PostService.get_post_bundle(
         post_id=int(post_id),
         user=self.user
     )
     self.render("editpost.html",
                 error='',
                 **post_bundle._asdict()
                 )
Exemple #4
0
    def post(self, comment_id):
        if not self.user:
            self.redirect('/blog/login')
            return

        if self.request.POST.get('save_comment'):
            new_comment, error_msg = PostService.update_comment(
                comment_id=int(comment_id),
                user_id=int(self.user.key().id()),
                content=self.request.get('content')
            )

            if error_msg:
                self.render('editcomment.html',
                            error=error_msg,
                            comment_id=comment_id
                            )
            else:
                time.sleep(0.5)
                self.redirect('/blog/' + str(new_comment.post_id))
        else:
            comment = Comment.get_by_id(int(comment_id))
            self.redirect('/blog/' + str(comment.post_id))
Exemple #5
0
 def post(self):
     title = self.get_argument("title", None)
     content = self.get_argument("content", None)
     post = PostService.add(title, content)
     self.write(post)
Exemple #6
0
 def get(self):
     posts = PostService.get_list()
     self.render('index.html', posts=posts)
def list_recent():
    return PostService().list_recent(request.get_json())
def list_particular():
    return PostService().list_particular(request.get_json())
def retrieve_post():
    return PostService().retrieve_post(request.get_json())
Exemple #10
0
def delete_post():
    return PostService().delete_post(request.get_json())
Exemple #11
0
def create_post():
    return PostService().create_post(request.get_json())
Exemple #12
0
    def post(self, post_id):
        if not self.user:
            self.redirect('/blog/login')
            return

        # get all the data
        post_bundle = PostService.get_post_bundle(
            post_id=int(post_id),
            user=self.user)
        error_msg = ''

        # checking which button was pressed
        if self.request.POST.get('submit_comment'):
            comment = self.request.get('comment_content')
            if comment:
                new_comment = PostService.add_comment(
                    comment=self.request.get('comment_content'),
                    post_id=int(post_id),
                    user_id=self.user.key().id()
                )
                # updating the bundle with the new comment
                post_bundle.comments.insert(0, new_comment)
            else:
                error_msg = "Please enter a comment"

        elif self.request.POST.get('update_comment'):
            comment_id = self.request.POST.get('comment_id')
            comment_author = int(self.request.POST.get('comment_author'))
            if comment_author != self.user.key().id():
                error_msg = "You can edit only your own comments"
            else:
                self.redirect('/blog/editcomment/' + str(comment_id))

        elif self.request.POST.get('edit_post'):
            if post_bundle[0].created_by != self.user.key().id():
                error_msg = "You can edit only your own posts"
            else:
                self.redirect('/blog/editpost/' + str(post_id))

        elif self.request.POST.get('like'):
            new_like, error_msg = PostService.like_update(
                post_id=int(post_id),
                user_id=self.user.key().id()
            )
            # updating the bundle with the new like
            post_bundle = post_bundle._replace(like=new_like)

        elif self.request.POST.get('delete_comment'):
            comment_id = self.request.POST.get('comment_id')
            updated_comments, error_msg = PostService.delete_comment(
                post_id=int(post_id),
                comment_id=int(comment_id),
                user_id=self.user.key().id()

            )
            # updating the bundle updated list of comments
            post_bundle = post_bundle._replace(comments=updated_comments)

        elif self.request.POST.get('delete_post'):
            posts, error_msg = PostService.delete_post(
                post_id=int(post_id),
                user_id=self.user.key().id()
            )
            if not error_msg:
                time.sleep(0.5)
                self.redirect('/blog')
                return

        self.render('showpost.html',
                    error=error_msg,
                    **post_bundle._asdict())  # passing the bundle as dictionary