コード例 #1
0
ファイル: views.py プロジェクト: loulonglong/django
def getallqunuser(request):
    if request.method == "POST":
        pageNo = request.POST.get("page", None)  # 读取get数据,None为默认值
        userid = request.POST.get("userid", None)  # 读取get数据,None为默认值

    if request.method == "GET":
        pageNo = request.GET.get("page", None)  # 读取get数据,None为默认值
        userid = request.GET.get("userid", None)  # 读取get数据,None为默认值

    print("查询用户所在群下所有用户:用户ID:", userid)

    result = {}

    page = PageForId()
    page.pageno = pageNo
    page.userid = userid
    page.pagesize = 20  # 一次查询100个
    page.start = 20 * (int(pageNo) - 1)  # 数据库本来就是从后向前查询的   在数据库中第0条记录就是最默认的记录
    allUsers = UserDAO.queryallqunuser(page)
    alluserback = []
    for i in range(len(allUsers)):
        alluserback.append(fun.user2else_back(allUsers[i]))

    result["respcode"] = ResultCode.SUCCESS
    result["message"] = "查询用户成功!"
    result["data"] = alluserback
    result["errorcode"] = ResultCode.SUCCESS
    print("查询到用户,数目为", len(alluserback))
    return JsonResponse(result)
コード例 #2
0
ファイル: views.py プロジェクト: loulonglong/django
def getalluser(request):
    if request.method == "POST":
        pageNo = request.POST.get("page", None)  # 读取get数据,None为默认值

    if request.method == "GET":
        pageNo = request.GET.get("page", None)  # 读取get数据,None为默认值

    print("分页查询所有用户page:", pageNo)

    result = {}
    alluserback = []

    page = PageForId()
    page.pageno = pageNo
    page.pagesize = 100  # 一次查询100个

    page.start = 100 * (pageNo - 1)  # 数据库本来就是从后向前查询的   在数据库中第0条记录就是最默认的记录

    alluser = UserDAO.queryalluser(page)

    if (alluser and len(alluser) != 0):
        for i in range(len(alluser)):
            user_back = fun.user2else_back(alluser[i])
            alluserback.append(user_back)

    result["respcode"] = ResultCode.SUCCESS
    result["message"] = "查询用户成功!"
    result["data"] = alluserback
    result["errorcode"] = ResultCode.SUCCESS
    print("查询用户成功!")
    return JsonResponse(result)
コード例 #3
0
def queryAllsixin(request):
    #第一层的结果集
    result = {}
    allmessage_back = []

    if request.method == "POST":
        receive_id = int(request.POST.get("receive_id",
                                          None))  # 读取post数据,None为默认值
        pageNo = int(request.POST.get("page", None))  # 读取post数据,None为默认值
    if request.method == "GET":
        receive_id = int(request.GET.get("receive_id",
                                         None))  # 读取post数据,None为默认值
        pageNo = int(request.POST.get("page", None))  # 读取post数据,None为默认值
    print("查询某人的所有接收私信接口参数:接收者ID", receive_id, "page", pageNo)

    #获取聊天数目
    page = PageForId()
    page.pageno = pageNo
    page.receive_id = receive_id

    page.pagesize = 10
    page.start = 10 * (pageNo - 1)  #数据库本来就是从后向前查询的   在数据库中第0条记录就是最默认的记录
    try:
        allMessage = Chat_MessageDAO.queryAllsixin(page.receive_id, page.start,
                                                   page.pagesize)  #通过abid查询
        if (allMessage and len(allMessage) > 0):
            receiveuser = fun.user2else_back(UserDAO.getUserInfoId(receive_id))
            for message in allMessage:
                senduser = fun.user2else_back(
                    UserDAO.getUserInfoId(message.getSend_id()))
                message_back = fun.chatmessage2back(message)
                message_back['send_user'] = senduser
                message_back['receive_user'] = receiveuser

                allmessage_back.append(message_back)

        result["message"] = "查询成功"
        result["data"] = allmessage_back
        result["errorcode"] = ""
        result["respcode"] = ResultCode.SUCCESS

    except Exception as e:
        print(e)
        result["message"] = "查询失败"
        result["data"] = ""
        result["errorcode"] = ResultCode.FAIL
        result["respcode"] = ResultCode.FAIL
        print("查询失败")

    return JsonResponse(result)
