Exemple #1
0
def test_weibo():
    # add
    form = dict(
        content='hello',
    )
    user_id = 1
    Weibo.add(form, user_id)

    # update
    form = dict(
        id=1,
        content='well done',
        user_id=1,
    )
    weibo_id = 1
    Weibo.update(weibo_id, **form)

    # comments
    w = Weibo.one(id=1)
    form = dict(
        content='hello',
        weibo_id=1,
    )
    c = Comment(form)
    c.add(1)
    form = dict(
        content='hello233',
        weibo_id=1,
    )
    c = Comment(form)
    c.add(1)

    cs = w.comments()
    log('test comments cs', cs)
Exemple #2
0
def comment_add(request):
    """
    用于增加新 todo 的路由函数
    """
    form = request.form()
    u = current_user(request)
    Comment.add(u.id, form)
    return redirect('/weibo')
Exemple #3
0
def comment_add(request):
    """
    添加评论
    """
    u = current_user(request)
    form = request.form()
    c = Comment(form)
    c.add(u.id)

    log('comment add', c, u, form)
    return redirect('/weibo/index')
Exemple #4
0
def comment_add():
    u = current_user()
    form = request.form.to_dict()

    # 发邮件
    content = form['content']
    users = users_from_content(content)
    send_mails(u, users, content)

    Comment.add(form, user_id=u.id)
    blog_id = form['blog_id']
    return redirect(url_for('routes_blog.detail', blog_id=blog_id))
Exemple #5
0
def comment_add():
    form = request.get_json()
    log(form)
    todo = Todo.one(id=form['id'])
    if todo is not None:
        c = Comment.add(form)
        return render_json(c)
Exemple #6
0
    def test_get_comments_by_card_id(self):
        uid0 = User.add("test1", "password", "*****@*****.**")
        bid0 = Board.add("board1", "A")
        lid0 = List.add("To Do", bid0)

        caid0 = Card.add("card1", lid0, uid0)
        caid1 = Card.add("card2", lid0, uid0)

        coid0 = Comment.add(caid0, uid0, "comment1")
        coid1 = Comment.add(caid1, uid0, "comment2")

        comment0 = Comment.get(coid0)
        comment1 = Comment.get(coid1)

        assert coid0 in [comment.id for comment in Comment.get_comments_by_card_id(caid0)]
        assert coid1 not in [comment.id for comment in Comment.get_comments_by_card_id(caid0)]
Exemple #7
0
def add_comment(post_id, comment_body, user, parent_id=None):

    post = Post.get_by_id(post_id)
    if parent_id is not None:
        parent = Comment.get_by_id(parent_id).key

    comment = Comment()
    comment.add(text=comment_body,
                author=user,
                post=post.key,
                parent=None if parent_id is None else parent)

    if post.num_comments is None:
        post.num_comments = 0

    post.num_comments += 1
    post.put()
Exemple #8
0
def comment_add():
    log('添加评论')
    form = request.get_json()
    u = current_user()
    w = Weibo.find_by(id=int(form['weibo_id']))
    c = Comment.add(form, u.id, u.username, w.id)
    # log('c---', c)
    return jsonify(c.json())
def add(request):
    # 得到浏览器发送的表单, 浏览器用 ajax 发送 json 格式的数据过来
    # 所以这里我们用新增加的 json 函数来获取格式化后的 json 数据
    form = request.json()
    # 创建一个 comment
    u = current_user(request)
    t = Comment.add(form, u.id)
    # 把创建好的 comment 返回给浏览器
    return json_response(t.json())
Exemple #10
0
def add():
    target_type = request.values.get('target_type')
    target_id = request.values.get('target_id')
    url = request.values.get('url')
    msg = request.values.get('msg')
    msg_channel = request.values.get('msg_channel')
    comment = Comment.add(target_type, target_id, msg, g.user, msg_channel=msg_channel)
    add_comment_signal.send(current_app._get_current_object(), comment=comment, msg_channel=msg_channel, url=url)
    return jsonify({'msg': "msg add success"})
Exemple #11
0
def add_comment(post_id, comment_body, user, parent_id=None):

    post = Post.get_by_id(post_id)
    if parent_id is not None:
        parent = Comment.get_by_id(parent_id).key

    comment = Comment()
    comment.add(
        text=comment_body,
        author=user,
        post=post.key,
        parent=None if parent_id is None else parent)

    if post.num_comments is None:
        post.num_comments = 0

    post.num_comments += 1
    post.put()
def comment_add(request):
    '''
    创建一个 comment
    '''
    form = request.dejson()
    u = current_user(request)
    form['user_id'] = u.id
    c = Comment.add(form)
    return json_response(c.to_dict())
Exemple #13
0
def comment_add(request):
    u = current_user(request)
    form = request.form()
    weibo_id = int(form['weibo_id'])

    c = Comment.add(form, u.id, weibo_id)

    log('comment add', c, u, form)
    return redirect('/weibo/index')
