예제 #1
0
    def get(self, post_id):
        post_key = db.Key.from_path('Post', int(post_id))
        post = db.get(post_key)

        #Get all comments for post id
        comments = Comment.all().filter('post =', post_key)
        comments.order("-created")

        #check if post exists
        if not self.post_exists(post_id):
            page_error = 'This post does not exist !'
            return self.render('login-form.html', page_error = page_error)


        user_id = self.read_secure_cookie('user_id')
        author_id = post.author.key().id()
        edit = False

        #check if logged in user is the author of the post
        #if the user is the author he can edit and/or delete the post
        if user_id:
            if (long(user_id) == author_id):
              edit = True



        #number of likes
        post = Post.by_id(post_id)
        likes = Like.all().filter('post =', post).count()

        self.render("permalink.html", post = post, comments = comments, edit = edit, likes = likes)
예제 #2
0
    def get(self, post_id, post_user_id):
        """ If the user is signed in and authored the post, delete the post and
        redirect the user to the homepage.  Otherwise, send non-signed in users
        to the login page. For all other cases go back to the current page with
        a permission error. """
        if self.user and self.user.key().id() == int(post_user_id):
            postkey = db.Key.from_path('Post', int(post_id), parent=blog_key())
            post = db.get(postkey)
            comments = Comment.all().filter('post =', postkey)
            likes = Like.all().filter('post_id =', post.key().id())

            if post:
                delete_dependents(comments=comments, likes=likes)
                post.delete()
                return self.redirect('/')

        elif not self.user:
            return self.redirect("/login")

        else:
            postkey = db.Key.from_path('Post', int(post_id), parent=blog_key())
            post = db.get(postkey)
            error_msg = "You do not have permission to delete this post"
            comments = db.GqlQuery(
            "select * from Comment where ancestor is :1 order by created desc limit 10", postkey) # NOQA

            self.render("permalink.html", post=post, comments=comments,
                        error_msg=error_msg)
예제 #3
0
def delete(request):
    weibo_id = int(request.query['id'])
    Weibo.delete(weibo_id)
    cs = Comment.all(weibo_id=weibo_id)
    for c in cs:
        Comment.delete(c.id)
    return redirect('/weibo/index')
예제 #4
0
 def all(cls, **kwargs):
     u = current_user()
     data = super().all(user_id=u.id, **kwargs)
     for d in data:
         comments = Comment.all(todo_id=d['id'])
         d['comments'] = comments
     return data
예제 #5
0
    def get(self, post_id):
        """ If user is signed in, lookup whether the user liked the post. Retrieve
        all comments for that post. Render permalink.html with the current user,
        post, comments, and the liked status for the current user. """
        postkey = db.Key.from_path('Post', int(post_id), parent=blog_key())
        post = db.get(postkey)
        comments = Comment.all().filter('post =', postkey)
        if self.user:
            user_id = self.user.key().id()
            likedpost = db.GqlQuery(
                "select * from Like where ancestor is :1 and user_id = :2",
                postkey, user_id)
            liked = likedpost.get()
        else:
            liked = None

        if not post:
            self.error(404)
            return

        self.render("permalink.html",
                    user=self.user,
                    post=post,
                    comments=comments,
                    liked=liked)
예제 #6
0
def delete(request):
    weibo_id = int(request.query['id'])
    Weibo.delete(weibo_id)
    # 注意删除所有微博对应评论
    cs = Comment.all(weibo_id=weibo_id)
    for c in cs:
        c.delete()
    return redirect('/weibo/index')
예제 #7
0
def delete(request):
    weibo_id = int(request.query['id'])
    c = Comment.all(weibo_id=weibo_id)
    for i in c:
        i.delete(i.id)
    Weibo.delete(weibo_id)
    d = dict(message="成功删除 weibo")
    return json_response(d)