コード例 #4
0
ファイル: views.py プロジェクト: loulonglong/django
def getuserallimg(request):
    if request.method == "POST":
        pageNo = request.POST.get("page", None)  # 读取get数据,None为默认值
        userid = request.POST.get("userid", None)  # 读取get数据,None为默认值
    if request.method == "GET":
        pageNo = request.GET.get("page", None)  # 读取get数据,None为默认值
        userid = request.GET.get("userid", None)  # 读取get数据,None为默认值

    print("查询用户图片:用户ID:", userid)

    result = {}
    allpic = []

    page = PageForId()
    page.pageno = pageNo
    page.userid = userid
    page.pagesize = 10  # 一次查询100个
    page.start = 10 * (pageNo - 1)  # 数据库本来就是从后向前查询的   在数据库中第0条记录就是最默认的记录

    alldiary = DiaryDAO.selectimgDiarysforuser(page)

    if (alldiary and len(alldiary) != 0):
        for i in range(len(alldiary)):
            if (alldiary[i].imgone):
                allpic.append(alldiary[i].imgone)
            if (alldiary[i].imgtwo):
                allpic.append(alldiary[i].imgtwo)
            if (alldiary[i].imgthree):
                allpic.append(alldiary[i].imgthree)
            if (alldiary[i].imgfour):
                allpic.append(alldiary[i].imgfour)
            if (alldiary[i].imgfive):
                allpic.append(alldiary[i].imgfive)
            if (alldiary[i].imgsix):
                allpic.append(alldiary[i].imgsix)
            if (alldiary[i].imgseven):
                allpic.append(alldiary[i].imgseven)
            if (alldiary[i].imgeight):
                allpic.append(alldiary[i].imgeight)
            if (alldiary[i].imgnine):
                allpic.append(alldiary[i].imgnine)

    result["respcode"] = ResultCode.SUCCESS
    result["message"] = "查询群组图片成功!"
    result["data"] = allpic
    result["errorcode"] = ResultCode.SUCCESS
    print("查询群组图片成功!")
    return JsonResponse(result)
コード例 #5
0
ファイル: views.py プロジェクト: loulonglong/django
def getdifuser(request):
    if request.method == "POST":
        pageNo = request.POST.get("page", None)  # 读取get数据,None为默认值
        userid = request.POST.get("userid", None)  # 读取get数据,None为默认值
        showtype = request.POST.get("showtype", None)  # 读取get数据,None为默认值
    if request.method == "GET":
        pageNo = request.GET.get("page", None)  # 读取get数据,None为默认值
        userid = request.GET.get("userid", None)  # 读取get数据,None为默认值
        showtype = request.GET.get("showtype", None)  # 读取get数据,None为默认值

    print("查询各种类型的用户:用户ID:", userid, "类型", showtype)

    result = {}
    alluser = []

    me = UserDAO.getUserInfoId(userid)
    if (not me):
        result["respcode"] = ResultCode.FAIL
        result["message"] = "用户不存在!请先注册登陆"
        result["data"] = ""
        result["errorcode"] = ResultCode.FAIL
        print("用户不存在")
        return JsonResponse(result)

    page = PageForId()
    page.pageno = pageNo
    page.userid = userid
    page.pagesize = 100  # 一次查询100个
    page.deal = showtype
    page.start = 100 * (pageNo - 1)  # 数据库本来就是从后向前查询的   在数据库中第0条记录就是最默认的记录
    allmore = MoreDAO.selectmorelistInfopage(page)
    if (allmore and len(allmore) != 0):
        for i in range(len(allmore)):
            user1 = UserDAO.getUserInfoId(allmore[i].userid_destination)
            user_back = fun.user2else_back(user1)
            more = getuserdeal(userid, user1.id, ResultCode.USER_ZAN)
            if (more):
                user_back['ideal'] = ResultCode.USER_ZAN
            alluser.append(user_back)

    result["respcode"] = ResultCode.SUCCESS
    result["message"] = "查询用户成功!"
    result["data"] = alluser
    result["errorcode"] = ResultCode.SUCCESS
    print("查询各种类型用户,数目为", len(alluser))
    return JsonResponse(result)
