Beispiel #1
0
def friends(request, field, page):
    """
    搜索好友
    :param field: 肯能是username,也肯是uid
    :param page: 当前页
    :return:
    """

    # todo 服务器必须筛选,当前用户已经通过了对方验证的用户
    page = int(page)
    print(field, page)
    if request.session.get("userId", "") == "":
        return error_response.session_error()
    holder_id = request.session["userId"]
    if phone_tools.check_phone(field):
        all_user = User.objects.filter(phone=field)[page * 10:10 * (page + 1)]
        friends_ret = friends_creator.info(all_user, holder_id)
    else:
        search = field
        all_user = User.objects.filter(
            username__contains=search)[page * 10:10 * (page + 1)]
        friends_ret = friends_creator.info(all_user, holder_id)
    if not friends_ret['result']:
        friends_ret['status'] = response_code.NULL_DATA
    print(json.dumps(friends_ret, ensure_ascii=False))
    return HttpResponse(json.dumps(friends_ret, ensure_ascii=False))
Beispiel #2
0
def group(request, field, page):
    """
    群端搜索
    """
    page = int(page)
    if request.session.get("userId", "") == "":
        return error_response.session_error()
    holder_id = request.session["userId"]
    all_gopup = Group.objects.filter(name__contains=field)[(page - 1) * 10:10 *
                                                           (page - 1) + 10]
    goups_ret = groups_creator.info(all_gopup, holder_id)
    return HttpResponse(json.dumps(goups_ret, ensure_ascii=False))
Beispiel #3
0
def create(request, uid):
    """
    建立好友关系
    :param uid: 好友的id
    :return:
    """
    if request.session.get("userId", "") == "":
        return error_response.session_error()
    holder_id = request.session["userId"]
    print(holder_id)
    is_exists = Friends.objects.filter(origin_id=holder_id,
                                       target_id=uid).exists()
    if is_exists:
        ret = error_response.base_error(response_code.EXIST_FRIENDS)
    else:
        ret = friends_creator.relation(holder_id, uid)
    print(json.dumps(ret))
    return HttpResponse(json.dumps(ret))