예제 #8
0
def delete():
    weibo_id = int(request.args['id'])
    Weibo.delete(weibo_id)
    comments = Comment.all(id=weibo_id)
    # log('AAAA', comments)
    for comment in comments:
        # log('BBB', comment['id'])
        Comment.delete(comment.id)
    d = dict(message="成功删除 weibo")
    return jsonify(d)
예제 #9
0
def all(request):
    w = Weibo.all()
    for i in w:
        c = Comment.all(weibo_id=i.id)
        x = [t.json() for t in c]
        s = json.dumps(x, ensure_ascii=False)
        i.comment = s
        i.save(i.__dict__)
    weibos = Weibo.all_json()
    return json_response(weibos)
예제 #10
0
def delete(request):
    log('routes weibo delete')
    weibo_id = int(request.query['id'])

    cs = Comment.all(weibo_id=weibo_id)
    for c in cs:
        c.delete(c.id)

    Weibo.delete(weibo_id)

    return redirect('/weibo/index')
예제 #11
0
def delete(request):
    log('<F weibo delete>')
    Weibo_id = int(request.query['weibo_id'])
    comments = Comment.all(weibo_id=Weibo_id)
    if len(comments) != 0:
        for comment in comments:
            comment.delete(comment.id)
    Weibo.delete(Weibo_id)

    d = dict(message="成功删除 Weibo")
    return json_response(d)
예제 #12
0
def weibo_delete(request):
    '''
    删除浏览器发送数据对应的 weibo
    返回删除成功的信息
    '''
    weibo_id = int(request.query['id'])
    # 循环遍历该 weibo 所有评论,并删除
    comments = Comment.all(weibo_id=weibo_id)
    for comment in comments:
        Comment.delete(comment.id)
    Weibo.delete(weibo_id)
    d = dict(message="成功删除 weibo")
    return json_response(d)
예제 #13
0
def weibo_all(request):
    """
    返回 json 格式的所有 weibo 数据
    """
    weibos = Weibo.all_to_dict()
    for weibo in weibos:
        # 获取每条 weibo 对应所有评论
        comments = Comment.all(weibo_id=int(weibo['id']))
        comments_dict = [comment.to_dict() for comment in comments]

        # 使每个 weibo 对象带上对应的评论数据
        weibo['comments'] = comments_dict
    return json_response(weibos)
예제 #14
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
     comments=Comment.all().filter('post_fk =',post.key()).order('-created')      
     likes=db.GqlQuery("select * from Vote where post_id_fk="+post_id+" and content='Like'")
     unlikes=db.GqlQuery("select * from Vote where post_id_fk="+post_id+" and content='Unlike'")
     likecount=str(likes.count())
     unlikecount=str(unlikes.count())
     logging.info("test: "+likecount)
     self.render("permalink.html", post = post, comments=comments,likecount=likecount,unlikecount=unlikecount)
예제 #15
0
def delete(request):
    weibo_id = int(request.query['id'])
    Weibo.delete(weibo_id)

    comments = Comment.all()
    for c in comments:
        if c.weibo_id == weibo_id:
            comment_id = c.id
            Comment.delete(comment_id)

    d = dict(
        message="成功删除 weibo"
    )
    return json_response(d)
예제 #16
0
def index():
    comments = Comment.all()
    return render_template('comment_new.html', comments=comments)
예제 #17
0
 def comments(self):
     cs = Comment.all(weibo_id=self.id)
     return cs
예제 #18
0
파일: weibo.py 프로젝트: etlRlks/web_server
 def comments(self):
     # log('self id', self.id)
     cs = Comment.all(weibo_id=self.id)
     return cs
예제 #19
0
 def comments(self):
     return Comment.all().filter("post = ", str(self.key().id()))
예제 #20
0
def comment_all(request):
    comment_list = Comment.all()
    # 要转换为 dict 格式才行
    comments = [t.json() for t in comment_list]
    return json_response(comments)
예제 #21
0
 def delete_all(cls, id):
     Weibo.delete(id)
     comments = Comment.all(weibo_id=id)
     for comment in comments:
         # 使用了delete
         Comment.delete(comment.id)