コード例 #6
0
def querytongzhifortype(request):
    #第一层的结果集*/
    result = {}
    allTongzhiback = []
    if request.method == "POST":
        pageNo = int(request.POST.get("page", None))  # 读取post数据,None为默认值
        messagetype = int(request.POST.get("messagetype",
                                           None))  # 读取post数据,None为默认值
    if request.method == "GET":
        pageNo = int(request.GET.get("page", None))  # 读取post数据,None为默认值
        messagetype = int(request.GET.get("messagetype",
                                          None))  # 读取post数据,None为默认值
    tongzhi_back = Tongzhi_back()

    print("查询指定类型的所有通知接口参数")
    page = PageForId()
    page.pageNo = pageNo
    page.pagesize = 20
    page.messagetype = messagetype
    page.start = 20 * (pageNo - 1)  #数据库本来就是从后向前查询的   在数据库中第0条记录就是最默认的记录
    try:
        allMessage = TongzhiDAO.querytongzhifortype(page)
        if (len(allMessage) > 0):
            for i in range(len(allMessage)):
                tongzhi = allMessage[i]
                tongzhi_back = fun.tongzhi2back(tongzhi)
                allTongzhiback.add(tongzhi_back)
        result["message"] = "查询成功"
        result["data"] = allTongzhiback
        result["errorcode"] = ""
        result["respcode"] = ResultCode.SUCCESS
        print("查询到通知数目", len(allTongzhiback))
    except Exception as e:
        print(e)
        result["message"] = "查询失败"
        result["data"] = ""
        result["errorcode"] = ResultCode.FAIL
        result["respcode"] = ResultCode.FAIL
    return result
コード例 #7
0
def queryqunchat(request):
    #第一层的结果集
    result = {}
    allmessage_back = []

    if request.method == "POST":
        qunid = int(request.POST.get("qunid", None))  # 读取post数据,None为默认值
        receive_id = int(request.POST.get("receive_id",
                                          None))  # 读取post数据,None为默认值
        pageNo = int(request.POST.get("page", None))  # 读取post数据,None为默认值
    if request.method == "GET":
        qunid = int(request.GET.get("qunid", None))  # 读取post数据,None为默认值
        receive_id = int(request.GET.get("receive_id",
                                         None))  # 读取post数据,None为默认值
        pageNo = int(request.POST.get("page", None))  # 读取post数据,None为默认值
    print("查询群聊接口参数:接收者ID", receive_id, "page", pageNo)

    #首先查询是否存在聊天关系
    chatuser1 = Chatuser()
    chatuser1.send_id = qunid
    chatuser1.receive_id = receive_id
    chatuser1.usertype = ResultCode.CHATUSER_TYPE_QUN
    chatuser1 = ChatuserDAO.querychatqunexist(chatuser1)
    if (chatuser1 == None):
        result["message"] = "暂无聊天信息"
        result["data"] = ""
        result["errorcode"] = ""
        result["respcode"] = ResultCode.FAIL
        print("不存在聊天关系")
        return JsonResponse(result)

    #设置聊天关系为已读
    #获取聊天数目
    page = PageForId()
    page.pageno = pageNo
    page.receive_id = receive_id
    page.send_id = qunid
    page.abid = chatuser1.abid
    page.pagesize = 20
    page.start = 20 * (pageNo - 1)  #数据库本来就是从后向前查询的   在数据库中第0条记录就是最默认的记录
    try:
        allMessage = Chat_MessageDAO.queryAllsixinwithhe(
            page.abid, page.start, page.pagesize)  #通过abid查询
        if (len(allMessage) > 0):
            #修改聊天用户的状态   在群聊中
            page.state = ResultCode.CHATUSER_OLD
            ChatuserDAO.updatachatuserstateforuser(page)
            qun = QunDAO.getqunInfoqunid(qunid)
            for message in allMessage:
                message_back = fun.chatmessage2back(message)
                #获取消息发送者信息
                senduser = fun.user2else_back(
                    UserDAO.getUserInfoId(message_back['send_id']))
                message_back['send_user'] = senduser
                message_back['qun'] = model_to_dict(qun)

                allmessage_back.append(message_back)

        result["message"] = "查询成功"
        result["data"] = allmessage_back
        result["errorcode"] = ""
        result["respcode"] = ResultCode.SUCCESS

    except Exception as e:
        print(e)
        result["message"] = "查询失败"
        result["data"] = ""
        result["errorcode"] = ResultCode.FAIL
        result["respcode"] = ResultCode.FAIL
        print("查询失败")

    return JsonResponse(result)
