Ejemplo n.º 1
0
    def post(self):
        """
        Removes a post entry if user is authenticated, 
        if no redirects to login route
        :return: 
        """
        post_id = self.request.get('id')

        post = Post.get_by_id(post_id)

        if Post.is_post_owner(self.request.cookies.get('user_id'), post):
            post.key.delete()
            time.sleep(2)

        self.redirect('/main')
Ejemplo n.º 2
0
    def post(self):
        """
        Creates or update a new post entry if user is 
        authenticated, if no redirects to login route
        :return: 
        """
        user_id = self.request.cookies.get('user_id')
        post_id = self.request.get('id')
        title = self.request.get('title')
        content = self.request.get('content')

        if 'update' in self.request.POST:
            post = Post.get_by_id(post_id)

            if Post.is_post_owner(user_id, post):
                post.title = title
                post.content = content
                post.last_modified = datetime.datetime.now()

                post.put()

                time.sleep(2)
        elif 'create' in self.request.POST:
            title = self.request.get('title')
            content = self.request.get('content')

            user = User.get_by_hash(user_id)

            p = Post(author=user.user,
                     title=title,
                     content=content,
                     created=datetime.datetime.now(),
                     last_modified=datetime.datetime.now())
            p.put()

            time.sleep(2)

        self.redirect('/main')
 def can_unlike(self, user, post):
     return not Post.is_post_owner(user.hash, post) \
            and 'unlike' in self.request.POST \
            and user.user in post.likes