def super_put_comment(id):
    data = request.json or {}
    data['id'] = id
    data['userId'] = g.user.id
    SuperPutCommentForm(data=data).validate_for_api()
    CommentModel.put_comment(data=data)
    return Success(msg='修改评论成功!')
Exemple #2
0
 def validate_id(self, value):
     try:
         id = ObjectId(value.data)
     except:
         raise ValueError('评论id无效!')
     comment = CommentModel.objects(id=id).first()
     if not comment:
         raise ValueError('评论id无效!')
Exemple #3
0
def create_posts():
    """ generate random posts """
    for i in range(150):
        tag = [ Tags[random_number(0,len(Tags)-1)], Tags[random_number(0,len(Tags)-1)] ]
        post = " ".join(map(''.join, zip(*[iter(id_generator(500))]*random_number())))
        description = " ".join(map(''.join, zip(*[iter(id_generator(100))]*random_number())))
        title = " ".join(map(''.join, zip(*[iter(id_generator(25))]*random_number())))
        slugid = slugify(title) # check if this already exists - if so, throw or pass
        pm = PostModel( Title = title, Post=post, Tags=tag, Description=description, Published=True, id=slugid )
        pm.put()
        postId = pm.key.id()
        for tg in tag:
            TagModel.create_or_update_tag(tg)
        for i in xrange(random_number(3,15)):
            comment = " ".join(map(''.join, zip(*[iter(id_generator(100))]*random_number())))
            username = id_generator(random_number(6,15))
            email = ".".join([ "@".join([username, id_generator(random_number(5,10))]), "com" ])
            cm = CommentModel( Name=username, Email=email, Comment=comment, SlugId=slugid, Published=True )
            cm.put()
def get_comment_list():
    data = request.args
    form = GetCommentListForm(data=data)
    form.validate_for_api()
    data = {
        "topicId": form.topicId.data,
        'page': form.page.data,
        'size': form.size.data
    }
    data = CommentModel.get_comment_list(data)
    return Success(msg='获取成功!', data=data)
Exemple #5
0
 def validate_id(self, value):
     try:
         id = ObjectId(value.data)
     except:
         raise ValueError('评论id无效!')
     comment = CommentModel.objects(id=id).first()
     if not comment:
         raise ValueError('评论id无效!')
     userId = self.userId.data
     if str(comment['userId']['id']) != userId:
         raise ValueError('违规操作!')
Exemple #6
0
def single_post(slug):
    """ given a slug, display the related page """
    context = _get_post_context(slug)
    commentform = CommentForm()
    if commentform.validate_on_submit():
        try:
            ncomment = CommentModel.create_comment(commentform, slug)
            return redirect(url_for('single_post', slug=slug))
        except Exception as e:
            return redirect(url_for('error404'))
    context.update({'commentform':commentform})
    context.update( _explorerInfo(url_for('single_post', slug=slug)) )
    return render_page_or_error('single_post.html', context)
def super_delete_comment(id):
    data = {"id": id}
    SuperDeleteCommentForm(data=data).validate_for_api()
    CommentModel.delete_comment(id)
    return Success(msg='删除评论成功!')
def delete_comment(id):
    data = {"id": id, "userId": g.user.id}
    DeleteCommentForm(data=data).validate_for_api()
    CommentModel.delete_comment(id)
    return Success(msg='删除评论成功!')
def post_comment():
    data = request.json or {}
    data['userId'] = g.user.id
    PostCommentForm(data=data).validate_for_api()
    CommentModel.add_comment(data=data)
    return Success(msg='添加评论成功!')
Exemple #10
0
def _post_tasklet(slug):
    post, comments = yield PostModel.get_by_id_async(slug), CommentModel.get_comment_by_slug_async(slug)
    raise ndb.Return((post, comments))