コード例 #8
0
def queryAllsixinwithhe(request):
    #第一层的结果集
    result = {}
    allmessage_back = []
    if request.method == "POST":
        send_id = int(request.POST.get("send_id", None))  # 读取post数据,None为默认值
        receive_id = int(request.POST.get("receive_id",
                                          None))  # 读取post数据,None为默认值
        pageNo = int(request.POST.get("page", None))  # 读取post数据,None为默认值
    if request.method == "GET":
        send_id = int(request.POST.get("send_id", None))  # 读取post数据,None为默认值
        receive_id = int(request.GET.get("receive_id",
                                         None))  # 读取post数据,None为默认值
        pageNo = int(request.POST.get("page", None))  # 读取post数据,None为默认值
    print("查询和某人的所有私信接口参数:接收者ID", receive_id, "发送者id", send_id, "page", pageNo)

    #首先查询是否存在聊天关系
    chatuser1 = Chatuser()
    chatuser1.send_id = send_id
    chatuser1.receive_id = receive_id
    chatuser1.usertype = ResultCode.CHATUSER_TYPE_RECEIVE
    chatuser1 = ChatuserDAO.querychatuserexist(chatuser1)
    if (chatuser1 == None):
        chatuser1 = Chatuser()
        chatuser1.send_id = send_id
        chatuser1.receive_id = receive_id
        chatuser1.usertype = ResultCode.CHATUSER_TYPE_SEND
        chatuser1 = ChatuserDAO.querychatuserexist(chatuser1)
        if (chatuser1 == None):
            result["message"] = "不存在聊天关系"
            result["data"] = allmessage_back
            result["errorcode"] = ""
            result["respcode"] = ResultCode.SUCCESS
            print("不存在聊天关系")
            return JsonResponse(result)

    #设置聊天关系为已读
#获取聊天数目
    page = PageForId()
    page.pageno = pageNo
    page.receive_id = receive_id
    page.send_id = send_id

    page.pagesize = 10
    page.start = 10 * (pageNo - 1)  #数据库本来就是从后向前查询的   在数据库中第0条记录就是最默认的记录

    try:
        allMessage = Chat_MessageDAO.queryAllsixinwithhe(
            page.abid, page.start, page.pagesize)  #通过abid查询
        if (allMessage and len(allMessage) > 0):
            page.state = ResultCode.CHATUSER_OLD
            ChatuserDAO.updatachatuserstateforuser(chatuser1)  #修改聊天用户的状态
            senduser = fun.user2else_back(UserDAO.getUserInfoId(send_id))
            receiveuser = fun.user2else_back(UserDAO.getUserInfoId(receive_id))
            for message in allMessage:
                print("查询聊天记录" + message.content)
                message_back = fun.chatmessage2back(message)
                if (message_back['send_id'] == send_id):
                    message_back['send_user'] = senduser
                    message_back['receive_user'] = receiveuser
                else:
                    message_back['send_user'] = receiveuser
                    message_back['receive_user'] = senduser

                allmessage_back.append(message_back)

        result["message"] = "查询成功"
        result["data"] = allmessage_back
        result["errorcode"] = ""
        result["respcode"] = ResultCode.SUCCESS

    except Exception as e:
        print(e)
        result["message"] = "查询失败"
        result["data"] = ""
        result["errorcode"] = ResultCode.FAIL
        result["respcode"] = ResultCode.FAIL
        print("查询失败")

    return JsonResponse(result)