示例#1
0
def text(f, id):
    article = Article(id)
    actions.browse(id)
    score = article.score()
    aaa = Article(id)
    a = aaa.content()
    c = Comment.queryComment(id)
    e = Evil_comment.query()
    comments = []
    for i in c:
        flag = True
        for j in e:
            if j[1] in i[2]:
                flag = False
        if flag == True:
            comments.append(i)
    n = len(comments)
    c = []
    for i in comments:
        comment = Comment(str(i[0]))
        i = list(i)
        i.append(actions.addr_protect(i[5]))
        i.append(comment.score())
        c.append(i)
    com = sorted(c, key=lambda s: s[0], reverse=True)
    addr = actions.addr_protect(a[0][2])
    return render_template('article.html',
                           content=a[0],
                           comments=com,
                           num=n,
                           addr=addr,
                           score=score)
示例#2
0
def search():
    if request.method == 'POST':
        keyword = request.form.get('keyword')
        keyword = str(keyword)
        if keyword == '':
            return redirect(url_for('index'))
        result, c = actions.searchinfo(keyword)
        result.reverse()
        b = Blacklist.query()
        blacklist = []
        articles = []
        for i in result:
            article = Article(str(i[0]))
            i = list(i)
            i.append(actions.addr_protect(i[2]))
            i.append(article.score())
            articles.append(i)
        comments = []
        for i in c:
            comment = Comment(str(i[0]))
            i = list(i)
            i.append(actions.addr_protect(i[5]))
            i.append(comment.score())
            i.append(actions.exchange(str(i[1])))
            comments.append(i)
        for i in b:
            blacklist.append(i[1])
        return render_template('search.html',
                               keyword=keyword,
                               articles=articles,
                               blacklist=blacklist,
                               comments=comments)
    else:
        return redirect(url_for('index'))
示例#3
0
def comment_down():
    if request.method == 'GET':
        id = request.args.get('id')
        id = re.sub("\D", "", id)
        i = Comment.voted_down(id)
        c = Comment(id)
        score = c.score()
        result = str(i) + ',' + str(score)
        return result
    else:
        pass
示例#4
0
 def post(self, post_id):
     message = self.request.get("message")
     p = Post.by_id(BLOG_KEY, post_id)
     if not message:
         error = "inform a valid comment, please"
         self.render("post-permalink.html", p=p, new_comment_error=error)
     else:
         comment = Comment(parent=p.key,
                           owner=self.user.key,
                           content=message)
         comment.put()
         self.redirect('/blog/%s' % post_id)
示例#5
0
def add_comment(forum, articleID):
    comment = request.form.get('comment')
    addr = request.form.get('addr')
    if actions.is_valid_email(addr) == False:
        return 'Sorry,it is not valid e-mail'
    b = Blacklist(addr)
    if b.is_in_blacklist():
        return 'Sorry,you are in black list'
    if Evil_comment.is_evil_comment(comment) == True:
        return 'Evil comment! Comment failed'
    if Comment.time_limit(addr) == 0:
        return 'You can not publish a article in a very short period. '
    Comment.addComment(articleID, comment, addr, forum)
    return redirect(url_for('text', f=forum, id=articleID))
示例#6
0
    def post(self, post_id):
        text = self.request.get('comment-text')
        params = dict(comment_text=text)

        post, post_id = get_post_from_request(self, post_id)
        if not post:
            return self.abort(404, "No post associated with request")
        params['post_id'] = post_id

        if text:
            # Creating comment
            comment = Comment(user=self.user.key, post=post.key, content=text)
            comment.put()

            self.redirect_to_uri("permalink", post_id=post_id)
        else:
            params['comment_error'] = "Comment cannot be empty"
            self.render_page(**params)
示例#7
0
    def post(self, post_id, comment_id):
        postKey = ndb.Key(Post, int(post_id), parent=BLOG_KEY)
        c = Comment.by_id(postKey, comment_id)
        own = c and c.is_owned_by(self.user)
        if own:
            c.key.delete()
        else:
            self.flash("you can't delete other's comments", "danger")

        self.redirect('/blog/%s#comments-section' % post_id)
示例#8
0
    def post(self, post_id, comment_id):
        postKey = ndb.Key(Post, int(post_id), parent=BLOG_KEY)
        comment = Comment.by_id(postKey, comment_id)
        if comment and comment.is_owned_by(self.user):
            message = self.request.get("message")
            if not message:
                error = "inform a valid comment, please"
                self.render("post-permalink.html",
                            p=postKey.get(),
                            comment_error={str(comment_id): error})
                return
            else:
                comment.content = message
                comment.put()
        else:
            self.flash("you can't edit other's comments", "danger")

        self.redirect("/blog/%s" % post_id)
示例#9
0
    def post(self, comment_id):
        text = self.request.get('comment-text')
        params = dict(comment_text=text)

        comment = Comment.get_by_id(int(comment_id))
        if not comment:
            return self.abort(404, "No comment associated with request")

        post_id = comment.post.id()
        params['post_id'] = post_id

        if text:
            comment.content = text
            comment.put()

            self.redirect_to_uri("permalink", post_id=post_id)
        else:
            params['comment_error'] = "Comment cannot be empty"
            self.render_page(**params)
示例#10
0
def make_comment_change(self, comment_id, edit, delete):
    """Checks permissions and allows to edit/delete comment"""

    if edit and delete:
        log_request(self, "Request with edit & delete comment")
        return self.abort(400, "Edit and delete simultaneosly forbidden")

    if not self.user:
        return self.redirect_to_uri("signup")

    comment = Comment.get_by_id(int(comment_id))
    if not comment:
        return self.abort(404, "No comment associated with request")

    key = comment.key

    if comment.user.id() == self.user.key.id():
        if edit:
            return self.redirect_to_uri("comment_edit", comment_id=key.id())
        elif delete:
            comment.key.delete()
            return self.redirect_to_uri("permalink", post_id=comment.post.id())
    log_request(self, "User tried to change comment of another user")
    return self.abort(403, "You cannot change other user comments")
示例#11
0
 def get(self, comment_id):
     comment = Comment.get_by_id(int(comment_id))
     if not comment:
         return self.abort(404, "No comment associated with request")
     self.render_page(post_id=comment.post.id(), content=comment.content)