Ejemplo n.º 1
0
def new_answer():
    question = Question()
    idu = question.find_by_id().idu  # 查找出问题提出用户

    notification = Notification()
    notification.newanswer(idq, idu)
    return 'success'
Ejemplo n.º 2
0
def get_my_collection():
    collection = Collection()
    user = User()
    question = Question()

    username = request.args.get("username")
    idu = user.find_by_username(username)[0].id
    res = collection.find_by_idu(idu=idu)
    data = []
    for item in res:
        col = {}
        idq = item.idq
        q = question.find_by_id(id=idq)
        title = q.title
        category = q.category
        description = q.description
        view_count = q.view_count
        answer_count = q.answer_count
        collect_count = q.collect_count
        gmt_create = q.gmt_create
        col['idq'] = idq
        col['title'] = title
        col['category'] = category
        col['description'] = description
        col['view_count'] = view_count
        col['collect_count'] = collect_count
        col['answer_count'] = answer_count
        col['gmt_create'] = gmt_create

        data.append(col)
    return jsonify({'data': data})
Ejemplo n.º 3
0
    def newanswer(self, idq, idu):
        question = Question()
        title = question.find_by_id(id=idq).title
        content = "您的问题" + "'" + title + "'" + "有新的回答了,快去看看吧。"
        read = "n"

        notification = Notification(idu=idu, read=read, content=content)
        dbsession.add(notification)
        dbsession.commit()
        return 1
Ejemplo n.º 4
0
def get_history():
    history = History()
    user = User()
    question = Question()

    username = request.args.get("username")
    idu = user.find_by_username(username)[0].id
    res = history.find_by_idu(idu=idu)
    data = []
    for item in res:
        col = {}
        idq = item.idq
        title = question.find_by_id(id=idq).title
        col['idq'] = idq
        col['title'] = title

        data.append(col)
    return jsonify({'data': data})
Ejemplo n.º 5
0
    def newupvote(self, ida, idu1, idu2):
        answer = Answer()
        question = Question()
        user = User()

        nickname = user.find_by_id(idu2).nickname

        idq = answer.find_by_id(id=ida).idq

        title = question.find_by_id(id=idq).title

        content = nickname + "点赞了" + "您关于问题" + "'" + title + "'" + "的回答。"
        read = "n"

        notification = Notification(idu=idu1, read=read, content=content)
        dbsession.add(notification)
        dbsession.commit()
        return 1
Ejemplo n.º 6
0
def get_my_answer():
    answer = Answer()
    user = User()
    question = Question()
    data = []

    username = request.args.get('username')
    idu = user.find_by_username(username=username)[0].id
    res = answer.find_by_idu(idu=idu)
    for item in res:
        idq = item.idq
        title = question.find_by_id(id=idq).title
        a = {}
        a['id'] = item.id
        a['idq'] = idq
        a['title'] = title
        a['content'] = item.content
        a['upvote'] = item.upvote
        a['gmt_create'] = item.gmt_create

        data.append(a)
    return jsonify({'data': data})
Ejemplo n.º 7
0
def get_recommend():
    question = Question()
    user = User()
    answer = Answer()
    collection = Collection()
    history = History()

    username = request.args.get('username')
    idu = user.find_by_username(username=username)[0].id

    dict = {}
    dict['campus'] = 0
    dict['focus'] = 0
    dict['finance'] = 0
    dict['technology'] = 0
    dict['culture'] = 0
    dict['education'] = 0
    dict['depth'] = 0
    dict['entertain'] = 0
    dict['fashion'] = 0
    dict['sports'] = 0

    w1 = 1  # 浏览权重
    w2 = 3  # 回答权重
    w3 = 5  # 收藏权重

    '''
    1.遍历该用户的所有浏览记录,为分类+1
    2.遍历该用户的所有回答记录,为分类+3
    3.遍历该用户的所有收藏记录,为分类+5
    '''

    # 遍历history,为分类赋权重
    res1 = history.find_by_idu(idu=idu)
    for item in res1:
        idq = item.idq
        q = question.find_by_id(id=idq)
        cate = str(q.category)
        dict[cate] += w1

    # 遍历answer
    res2 = answer.find_by_idu(idu=idu)
    for item in res2:
        idq = item.idq
        q = question.find_by_id(id=idq)
        cate = str(q.category)
        dict[cate] += w2

    # 遍历collection
    res3 = collection.find_by_idu(idu=idu)
    for item in res3:
        idq = item.idq
        q = question.find_by_id(id=idq)
        cate = str(q.category)
        dict[cate] += w3

    # 对权重进行排序
    rec = sorted(dict.items(), key=lambda item:item[1], reverse=True)

    # 获取三个类别
    cate_0 = rec[0][0]
    cate_1 = rec[1][0]
    cate_2 = rec[2][0]

    data = []
    list = []
    list.extend(question.find_by_category(category=cate_0))
    list.extend(question.find_by_category(category=cate_1))
    list.extend(question.find_by_category(category=cate_2))

    for item in list:
        q = {}
        q['id'] = item.id
        q['title'] = item.title
        q['category'] = item.category
        q['description'] = item.description
        q['view_count'] = item.view_count
        q['answer_count'] = item.answer_count
        q['collect_count'] = item.collect_count
        q['gmt_create'] = item.gmt_create

        data.append(q)
    random.shuffle(data)
    return jsonify({'data': data})