Exemple #14
0
def comment_add(request):
    u = current_user(request)
    form = request.json()
    w = Weibo.find_by(id=int(form['weibo_id']))
    comment = Comment.add(form, u.id, w.id)
    comment.username = u.username
    log('comment add', comment)

    return json_response(comment.json())
Exemple #15
0
 def test_add_and_get(self):
     uid0 = User.add("test1", "password", "*****@*****.**")
     bid0 = Board.add("board1", "A")
     lid0 = List.add("To Do", bid0)
     caid0 = Card.add("card1", lid0, uid0)
     coid0 = Comment.add(caid0, uid0, "comment1")
     comment0 = Comment.get(coid0)
     assert caid0 == comment0.card_id
     assert uid0 == comment0.user_id
     assert "comment1" == comment0.content
Exemple #16
0
def add_comment():
    """
    用于增加新 comment 的路由函数
    """
    form = request.get_json()
    u = current_user()
    c = Comment.add(form, u.id)
    username = c.user().username
    c = c.json()
    c['username'] = username
    return jsonify(c)
Exemple #17
0
def test_comment():
    # add
    form = dict(
        content='hello',
        weibo_id=5,
    )
    c = Comment(form)
    c.add(1)

    # update
    form = dict(
        id=1,
        content='well done',
    )
    id = int(form['id'])
    Comment.update(1, **form)

    # user
    user = c.user()
    log('test comment user(), us, ', user)
Exemple #18
0
def api_add_comment(card_id=None):
    if card_id == None:
        return jsonify({'code': 400, 'message': 'Bad Request'})
    else:
        card = Card.get(long(card_id))
        if card == None:
            return jsonify({'code': 404, 'message': 'Page Not Found'})
    
    try:
        content = request.form['comment']
    except:
        return jsonify({'code': 400, 'message': 'Bad Request'})

    comment = Comment.add(long(card_id), current_user.id, content)
    return jsonify({'card_id': card_id})
Exemple #19
0
def fake_data():
    SQLModel.init_db()

    Test.new({})

    form = dict(
        username='******',
        password='******',
        role=UserRole.normal,
    )
    u, result = User.register(form)

    Session.add(u.id)

    form = dict(title='test todo ajax', )
    todo = Todo.add(form, u.id)
    t = TodoAjax.add(form, u.id)

    form = dict(content='test weibo', )
    weibo = Weibo.add(form, u.id)
    comment = Comment.add(form, u.id)
Exemple #20
0
 def add_comment(self, user, msg, msg_channel=0):
     Comment.add(self.target_type, self.target_id, msg, user,
                 datetime.datetime.now(), msg_channel)
Exemple #21
0
def comment_add(request):
    form = request.json()
    weibo_id = form['weibo_id']
    u = current_user(request)
    t = Comment.add(form, u.id, weibo_id)
    return json_response(t.json())
Exemple #22
0
def comment_add(request):
    form = request.json()
    u = current_user(request)
    weibo_id = int(form.pop('weibo_id'))
    c = Comment.add(form, u.id, weibo_id)
    return json_response(c.json())
Exemple #23
0
def comment_add(request):
    u = current_user(request)
    form = request.form()
    Comment.add(form, u.id)
    log('comment add')
    return redirect('/weibo/index')
Exemple #24
0
user0.set_avatar('http://127.0.0.1:5000/_uploads/images/avatar_1.png')
user1.set_avatar('http://127.0.0.1:5000/_uploads/images/avatar_2.png')

lid0 = List.add("To Do", bid0)
lid1 = List.add("Doing", bid0)
lid2 = List.add("Done", bid0)

caid0 = Card.add("card1", lid0, uid0)
caid1 = Card.add("card2", lid0, uid0)
caid2 = Card.add("card3", lid1, uid0)

card0 = Card.get(caid0)
card0.add_user(user1)
card0.add_user(user2)

coid0 = Comment.add(caid0, uid0, "comment1")
coid1 = Comment.add(caid0, uid1, "comment2")
coid2 = Comment.add(caid0, uid2, "comment3")



'''
# -*- coding: utf-8 -*-
from __future__ import absolute_import
from models.user import User
from models.board import Board
from models.list import List
from models.card import Card
from models.comment import Comment
from models.group import Group
from utils.db import mysql_engine, r_server
Exemple #25
0
 def add_comment(self, user, msg, msg_channel=0):
     Comment.add(self.target_type, self.target_id, msg, user, datetime.datetime.now(), msg_channel)
Exemple #26
0
def comment_add(request):
    form = request.json()
    u = current_user(request)
    c = Comment.add(form, u.id)
    return json_response(c.json())
Exemple #27
0
def comment_add(request):
    form = request.json()
    u = current_user(request)
    t = Comment.add(form, u.id, u.username)
    return json_response(t.json())