Пример #1
0
def register(data):
    try:
        userId = data["user_id"]
    except KeyError:
        return util.errorJsonWrapper("注册数据没有user_id字段")

    try:
        userPassword = data["user_password"]
    except KeyError:
        return util.errorJsonWrapper("注册数据没有user_id字段")
    try:
        userPassword = hashlib.md5(userPassword).hexdigest()

        token = hashlib.md5(userId + userPassword + str(datetime.datetime.now())).hexdigest()

        tokenoverdue = str(datetime.datetime.now() + datetime.timedelta(seconds = 30))

        checkRes = models.User.objects.filter(user_id=userId)
    except:
        return util.errorJsonWrapper("test")

    if len(checkRes) == 0:
        try:
            tmpUser = models.User(user_id = userId, user_password = userPassword, user_token = token, user_token_overdue = tokenoverdue)
            tmpUser.save()
        except Exception:
            return util.errorJsonWrapper("register 数据写入数据库出错")
        tokenDict = {"user_token" : token}
        #retList = []
        #retList.append(tokenDict)
        res = dict(retCode=0, retMsg="", retValue = tokenDict)
        return json.dumps(res)
        #return util.simpleOkJsonWrapper()
    else:
        return util.errorJsonWrapper("注册失败,该手机号已经被注册")
Пример #2
0
def login(data):
    userID = data.get("user_id")
    token = data.get("user_token")
    password = data.get("user_password")
    user = models.User.objects.filter(user_id = userID).first()

    if not user:
        return util.errorJsonWrapper("不存在该用户名")
    else:
        if token:
            if str(datetime.datetime.now()) < user.user_token_overdue:
                if token == user.user_token:
                    return getUserInfo(user,token)
                else:
                    return util.errorJsonWrapper("token错误")
            else:
                return util.errorJsonWrapper("token已过期")
        else:
            if user.user_password != hashlib.md5(password).hexdigest():
                return util.errorJsonWrapper("密码错误")
            else:
                token = hashlib.md5(userID + password + str(datetime.datetime.now())).hexdigest()
                user.user_token = token
                user.user_token_overdue = str(datetime.datetime.now() + datetime.timedelta(days = 3))
                user.save()
                
                return getUserInfo(user, token)
Пример #3
0
def register(data):
    try:
        userId = data["user_id"]
    except KeyError:
        return util.errorJsonWrapper("注册数据没有user_id字段")

    try:
        userPassword = data["user_password"]
    except KeyError:
        return util.errorJsonWrapper("注册数据没有user_id字段")

    userPassword = hashlib.md5(userPassword).hexdigest()

    checkRes = models.User.objects.filter(user_id = userId)

    if len(checkRes) == 0:
        try:
            tmpUser = models.User(user_id = userId, user_password = userPassword)
            tmpUser.save()
        except Exception:
            return util.errorJsonWrapper("register 数据写入数据库出错")

        return util.simpleOkJsonWrapper()
    else:
        return util.errorJsonWrapper("注册失败,该手机号已经被注册")
Пример #4
0
def login(data):
    userID = data.get("user_id")
    token = data.get("user_token")
    password = data.get("user_password")
    user = models.User.objects.filter(user_id=userID).first()

    if not user:
        return util.errorJsonWrapper("不存在该用户名")
    else:
        if token:
            if str(datetime.datetime.now()) < user.user_token_overdue:
                if token == user.user_token:
                    return getUserInfo(user, token)
                else:
                    return util.errorJsonWrapper("token错误")
            else:
                return util.errorJsonWrapper("token已过期")
        else:
            if user.user_password != hashlib.md5(password).hexdigest():
                return util.errorJsonWrapper("密码错误")
            else:
                token = hashlib.md5(userID + password +
                                    str(datetime.datetime.now())).hexdigest()
                user.user_token = token
                user.user_token_overdue = str(datetime.datetime.now() +
                                              datetime.timedelta(days=3))
                user.save()

                return getUserInfo(user, token)
Пример #5
0
def register(data):
    try:
        userId = data["user_id"]
    except KeyError:
        return util.errorJsonWrapper("注册数据没有user_id字段")

    try:
        userPassword = data["user_password"]
    except KeyError:
        return util.errorJsonWrapper("注册数据没有user_id字段")

    userPassword = hashlib.md5(userPassword).hexdigest()

    checkRes = models.User.objects.filter(user_id=userId)

    if len(checkRes) == 0:
        try:
            tmpUser = models.User(user_id=userId, user_password=userPassword)
            tmpUser.save()
        except Exception:
            return util.errorJsonWrapper("register 数据写入数据库出错")

        return util.simpleOkJsonWrapper()
    else:
        return util.errorJsonWrapper("注册失败,该手机号已经被注册")
Пример #6
0
def login(data):
    userID = data.get("user_id")
    token = data.get("user_token")
    password = data.get("user_password")
    user = models.User.objects.filter(user_id = userID).first()

    if not user:
        return util.errorJsonWrapper("不存在该用户名")
    else:
        if token:
            if str(datetime.datetime.now()) < user.user_token_overdue:
                if token == user.user_token:
                    return util.simpleOkJsonWrapper()
                else:
                    return util.errorJsonWrapper("token错误")
            else:
                return util.errorJsonWrapper("token已过期")


        if password:
            if user.user_password != hashlib.md5(password).hexdigest():
                return util.errorJsonWrapper("密码错误")
            else:
                token = hashlib.md5(userID + password + str(datetime.datetime.now())).hexdigest()
                user.user_token = token
                user.user_token_overdue = str(datetime.datetime.now() + datetime.timedelta(seconds = 30))
                user.save()
                tokenDict = {"user_token" : token}
                #retList = []
                #retList.append(tokenDict)
                res = dict(retCode=0, retMsg="", retValue = tokenDict)
                return json.dumps(res)
Пример #7
0
def issueFosterPetInfo(data):
    try:
        userId = data["user_id"]
    except KeyError:
        return util.errorJsonWrapper("寄养消息没有user_id字段")

    try:
        activityId = data["activity_id"]
    except KeyError:
        return util.errorJsonWrapper("寄养消息没有activity_id字段")
    
    checkUserId = models.User.objects.filter(user_id=userId)
    if len(checkUserId) == 0:
        return util.errorJsonWrapper("不存在该userId用户")

    checkActivityId = models.Activity.objects.filter(pk=activityId)
    if len(checkActivityId) == 0:
        return util.errorJsonWrapper("不存在该activity_id活动")


    try:
        tmpParticipant = models.Participant(participant_user_id = checkUserId[0], participant_activity_id=checkActivityId[0], participant_user_type=2)
        tmpParticipant.save()
        return util.simpleOkJsonWrapper()
    except Exception:
        return util.errorJsonWrapper("Participant 数据写入数据库出错")
Пример #8
0
def functionChoice(methodData):
    if methodData == "postFormError":
        return HttpResponse(util.errorJsonWrapper("post数据没有method字段"))
    else:
        try:
            data = json.loads(methodData)
        except ValueError:
            return HttpResponse(util.errorJsonWrapper("json数据格式错误,无法解析"))
        try:
            funcName = data["name"]
        except KeyError:
            return HttpResponse(util.errorJsonWrapper("json数据格式中没有name字段"))
        try:
            funcArgs = data["args"]
        except KeyError:
            return HttpResponse(util.errorJsonWrapper("json数据格式中没有args字段"))

        if funcName == "register":
            return HttpResponse(register.register(funcArgs))
        elif funcName == "login":
            return HttpResponse(login.login(funcArgs))
        elif funcName == "issueAdoptPetInfo":
            return HttpResponse(issueAdoptPetInfo.issueAdoptPetInfo(funcArgs))
        elif funcName == "getAdoptDetailList":
            return HttpResponse(
                getAdoptDetailList.getAdoptDetailList(funcArgs))
        elif funcName == "issueFosterPetInfo":
            return HttpResponse(
                issueFosterPetInfo.issueFosterPetInfo(funcArgs))
        elif funcName == "getInfoList":
            return HttpResponse(getInfoList.getInfoList(funcArgs))
        else:
            return HttpResponse(util.errorJsonWrapper(funcName + u":暂不支持该函数"))
Пример #9
0
def getAdoptDetailList(data):

    activityId = data.get("activity_id")
    if not activityId:
        return util.errorJsonWrapper("收养详细信息获取请求错误,不存在该activity_id")

    activity = models.Activity.objects.get(pk = activityId)
    if not activity:
        return util.errorJsonWrapper("收养详细信息获取请求错误,不存在该活动")

    user = models.Participant.objects.filter(participant_activity = activity).first().participant_user
    if not user:
        return util.errorJsonWrapper("收养详细信息获取请求错误,不存在该用户")

    # check token by stanwu 为了方便调试暂时注释掉
    #token = data.get("user_token")
    #if token != user.user_token:
    #    return util.errorJsonWrapper("token错误")

    detailDict = {  "user_id" : user.user_id, "activity_picture" : activity.activity_picture, "user_avatar" : user.user_avatar,
                    "user_nickname" : user.user_nickname, "user_age" : user.user_age, "user_interest" : user.user_interest,
                    "activity_pet_type" : activity.activity_pet_type, "activity_price" : activity.activity_price,
                    "activity_address": activity.activity_address, "activity_introduction": activity.activity_introduction,
                    "activity_start_time": activity.activity_start_time,
                    "activity_end_time": activity.activity_end_time
                    }

    retList = []
    retList.append(detailDict)
    res = dict(retCode = 0, retMsg = "", retValue = detailDict)

    return json.dumps(res)
Пример #10
0
def issueFosterPetInfo(data):
    try:
        userId = data["user_id"]
    except KeyError:
        return util.errorJsonWrapper("寄养消息没有user_id字段")

    try:
        activityId = data["activity_id"]
    except KeyError:
        return util.errorJsonWrapper("寄养消息没有activity_id字段")

    checkUserId = models.User.objects.filter(user_id=userId)
    if len(checkUserId) == 0:
        return util.errorJsonWrapper("不存在该userId用户")

    checkActivityId = models.Activity.objects.filter(pk=activityId)
    if len(checkActivityId) == 0:
        return util.errorJsonWrapper("不存在该activity_id活动")

    try:
        tmpParticipant = models.Participant(
            participant_user_id=checkUserId[0],
            participant_activity_id=checkActivityId[0],
            participant_user_type=2)
        tmpParticipant.save()
        return util.simpleOkJsonWrapper()
    except Exception:
        return util.errorJsonWrapper("Participant 数据写入数据库出错")
Пример #11
0
def functionChoice(post, files):
    methodData = post.get("method", "postFormError")

    if methodData == "postFormError":
        return HttpResponse(util.errorJsonWrapper("post数据没有method字段"))
    else:
        try:
            data = json.loads(methodData)
        except ValueError:
            return HttpResponse(util.errorJsonWrapper("json数据格式错误,无法解析"))
        try:
            funcName = data["name"]
        except KeyError:
            return HttpResponse(util.errorJsonWrapper("json数据格式中没有name字段"))
        try:
            funcArgs = data["args"]
        except KeyError:
            return HttpResponse(util.errorJsonWrapper("json数据格式中没有args字段"))

        if funcName == "register":
            return HttpResponse(register.register(funcArgs))
        elif funcName == "completeUserInfo":
            return HttpResponse(completeUserInfo.completeUserInfo(funcArgs,files))
        elif funcName == "login":
            return HttpResponse(login.login(funcArgs))
        elif funcName == "issueAdoptPetInfo":
            return HttpResponse(issueAdoptPetInfo.issueAdoptPetInfo(funcArgs,files))
        elif funcName == "issueFosterPetInfo":
            return HttpResponse(issueFosterPetInfo.issueFosterPetInfo(funcArgs))
        elif funcName == "getInfoList":
            return HttpResponse(getInfoList.getInfoList(funcArgs))
        elif funcName == "getAdoptDetailList":
            return HttpResponse(getAdoptDetailList.getAdoptDetailList(funcArgs))
        else:
            return HttpResponse(util.errorJsonWrapper(funcName+u":暂不支持该函数"))
Пример #12
0
def login(data):
    userID = data.get("user_id")
    password = data.get("user_password")
    user = models.User.objects.filter(user_id = userID).first()
    if not user:
        return util.errorJsonWrapper("不存在该用户名")
    else:
        if not password:
            return util.errorJsonWrapper("请输入密码")
        elif user.user_password != hashlib.md5(password).hexdigest():
            return util.errorJsonWrapper("密码错误")
        else:
            return util.simpleOkJsonWrapper()
Пример #13
0
def getInfoList(data):
    try:
        userId = data["user_id"]
    except KeyError:
        return util.errorJsonWrapper("请求数据没有user_id字段")

    try:
        activityType = data["activity_type"]
    except KeyError:
        return util.errorJsonWrapper("请求数据没有activity_type字段")

    try:
        number = data["number"]
    except KeyError:
        return util.errorJsonWrapper("请求数据没有number字段")

    try:
        sortType = data["sort_type"]
    except KeyError:
        return util.errorJsonWrapper("请求数据没有sort_type字段")

    resList = models.Participant.objects.filter(
        participant_user__user_id=userId, participant_user_type=activityType)

    retValue = []
    for item in resList:
        retValueItem = {}
        userInfo = item.participant_user
        activityInfo = item.participant_activity

        retValueItem["activity_id"] = activityInfo.pk
        retValueItem["activity_picture"] = activityInfo.activity_picture
        retValueItem['activity_price'] = activityInfo.activity_price

        retValueItem["user_nickname"] = userInfo.user_nickname
        retValueItem["user_avatar"] = userInfo.user_avatar
        retValueItem["user_address"] = userInfo.user_address

        retValue.append(retValueItem)

    retValue = retValue[:number]

    result = {}

    result["retValue"] = retValue
    result["retCode"] = 0
    result["retMsg"] = ""

    return json.dumps(result)
Пример #14
0
def getInfoList(data):
    try:
        userId = data["user_id"]
    except KeyError:
        return util.errorJsonWrapper("请求数据没有user_id字段")

    try:
        activityType = data["activity_type"]
    except KeyError:
        return util.errorJsonWrapper("请求数据没有activity_type字段")

    try:
        number = data["number"]
    except KeyError:
        return util.errorJsonWrapper("请求数据没有number字段")

    try:
        sortType = data["sort_type"]
    except KeyError:
        return util.errorJsonWrapper("请求数据没有sort_type字段")
    
    resList = models.Participant.objects.filter(participant_user__user_id=userId, participant_user_type=activityType)

    retValue = []
    for item in resList:
        retValueItem = {}
        userInfo = item.participant_user
        activityInfo = item.participant_activity

        retValueItem["activity_id"] = activityInfo.pk
        retValueItem["activity_picture"] = activityInfo.activity_picture
        retValueItem['activity_price'] = activityInfo.activity_price

        retValueItem["user_nickname"] = userInfo.user_nickname
        retValueItem["user_avatar"] = userInfo.user_avatar
        retValueItem["user_address"] = userInfo.user_address

        retValue.append(retValueItem)

    retValue = retValue[:number]

    result = {}

    result["retValue"] = retValue
    result["retCode"] = 0
    result["retMsg"] = ""

    return json.dumps(result)
Пример #15
0
def register(data):
    try:
        userId = data["user_id"]
    except KeyError:
        return util.errorJsonWrapper("注册数据没有user_id字段")

    try:
        userPassword = data["user_password"]
    except KeyError:
        return util.errorJsonWrapper("注册数据没有user_id字段")
    try:
        userPassword = hashlib.md5(userPassword).hexdigest()

        token = hashlib.md5(userId + userPassword +
                            str(datetime.datetime.now())).hexdigest()

        tokenoverdue = str(datetime.datetime.now() +
                           datetime.timedelta(days=3))

        checkRes = models.User.objects.filter(user_id=userId)
    except:
        return util.errorJsonWrapper("test")

    if len(checkRes) == 0:
        try:
            tmpUser = models.User(user_id=userId,
                                  user_password=userPassword,
                                  user_token=token,
                                  user_token_overdue=tokenoverdue)
            tmpUser.save()
        except Exception:
            return util.errorJsonWrapper("register 数据写入数据库出错")

        retValueItem = {}
        retValueItem['user_token'] = token
        retValueItem["user_nickname"] = ""
        retValueItem["user_avatar"] = ""
        retValueItem["user_address"] = ""
        retValueItem["user_age"] = 0
        retValueItem["user_interest"] = 0
        retValueItem["user_gender"] = 0
        retValueItem["user_authenticated"] = False
        res = dict(retCode=0, retMsg="", retValue=retValueItem)

        return json.dumps(res)
    else:
        return util.errorJsonWrapper("注册失败,该手机号已经被注册")
Пример #16
0
def issueAdoptPetInfo(data):
    EVENT_STATUS = 0
    ADOPT = 1
    userId = data.get("user_id")
    user = models.User.objects.filter(user_id = userId).first()
    if not user:
        return util.errorJsonWrapper("不存在该用户")

    # check token by stanwu
    token = data.get("user_token")
    if token != user.user_token:
        return util.errorJsonWrapper("token错误")

    activityPic = data.get("activity_picture")
    activityIntro = data.get("activity_introduction")
    activityAddr = data.get("activity_address")
    activityLongi = data.get("activity_longitude")
    activityLati = data.get("activity_latitude")
    activityPet = data.get("activity_pet_type")
    activityPrice = data.get("activity_price")
    activityStartTime = data.get("activity_start_time")
    activityEndTime = data.get("activity_end_time")

    try:
        activity = models.Activity( activity_introduction = activityIntro,
                                activity_picture = activityPic,
                                activity_price = activityPrice,
                                activity_pet_type = activityPet,
                                activity_start_time = activityStartTime,
                                activity_end_time = activityEndTime,
                                activity_status = EVENT_STATUS,
                                activity_address = activityAddr)
        activity.save()
    except Exception:
        return util.errorJsonWrapper("发布收养信息出错,activity无法写入数据库")

    try:
        participant = models.Participant(participant_user = user,
                                     participant_activity = activity,
                                     participant_user_type = ADOPT)
        participant.save()
    except Exception:
        return util.errorJsonWrapper("发布收养信息出错,participant无法写入数据库")

    return util.simpleOkJsonWrapper()
Пример #17
0
def issueAdoptPetInfo(data):
    EVENT_STATUS = 0
    ADOPT = 1
    userId = data.get("user_id")
    user = models.User.objects.filter(user_id=userId).first()
    if not user:
        return util.errorJsonWrapper("不存在该用户")

    # check token by stanwu
    token = data.get("user_token")
    if token != user.user_token:
        return util.errorJsonWrapper("token错误")

    activityPic = data.get("activity_picture")
    activityIntro = data.get("activity_introduction")
    activityAddr = data.get("activity_address")
    activityLongi = data.get("activity_longitude")
    activityLati = data.get("activity_latitude")
    activityPet = data.get("activity_pet_type")
    activityPrice = data.get("activity_price")
    activityStartTime = data.get("activity_start_time")
    activityEndTime = data.get("activity_end_time")

    try:
        activity = models.Activity(activity_introduction=activityIntro,
                                   activity_picture=activityPic,
                                   activity_price=activityPrice,
                                   activity_pet_type=activityPet,
                                   activity_start_time=activityStartTime,
                                   activity_end_time=activityEndTime,
                                   activity_status=EVENT_STATUS,
                                   activity_address=activityAddr)
        activity.save()
    except Exception:
        return util.errorJsonWrapper("发布收养信息出错,activity无法写入数据库")

    try:
        participant = models.Participant(participant_user=user,
                                         participant_activity=activity,
                                         participant_user_type=ADOPT)
        participant.save()
    except Exception:
        return util.errorJsonWrapper("发布收养信息出错,participant无法写入数据库")

    return util.simpleOkJsonWrapper()
Пример #18
0
def issueFosterPetInfo(data):
    try:
        userId = data["user_id"]
    except KeyError:
        return util.errorJsonWrapper("请求数据没有user_id字段")
    try:
        userToken = data["user_token"]
    except KeyError:
        return util.errorJsonWrapper("请求数据没有token字段")

    if not util.checkToken(userId, userToken):
        return util.errorJsonWrapper("token 验证失败")

    try:
        activityId = data["activity_id"]
    except KeyError:
        return util.errorJsonWrapper("寄养消息没有activity_id字段")
     
    checkUserId = models.User.objects.filter(user_id=userId)
    if len(checkUserId) == 0:
        return util.errorJsonWrapper("不存在该userId用户")

    checkActivityId = models.Activity.objects.filter(pk=activityId)
    if len(checkActivityId) == 0:
        return util.errorJsonWrapper("不存在该activity_id活动")
    
    #判断该活动是否已经被别人寄养
    isParAdopted = models.Participant.objects.filter(participant_activity = checkActivityId[0], participant_user_type = 1,
            participant_status = 1)

    if isParAdopted:
        return util.errorJsonWrapper("该活动已经被别人寄养")

    #判断是否已经有取消状态的订单
    parti = models.Participant.objects.filter(participant_user = checkUserId[0], participant_activity = checkActivityId[0], 
            participant_user_type = 2, participant_status = 2)
    try:
        if parti:
            parti.participant_status = 1
            parti.save()
        else:
            tmpParticipant = models.Participant(participant_user = checkUserId[0], participant_activity = checkActivityId[0], 
                    participant_user_type=2, participant_status = 1)
            tmpParticipant.save()


        adoptParticipant = models.Participant.objects.filter(participant_activity = checkActivityId[0], participant_user_type=1)
        for parti in adoptParticipant:
            parti.participant_status = 1
            parti.save()
    
        return util.simpleOkJsonWrapper()
    except Exception:
        return util.errorJsonWrapper("Participant 数据写入数据库出错")
Пример #19
0
def completeUserInfo(data, files):
    try:
        userId = data["user_id"]
    except KeyError:
        return util.errorJsonWrapper("注册数据没有user_id字段")

    try:
        userGender = data["user_gender"]
    except KeyError:
        return util.errorJsonWrapper("注册数据没有user_gender字段")
    try:
        userAge = data["user_age"]
    except KeyError:
        return util.errorJsonWrapper("注册数据没有user_age字段")
    try:
        userAddress = data["user_address"]
    except KeyError:
        return util.errorJsonWrapper("注册数据没有user_address字段")
    try:
        userNickname = data["user_nickname"]
    except KeyError:
        return util.errorJsonWrapper("注册数据没有user_nickname字段")
    try:
        userInterest = data["user_interest"]
    except KeyError:
        return util.errorJsonWrapper("注册数据没有user_interest字段")
    

    FIllin = models.User.objects.get(user_id=userId)

    if FIllin:
        try:
            FIllin.user_gender = userGender
            FIllin.user_age = userAge
            FIllin.user_address = userAddress
            FIllin.user_nikename = userNickname
            #FIllin.user_longitude = userLongitude
            #FIllin.user_latitude = userLatitude
            FIllin.user_interest = userInterest
            
            #保存头像地址
            FIllin.user_avatar = saveUserAvatar(files)
            #return util.errorJsonWrapper(saveUserAvatar(files))

            FIllin.save()

        except Exception:
            return util.errorJsonWrapper("用户数据写入数据库出错")

        return util.simpleOkJsonWrapper()

    else:
        return util.errorJsonWrapper("该用户不存在")
Пример #20
0
def functionChoice(post, files):
    methodData = post.get("method", "postFormError")
    #return HttpResponse(json.dumps(post))
    if methodData == "postFormError":
        return HttpResponse(util.errorJsonWrapper("post数据没有method字段"))
    else:
        try:
            data = json.loads(methodData)
        except ValueError:
            return HttpResponse(util.errorJsonWrapper("json数据格式错误,无法解析"))
        try:
            funcName = data["name"]
        except KeyError:
            return HttpResponse(util.errorJsonWrapper("json数据格式中没有name字段"))
        try:
            funcArgs = data["args"]
        except KeyError:
            return HttpResponse(util.errorJsonWrapper("json数据格式中没有args字段"))

        if funcName == "register":
            return HttpResponse(register.register(funcArgs))
        elif funcName == "completeUserInfo":
            return HttpResponse(completeUserInfo.completeUserInfo(funcArgs,files))
        elif funcName == "login":
            return HttpResponse(login.login(funcArgs))
        elif funcName == "issueAdoptPetInfo":
            return HttpResponse(issueAdoptPetInfo.issueAdoptPetInfo(funcArgs,files))
        elif funcName == "issueFosterPetInfo":
            return HttpResponse(issueFosterPetInfo.issueFosterPetInfo(funcArgs))
        elif funcName == "getInfoList":
            return HttpResponse(getInfoList_dev.getInfoList(funcArgs))
        elif funcName == "getUserInfoList":
            return HttpResponse(getUserInfoList.getUserInfoList(funcArgs))
        elif funcName == "getAdoptDetailList":
            return HttpResponse(getAdoptDetailList.getAdoptDetailList(funcArgs))
        elif funcName == "authenticateUser":
            return HttpResponse(authenticateUser.authenticateUser(funcArgs,files))
        elif funcName == "logout":
            return HttpResponse(logout.logout(funcArgs))
        elif funcName == "cancelFoster":
            return HttpResponse(cancelFoster.cancelFoster(funcArgs))
        else:
            return HttpResponse(util.errorJsonWrapper(funcName+u":暂不支持该函数"))
Пример #21
0
def register(data):
    try:
        userId = data["user_id"]
    except KeyError:
        return util.errorJsonWrapper("注册数据没有user_id字段")

    try:
        userPassword = data["user_password"]
    except KeyError:
        return util.errorJsonWrapper("注册数据没有user_id字段")
    try:
        userPassword = hashlib.md5(userPassword).hexdigest()

        token = hashlib.md5(userId + userPassword + str(datetime.datetime.now())).hexdigest()

        tokenoverdue = str(datetime.datetime.now() + datetime.timedelta(days = 3))

        checkRes = models.User.objects.filter(user_id=userId)
    except:
        return util.errorJsonWrapper("test")

    if len(checkRes) == 0:
        try:
            tmpUser = models.User(user_id = userId, user_password = userPassword, user_token = token, user_token_overdue = tokenoverdue)
            tmpUser.save()
        except Exception:
            return util.errorJsonWrapper("register 数据写入数据库出错")

        retValueItem = {}
        retValueItem['user_token'] = token
        retValueItem["user_nickname"] = ""
        retValueItem["user_avatar"] = ""
        retValueItem["user_address"] = ""
        retValueItem["user_age"] = 0
        retValueItem["user_interest"] = 0
        retValueItem["user_gender"] = 0
        retValueItem["user_authenticated"] = False
        res = dict(retCode=0, retMsg="", retValue = retValueItem)

        return json.dumps(res)
    else:
        return util.errorJsonWrapper("注册失败,该手机号已经被注册")
Пример #22
0
def authenticateUser(data, files):
    try:
        userId = data["user_id"]
    except KeyError:
        return util.errorJsonWrapper("请求数据没有user_id字段")
    try:
        userToken = data["user_token"]
    except KeyError:
        return util.errorJsonWrapper("请求数据没有token字段")

    if not util.checkToken(userId, userToken):
        return util.errorJsonWrapper("token 验证失败")

    user = models.User.objects.get(user_id=userId)

    if user:
        try:
            picName = util.savePicture(files, "user_authenticated_picture",
                                       20 * 1024 * 1024)
            if picName == -1:
                return util.errorJsonWrapper("failed")
            user.user_authenticated_picture = picName
            user.user_authenticated = True
            user.save()

        except Exception:
            return util.errorJsonWrapper("用户认证信息存入数据库出错")

        return util.simpleOkJsonWrapper("用户认证成功")
    else:
        return util.errorJsonWrapper("该用户不存在")
Пример #23
0
def authenticateUser(data, files):
    try:
        userId = data["user_id"]
    except KeyError:
        return util.errorJsonWrapper("请求数据没有user_id字段")
    try:
        userToken = data["user_token"]
    except KeyError:
        return util.errorJsonWrapper("请求数据没有token字段")

    if not util.checkToken(userId, userToken):
        return util.errorJsonWrapper("token 验证失败")

    user = models.User.objects.get(user_id=userId)

    if user:
        try:
            picName = util.savePicture(files,"user_authenticated_picture",20*1024*1024)
            if picName == -1:
                return util.errorJsonWrapper("failed")
            user.user_authenticated_picture = picName 
            user.user_authenticated = True
            user.save()

        except Exception:
            return util.errorJsonWrapper("用户认证信息存入数据库出错")

        return util.simpleOkJsonWrapper("用户认证成功")
    else:
        return util.errorJsonWrapper("该用户不存在")
Пример #24
0
def getAdoptDetailList(data):

    activityId = data.get("activity_id")
    if not activityId:
        return util.errorJsonWrapper("收养详细信息获取请求错误,不存在该activity_id")

    activity = models.Activity.objects.get(pk=activityId)
    if not activity:
        return util.errorJsonWrapper("收养详细信息获取请求错误,不存在该活动")

    user = models.Participant.objects.filter(
        participant_activity=activity).first().participant_user
    if not user:
        return util.errorJsonWrapper("收养详细信息获取请求错误,不存在该用户")

    # check token by stanwu
    token = data.get("user_token")
    if token != user.user_token:
        return util.errorJsonWrapper("token错误")

    detailDict = {
        "user_id": user.user_id,
        "activity_picture": activity.activity_picture,
        "user_avatar": user.user_avatar,
        "user_nickname": user.user_nickname,
        "user_age": user.user_age,
        "user_interest": user.user_interest,
        "activity_pet_type": activity.activity_pet_type,
        "activity_price": activity.activity_price,
        "activity_address": activity.activity_address,
        "activity_introduction": activity.activity_introduction,
        "activity_start_time": activity.activity_start_time,
        "activity_end_time": activity.activity_end_time
    }

    retList = []
    retList.append(detailDict)
    res = dict(retCode=0, retMsg="", retValue=retList)

    return json.dumps(res)
Пример #25
0
def cancelFoster(data):
    userId = data.get("user_id")
    if not userId:
        return util.errorJsonWrapper("缺少user_id")

    user = models.User.objects.filter(user_id=userId).first()
    if not user:
        return util.errorJsonWrapper("该用户不存在")

    userToken = data.get("user_token")
    if not userToken:
        return util.errorJsonWrapper("token不存在")

    if not util.checkToken(userId, userToken):
        return util.errorJsonWrapper("token验证失败")

    activityId = data.get("activity_id")
    if not activityId:
        return util.errorJsonWrapper("缺少activity_id")

    activity = models.Activity.objects.filter(pk=activityId).first()
    if not activity:
        return util.errorJsonWrapper("该活动不存在")

    partAdopt = models.Participant.objects.filter(
        participant_activity=activity, participant_user_type=1).first()
    if not partAdopt:
        return util.errorJsonWrapper("不存在该收养用户")

    partFoster = models.Participant.objects.filter(
        participant_user=user, participant_activity=activity).first()
    if not partFoster:
        return util.errorJsonWrapper("不存在该寄养用户")

    try:
        partAdopt.participant_status = 0
        partAdopt.save()

        partFoster.participant_status = 2
        partFoster.save()
    except:
        return util.errorJsonWrapper("写入数据库出错")

    return util.simpleOkJsonWrapper(partFoster.participant_status)
Пример #26
0
def logout(data):

    try:
        userId = data["user_id"]
    except KeyError:
        return util.errorJsonWrapper("请求数据没有user_id字段")
    try:
        userToken = data["user_token"]
    except KeyError:
        return util.errorJsonWrapper("请求数据没有token字段")

    if not util.checkToken(userId, userToken):
        return util.errorJsonWrapper("token 验证失败")

    user = models.User.objects.filter(user_id=userId).first()

    if not user:
        return util.errorJsonWrapper("不存在该用户名")
    else:
        user.user_token_overdue = str(datetime.datetime.now())
        user.save()
        return util.simpleOkJsonWrapper()
Пример #27
0
def logout(data):

    try:
        userId = data["user_id"]
    except KeyError:
        return util.errorJsonWrapper("请求数据没有user_id字段")
    try:
        userToken = data["user_token"]
    except KeyError:
        return util.errorJsonWrapper("请求数据没有token字段")

    if not util.checkToken(userId, userToken):
        return util.errorJsonWrapper("token 验证失败")

    user = models.User.objects.filter(user_id = userId).first()

    if not user:
        return util.errorJsonWrapper("不存在该用户名")
    else:
        user.user_token_overdue = str(datetime.datetime.now())
        user.save()
        return util.simpleOkJsonWrapper()
Пример #28
0
def cancelFoster(data):
    userId = data.get("user_id")
    if not userId:
        return util.errorJsonWrapper("缺少user_id")

    user = models.User.objects.filter(user_id = userId).first()
    if not user:
        return util.errorJsonWrapper("该用户不存在")

    userToken = data.get("user_token")
    if not userToken:
        return util.errorJsonWrapper("token不存在")

    if not util.checkToken(userId, userToken):
        return util.errorJsonWrapper("token验证失败")

    activityId = data.get("activity_id")
    if not activityId:
        return util.errorJsonWrapper("缺少activity_id")

    activity = models.Activity.objects.filter(pk = activityId).first()
    if not activity:
        return util.errorJsonWrapper("该活动不存在")
    
    partAdopt = models.Participant.objects.filter(participant_activity = activity, participant_user_type = 1).first()
    if not partAdopt:
        return util.errorJsonWrapper("不存在该收养用户")
    

    partFoster = models.Participant.objects.filter(participant_user = user, participant_activity = activity).first()
    if not partFoster:
        return util.errorJsonWrapper("不存在该寄养用户")

    try:
        partAdopt.participant_status = 0
        partAdopt.save()
        
        partFoster.participant_status = 2
        partFoster.save()
    except:
        return util.errorJsonWrapper("写入数据库出错")

    return util.simpleOkJsonWrapper(partFoster.participant_status)
Пример #29
0
def getAdoptDetailList(data):

    try:
        userId = data["user_id"]
    except KeyError:
        return util.errorJsonWrapper("请求数据没有user_id字段")
    try:
        userToken = data["user_token"]
    except KeyError:
        return util.errorJsonWrapper("请求数据没有token字段")

    if not util.checkToken(userId, userToken):
        return util.errorJsonWrapper("token 验证失败")

    activityId = data.get("activity_id")
    if not activityId:
        return util.errorJsonWrapper("收养详细信息获取请求错误,不存在该activity_id")

    activity = models.Activity.objects.get(pk = activityId)
    if not activity:
        return util.errorJsonWrapper("收养详细信息获取请求错误,不存在该活动")

    user = models.Participant.objects.filter(participant_activity = activity).first().participant_user
    if not user:
        return util.errorJsonWrapper("收养详细信息获取请求错误,不存在该用户")

    detailDict = {  "user_id" : user.user_id,
                    "activity_picture" : activity.activity_picture,
                    "user_avatar" : user.user_avatar,
                    "user_nickname" : user.user_nickname,
                    "user_age" : user.user_age,
                    "user_interest" : user.user_interest,
                    "activity_pet_type" : activity.activity_pet_type,
                    "activity_price" : activity.activity_price,
                    "activity_address": activity.activity_address,
                    "activity_introduction": activity.activity_introduction,
                    "activity_start_time": activity.activity_start_time,
                    "activity_end_time": activity.activity_end_time
                    }

    retList = []
    retList.append(detailDict)
    res = dict(retCode = 0, retMsg = "", retValue = retList)

    return json.dumps(res)
Пример #30
0
def getInfoList(data):
    try:
        userId = data["user_id"]
    except KeyError:
        return util.errorJsonWrapper("请求数据没有user_id字段")
    try:
        userToken = data["user_token"]
    except KeyError:
        return util.errorJsonWrapper("请求数据没有token字段")

    if not util.checkToken(userId, userToken):
        return util.errorJsonWrapper("token 验证失败")
    
    try:
        functionType = data["function_type"]
    except KeyError:
        return util.errorJsonWrapper("请求数据没有function_type字段")
    try:
        number = data["number"]
    except KeyError:
        return util.errorJsonWrapper("请求数据没有number字段")
    try:
        recommend_Type = data["recommend_type"]
    except KeyError:
        return util.errorJsonWrapper("请求数据没有recommend_type字段")
    try:
        gender = data["gender"]
    except KeyError:
        return util.errorJsonWrapper("请求数据没有gender字段")
    try:
        petType = data["pet_type"]
    except KeyError:
        return util.errorJsonWrapper("请求数据没有pet_type字段")

    #resList = models.Participant.objects.all()

    if functionType == RECOMMEND_FUNC:
        if recommend_Type == DEFAULT_RECOM:
            resList = models.Participant.objects.filter(participant_user_type=1)
        else:
            resList = intelligentSort(userId, recommend_Type)

    elif functionType == FILTER_FUNC:
        if gender == GENDER_ALL and petType == PET_ALL:
            resList = models.Participant.objects.filter(participant_user_type=1)
        elif gender == GENDER_ALL:
            resList = models.Participant.objects.filter(participant_activity__activity_pet_type=pet_type,participant_user_type=1)
        elif petType == PET_ALL:
            resList = models.Participant.objects.filter(participant_user__user_gender=gender,participant_user_type=1)
        else:
            resList = models.Participant.objects.filter(participant_activity__activity_pet_type=petType,participant_user__user_gender=gender,participant_user_type=1)            

    try:
        retValue = []
        for item in resList:
            retValueItem = {}
            userInfo = item.participant_user
            activityInfo = item.participant_activity

            retValueItem["activity_id"] = activityInfo.pk
            retValueItem["activity_picture"] = activityInfo.activity_picture
            retValueItem['activity_address'] = activityInfo.activity_address
            retValueItem['activity_price'] = activityInfo.activity_price
            retValueItem['activity_introduction'] = activityInfo.activity_introduction
            retValueItem['activity_pet_type'] = activityInfo.activity_pet_type
            retValueItem['activity_start_time'] = activityInfo.activity_start_time
            retValueItem['activity_end_time'] = activityInfo.activity_end_time
                

            retValueItem["user_id"] = userInfo.user_id
            retValueItem["user_nickname"] = userInfo.user_nickname
            retValueItem["user_avatar"] = userInfo.user_avatar
            retValueItem["user_address"] = userInfo.user_address
            retValueItem["user_age"] = userInfo.user_age
            retValueItem["user_interest"] = userInfo.user_interest
            retValueItem["user_gender"] = userInfo.user_gender
            retValueItem["user_authenticated"] = userInfo.user_authenticated

            retValue.append(retValueItem)

        if number >= 0:
            retValue = retValue[:number]

        result = {}

        result["retValue"] = retValue
        result["retCode"] = 0
        result["retMsg"] = ""

        return json.dumps(result)
    except Exception:
        return util.errorJsonWrapper("请求信息列表失败")
Пример #31
0
def completeUserInfo(data, files):
    try:
        userId = data["user_id"]
    except KeyError:
        return util.errorJsonWrapper("注册数据没有user_id字段")
    try:
        userToken = data["user_token"]
    except KeyError:
        return util.errorJsonWrapper("注册数据没有user_token字段")

    if not util.checkToken(userId, userToken):
        return util.errorJsonWrapper("token 验证失败")

    try:
        userGender = data["user_gender"]
    except KeyError:
        return util.errorJsonWrapper("注册数据没有user_gender字段")
    try:
        userAge = data["user_age"]
    except KeyError:
        return util.errorJsonWrapper("注册数据没有user_age字段")
    try:
        userAddress = data["user_address"]
    except KeyError:
        return util.errorJsonWrapper("注册数据没有user_address字段")
    try:
        userNickname = data["user_nickname"]
    except KeyError:
        return util.errorJsonWrapper("注册数据没有user_nickname字段")
    try:
        userInterest = data["user_interest"]
    except KeyError:
        return util.errorJsonWrapper("注册数据没有user_interest字段")

    FIllin = models.User.objects.get(user_id=userId)

    if FIllin:
        try:
            FIllin.user_gender = userGender
            FIllin.user_age = userAge
            FIllin.user_address = userAddress
            FIllin.user_nickname = userNickname
            FIllin.user_interest = userInterest

            picName = util.savePicture(files, "user_avatar", 2 * 1024 * 1024)
            if picName == -1:
                return util.errorJsonWrapper("failed")
            if picName != "":
                FIllin.user_avatar = picName

            FIllin.save()

        except Exception:
            return util.errorJsonWrapper("用户数据写入数据库出错")

        return util.simpleOkJsonWrapper()

    else:
        return util.errorJsonWrapper("该用户不存在")
Пример #32
0
def issueAdoptPetInfo(data,files):
    EVENT_STATUS = 1
    ADOPT = 1

    try:
        userId = data["user_id"]
    except KeyError:
        return util.errorJsonWrapper("请求数据没有user_id字段")
    try:
        userToken = data["user_token"]
    except KeyError:
        return util.errorJsonWrapper("请求数据没有token字段")

    if not util.checkToken(userId, userToken):
        return util.errorJsonWrapper("token 验证失败")

    user = models.User.objects.filter(user_id = userId).first()
    if not user:
        return util.errorJsonWrapper("不存在该用户")

    if not user.user_authenticated:
        return util.errorJsonWrapper("failed")
    
    activityIntro = data.get("activity_introduction")
    activityAddr = data.get("activity_address")
    activityLongi = data.get("activity_longitude")
    activityLati = data.get("activity_latitude")
    activityPet = data.get("activity_pet_type")
    activityPrice = data.get("activity_price")
    activityStartTime = data.get("activity_start_time")
    activityEndTime = data.get("activity_end_time")
    activityStartTime = time.strftime("%Y-%m-%d",(time.strptime(activityStartTime,"%Y-%m-%d")))
    activityEndTime = time.strftime("%Y-%m-%d",(time.strptime(activityEndTime,"%Y-%m-%d")))

    resDict = {}
    resDict['activity_introduction'] = activityIntro
    resDict['activity_address'] = activityAddr
    resDict['activity_longitude'] = activityLongi
    resDict['activity_latitude'] = activityLati
    resDict['activity_pet_type'] = activityPet
    resDict['activity_price'] = activityPrice
    resDict['activity_start_time'] = activityStartTime
    resDict['activity_end_time'] = activityEndTime
    resDict["user_id"] = user.user_id
    resDict["user_nickname"] = user.user_nickname
    resDict["user_avatar"] = user.user_avatar
    resDict["user_address"] = user.user_address
    resDict["user_age"] = user.user_age
    resDict["user_interest"] = user.user_interest
    resDict["user_gender"] = user.user_gender
    resDict["user_authenticated"] = user.user_authenticated


    picName = util.savePicture(files,"activity_picture",20*1024*1024)
    if picName == -1:
        return util.errorJsonWrapper("failed")
    activityPic = picName 

    try:

        activity = models.Activity(activity_introduction = activityIntro,
                                activity_picture = activityPic,
                                activity_price = activityPrice,
                                activity_pet_type = activityPet,
                                activity_start_time = activityStartTime,
                                activity_end_time = activityEndTime,
                                activity_status = EVENT_STATUS,
                                activity_latitude = activityLati,
                                activity_longitude = activityLongi,
                                activity_address = activityAddr)
        activity.save()
    except Exception:
        return util.errorJsonWrapper("发布收养信息出错,activity无法写入数据库")

    resDict["activity_id"] = activity.pk
    resDict["activity_picture"] = picName

    try:
        participant = models.Participant(participant_user = user,
                                     participant_activity = activity,
                                     participant_user_type = ADOPT)
        participant.save()
    except Exception:
        return util.errorJsonWrapper("发布收养信息出错,participant无法写入数据库")
    
    #userDict = {"user_id" : userId} 
    res = dict(retCode = 0, retMsg = "", retValue = resDict)
    return json.dumps(res)
Пример #33
0
def getInfoList(data):

    MAINPAGE = 1
    ALLADOPTLIST = 2
    ALLFOSTERLIST = 3
    USERADOPTLIST = 4
    USERFOSTERLIST = 5

    try:
        userId = data["user_id"]
    except KeyError:
        return util.errorJsonWrapper("请求数据没有user_id字段")

    try:
        userToken = data["user_token"]
    except KeyError:
        return util.errorJsonWrapper("请求数据没有token字段")

    if not util.checkToken(userId, userToken):
        return util.errorJsonWrapper("token 验证失败")


    try:
        activityType = data["activity_type"]
    except KeyError:
        return util.errorJsonWrapper("请求数据没有activity_type字段")

    try:
        number = data["number"]
    except KeyError:
        return util.errorJsonWrapper("请求数据没有number字段")

    try:
        sortType = data["sort_type"]
    except KeyError:
        return util.errorJsonWrapper("请求数据没有sort_type字段")

    if activityType == MAINPAGE or activityType == ALLADOPTLIST:
        resList = util.intelligentSort(userId, sortType)
    elif activityType == ALLFOSTERLIST: 
        resList = models.Participant.objects.filter(participant_user_type=2)
    elif activityType == USERADOPTLIST: 
        resList = models.Participant.objects.filter(participant_user__user_id=userId, participant_user_type=1)
    elif activityType == USERFOSTERLIST: 
        resList = models.Participant.objects.filter(participant_user__user_id=userId, participant_user_type=2)

    try:
        retValue = []
        for item in resList:
            retValueItem = {}
            userInfo = item.participant_user
            activityInfo = item.participant_activity

            retValueItem["activity_id"] = activityInfo.pk
            retValueItem["activity_picture"] = activityInfo.activity_picture
            retValueItem['activity_address'] = activityInfo.activity_address
            retValueItem['activity_price'] = activityInfo.activity_price
            retValueItem['activity_introduction'] = activityInfo.activity_introduction
            retValueItem['activity_pet_type'] = activityInfo.activity_pet_type
            retValueItem['activity_start_time'] = activityInfo.activity_start_time
            retValueItem['activity_end_time'] = activityInfo.activity_end_time
            

            retValueItem["user_id"] = userInfo.user_id
            retValueItem["user_nickname"] = userInfo.user_nickname
            retValueItem["user_avatar"] = userInfo.user_avatar
            retValueItem["user_address"] = userInfo.user_address
            retValueItem["user_age"] = userInfo.user_age
            retValueItem["user_interest"] = userInfo.user_interest
            retValueItem["user_gender"] = userInfo.user_gender
            retValueItem["user_authenticated"] = userInfo.user_authenticated

            retValue.append(retValueItem)

        if number >= 0:
            retValue = retValue[:number]

        result = {}

        result["retValue"] = retValue
        result["retCode"] = 0
        result["retMsg"] = ""

        return json.dumps(result)
    except Exception:

        return util.errorJsonWrapper("请求信息列表失败")
Пример #34
0
def issueFosterPetInfo(data):
    try:
        userId = data["user_id"]
    except KeyError:
        return util.errorJsonWrapper("请求数据没有user_id字段")
    try:
        userToken = data["user_token"]
    except KeyError:
        return util.errorJsonWrapper("请求数据没有token字段")

    if not util.checkToken(userId, userToken):
        return util.errorJsonWrapper("token 验证失败")

    try:
        activityId = data["activity_id"]
    except KeyError:
        return util.errorJsonWrapper("寄养消息没有activity_id字段")

    checkUserId = models.User.objects.filter(user_id=userId)
    if len(checkUserId) == 0:
        return util.errorJsonWrapper("不存在该userId用户")

    checkActivityId = models.Activity.objects.filter(pk=activityId)
    if len(checkActivityId) == 0:
        return util.errorJsonWrapper("不存在该activity_id活动")

    #判断该活动是否已经被别人寄养
    isParAdopted = models.Participant.objects.filter(
        participant_activity=checkActivityId[0],
        participant_user_type=1,
        participant_status=1)

    if isParAdopted:
        return util.errorJsonWrapper("该活动已经被别人寄养")

    #判断是否已经有取消状态的订单
    parti = models.Participant.objects.filter(
        participant_user=checkUserId[0],
        participant_activity=checkActivityId[0],
        participant_user_type=2,
        participant_status=2)
    try:
        if parti:
            parti.participant_status = 1
            parti.save()
        else:
            tmpParticipant = models.Participant(
                participant_user=checkUserId[0],
                participant_activity=checkActivityId[0],
                participant_user_type=2,
                participant_status=1)
            tmpParticipant.save()

        adoptParticipant = models.Participant.objects.filter(
            participant_activity=checkActivityId[0], participant_user_type=1)
        for parti in adoptParticipant:
            parti.participant_status = 1
            parti.save()

        return util.simpleOkJsonWrapper()
    except Exception:
        return util.errorJsonWrapper("Participant 数据写入数据库出错")
Пример #35
0
def getInfoList(data):
    try:
        userId = data["user_id"]
    except KeyError:
        return util.errorJsonWrapper("请求数据没有user_id字段")
    try:
        userToken = data["user_token"]
    except KeyError:
        return util.errorJsonWrapper("请求数据没有token字段")

    if not util.checkToken(userId, userToken):
        return util.errorJsonWrapper("token 验证失败")

    try:
        functionType = data["function_type"]
    except KeyError:
        return util.errorJsonWrapper("请求数据没有function_type字段")
    try:
        number = data["number"]
    except KeyError:
        return util.errorJsonWrapper("请求数据没有number字段")
    try:
        recommend_Type = data["recommend_type"]
    except KeyError:
        return util.errorJsonWrapper("请求数据没有recommend_type字段")
    try:
        gender = data["gender"]
    except KeyError:
        return util.errorJsonWrapper("请求数据没有gender字段")
    try:
        petType = data["pet_type"]
    except KeyError:
        return util.errorJsonWrapper("请求数据没有pet_type字段")

    #resList = models.Participant.objects.all()

    if functionType == RECOMMEND_FUNC:
        if recommend_Type == DEFAULT_RECOM:
            resList = models.Participant.objects.filter(
                participant_user_type=1)
        else:
            resList = intelligentSort(userId, recommend_Type)

    elif functionType == FILTER_FUNC:
        if gender == GENDER_ALL and petType == PET_ALL:
            resList = models.Participant.objects.filter(
                participant_user_type=1)
        elif gender == GENDER_ALL:
            resList = models.Participant.objects.filter(
                participant_activity__activity_pet_type=pet_type,
                participant_user_type=1)
        elif petType == PET_ALL:
            resList = models.Participant.objects.filter(
                participant_user__user_gender=gender, participant_user_type=1)
        else:
            resList = models.Participant.objects.filter(
                participant_activity__activity_pet_type=petType,
                participant_user__user_gender=gender,
                participant_user_type=1)

    try:
        retValue = []
        for item in resList:
            retValueItem = {}
            userInfo = item.participant_user
            activityInfo = item.participant_activity

            retValueItem["activity_id"] = activityInfo.pk
            retValueItem["activity_picture"] = activityInfo.activity_picture
            retValueItem['activity_address'] = activityInfo.activity_address
            retValueItem['activity_price'] = activityInfo.activity_price
            retValueItem[
                'activity_introduction'] = activityInfo.activity_introduction
            retValueItem['activity_pet_type'] = activityInfo.activity_pet_type
            retValueItem[
                'activity_start_time'] = activityInfo.activity_start_time
            retValueItem['activity_end_time'] = activityInfo.activity_end_time

            retValueItem["user_id"] = userInfo.user_id
            retValueItem["user_nickname"] = userInfo.user_nickname
            retValueItem["user_avatar"] = userInfo.user_avatar
            retValueItem["user_address"] = userInfo.user_address
            retValueItem["user_age"] = userInfo.user_age
            retValueItem["user_interest"] = userInfo.user_interest
            retValueItem["user_gender"] = userInfo.user_gender
            retValueItem["user_authenticated"] = userInfo.user_authenticated

            retValue.append(retValueItem)

        if number >= 0:
            retValue = retValue[:number]

        result = {}

        result["retValue"] = retValue
        result["retCode"] = 0
        result["retMsg"] = ""

        return json.dumps(result)
    except Exception:
        return util.errorJsonWrapper("请求信息列表失败")
Пример #36
0
def index(request):
    if request.method == "POST":
        #return functionChoice(request.POST.get("method","postFormError"))
        return functionChoice(request.POST, request.FILES)
    else:
        return HttpResponse(util.errorJsonWrapper("只支持POST方法"))
Пример #37
0
def getInfoList(data):
    try:
        userId = data["user_id"]
    except KeyError:
        return util.errorJsonWrapper("请求数据没有user_id字段")

    #为了方便调试暂时去掉token, removed by perryhuang

    #usertoken = data.get("user_token")
    #if not usertoken:
    #    return util.errorJsonWrapper("未传入token")        
    #checkToken = models.User.objects.filter(user_id=userId).first()
    #if usertoken != checkToken.user_token:
    #    return util.errorJsonWrapper("token错误")

    try:
        activityType = data["activity_type"]
    except KeyError:
        return util.errorJsonWrapper("请求数据没有activity_type字段")

    try:
        number = data["number"]
    except KeyError:
        return util.errorJsonWrapper("请求数据没有number字段")

    try:
        sortType = data["sort_type"]
    except KeyError:
        return util.errorJsonWrapper("请求数据没有sort_type字段")
    
    resList = models.Participant.objects.filter(participant_user__user_id=userId, participant_user_type=activityType)

    try:
        retValue = []
        for item in resList:
            retValueItem = {}
            userInfo = item.participant_user
            activityInfo = item.participant_activity

            retValueItem["activity_id"] = activityInfo.pk
            retValueItem["activity_picture"] = activityInfo.activity_picture
            retValueItem['activity_price'] = activityInfo.activity_price

            retValueItem["user_nickname"] = userInfo.user_nickname
            retValueItem["user_avatar"] = userInfo.user_avatar
            retValueItem["user_address"] = userInfo.user_address

            retValue.append(retValueItem)

        #number小于0时默认返回全部数据
        if number >= 0:
            retValue = retValue[:number]

        result = {}

        result["retValue"] = retValue
        result["retCode"] = 0
        result["retMsg"] = ""

        return json.dumps(result)
    except Exception:

        return util.errorJsonWrapper("请求信息列表失败")
Пример #38
0
def getUserInfoList(data):

    USERADOPTLIST = 1
    USERFOSTERLIST = 2

    try:
        userId = data["user_id"]
    except KeyError:
        return util.errorJsonWrapper("请求数据没有user_id字段")

    try:
        userToken = data["user_token"]
    except KeyError:
        return util.errorJsonWrapper("请求数据没有token字段")

    if not util.checkToken(userId, userToken):
        return util.errorJsonWrapper("token 验证失败")

    try:
        activityType = data["activity_type"]
    except KeyError:
        return util.errorJsonWrapper("请求数据没有activity_type字段")

    try:
        number = data["number"]
    except KeyError:
        return util.errorJsonWrapper("请求数据没有number字段")

    try:
        sortType = data["sort_type"]
    except KeyError:
        return util.errorJsonWrapper("请求数据没有sort_type字段")

    if activityType == USERADOPTLIST:
        resList = models.Participant.objects.filter(
            participant_user__user_id=userId, participant_user_type=1)
        tmpList = []
        for item in resList:
            userInfo = item.participant_user
            activityInfo = item.participant_activity
            userTypeInfo = item.participant_user_type

            tmpList.append(
                models.Participant.objects.filter(
                    participant_activity=activityInfo,
                    participant_user_type=2)[0])

        resList = tmpList

    elif activityType == USERFOSTERLIST:
        resList = models.Participant.objects.filter(
            participant_user__user_id=userId, participant_user_type=2)
        resListStatus = []
        for item in resList:
            resListStatus.append(item.participant_status)

        tmpList = []
        for item in resList:
            userInfo = item.participant_user
            activityInfo = item.participant_activity
            userTypeInfo = item.participant_user_type

            tmpList.append(
                models.Participant.objects.filter(
                    participant_activity=activityInfo,
                    participant_user_type=1)[0])

        resList = tmpList
    else:
        return util.errorJsonWrapper("getUserInfoList中不支持改活动类型")

    #try:
    retValue = []
    for idx in range(len(resList)):
        retValueItem = {}
        userInfo = resList[idx].participant_user
        activityInfo = resList[idx].participant_activity

        retValueItem["activity_id"] = activityInfo.pk
        retValueItem["activity_picture"] = activityInfo.activity_picture
        retValueItem['activity_address'] = activityInfo.activity_address
        retValueItem['activity_price'] = activityInfo.activity_price
        retValueItem[
            'activity_introduction'] = activityInfo.activity_introduction
        retValueItem['activity_pet_type'] = activityInfo.activity_pet_type
        retValueItem['activity_start_time'] = activityInfo.activity_start_time
        retValueItem['activity_end_time'] = activityInfo.activity_end_time

        retValueItem["user_id"] = userInfo.user_id
        retValueItem["user_nickname"] = userInfo.user_nickname
        retValueItem["user_avatar"] = userInfo.user_avatar
        retValueItem["user_address"] = userInfo.user_address
        retValueItem["user_age"] = userInfo.user_age
        retValueItem["user_interest"] = userInfo.user_interest
        retValueItem["user_gender"] = userInfo.user_gender
        retValueItem["user_authenticated"] = userInfo.user_authenticated

        if activityType == USERFOSTERLIST:
            retValueItem["participant_status"] = resListStatus[idx]

        retValue.append(retValueItem)

    if number >= 0:
        retValue = retValue[:number]

    result = {}

    result["retValue"] = retValue
    result["retCode"] = 0
    result["retMsg"] = ""

    return json.dumps(result)
Пример #39
0
def index(request):
    if request.method == "POST":
        #return functionChoice(request.POST.get("method","postFormError"))
        return functionChoice(request.POST, request.FILES)
    else:
        return HttpResponse(util.errorJsonWrapper("只支持POST方法"))
Пример #40
0
def completeUserInfo(data, files):
    try:
        userId = data["user_id"]
    except KeyError:
        return util.errorJsonWrapper("注册数据没有user_id字段")
    try:
        userToken = data["user_token"]
    except KeyError:
        return util.errorJsonWrapper("注册数据没有user_token字段")

    if not util.checkToken(userId, userToken):
        return util.errorJsonWrapper("token 验证失败")

    try:
        userGender = data["user_gender"]
    except KeyError:
        return util.errorJsonWrapper("注册数据没有user_gender字段")
    try:
        userAge = data["user_age"]
    except KeyError:
        return util.errorJsonWrapper("注册数据没有user_age字段")
    try:
        userAddress = data["user_address"]
    except KeyError:
        return util.errorJsonWrapper("注册数据没有user_address字段")
    try:
        userNickname = data["user_nickname"]
    except KeyError:
        return util.errorJsonWrapper("注册数据没有user_nickname字段")
    try:
        userInterest = data["user_interest"]
    except KeyError:
        return util.errorJsonWrapper("注册数据没有user_interest字段")
    

    FIllin = models.User.objects.get(user_id=userId)

    if FIllin:
        try:
            FIllin.user_gender = userGender
            FIllin.user_age = userAge
            FIllin.user_address = userAddress
            FIllin.user_nickname = userNickname
            FIllin.user_interest = userInterest
            
            picName = util.savePicture(files,"user_avatar",2*1024*1024)
            if picName == -1:
                return util.errorJsonWrapper("failed")
            if picName != "":
                FIllin.user_avatar = picName 

            FIllin.save()

        except Exception:
            return util.errorJsonWrapper("用户数据写入数据库出错")

        return util.simpleOkJsonWrapper()

    else:
        return util.errorJsonWrapper("该用户不存在")
Пример #41
0
def getUserInfoList(data):

    USERADOPTLIST = 1
    USERFOSTERLIST = 2

    try:
        userId = data["user_id"]
    except KeyError:
        return util.errorJsonWrapper("请求数据没有user_id字段")

    try:
        userToken = data["user_token"]
    except KeyError:
        return util.errorJsonWrapper("请求数据没有token字段")

    if not util.checkToken(userId, userToken):
        return util.errorJsonWrapper("token 验证失败")


    try:
        activityType = data["activity_type"]
    except KeyError:
        return util.errorJsonWrapper("请求数据没有activity_type字段")

    try:
        number = data["number"]
    except KeyError:
        return util.errorJsonWrapper("请求数据没有number字段")

    try:
        sortType = data["sort_type"]
    except KeyError:
        return util.errorJsonWrapper("请求数据没有sort_type字段")

    if activityType == USERADOPTLIST: 
        resList = models.Participant.objects.filter(participant_user__user_id=userId, participant_user_type=1)
        tmpList= []
        for item in resList:
            userInfo = item.participant_user
            activityInfo = item.participant_activity
            userTypeInfo = item.participant_user_type

            tmpList.append(models.Participant.objects.filter(participant_activity = activityInfo, participant_user_type = 2)[0])
        
        resList = tmpList
            
    elif activityType == USERFOSTERLIST: 
        resList = models.Participant.objects.filter(participant_user__user_id=userId, participant_user_type=2)
        resListStatus = []
        for item in resList:
            resListStatus.append(item.participant_status)

        tmpList= []
        for item in resList:
            userInfo = item.participant_user
            activityInfo = item.participant_activity
            userTypeInfo = item.participant_user_type

            tmpList.append(models.Participant.objects.filter(participant_activity = activityInfo, participant_user_type = 1)[0])
        
        resList = tmpList
    else:
        return util.errorJsonWrapper("getUserInfoList中不支持改活动类型")

    #try:
    retValue = []
    for idx in range(len(resList)):
        retValueItem = {}
        userInfo = resList[idx].participant_user
        activityInfo = resList[idx].participant_activity

        retValueItem["activity_id"] = activityInfo.pk
        retValueItem["activity_picture"] = activityInfo.activity_picture
        retValueItem['activity_address'] = activityInfo.activity_address
        retValueItem['activity_price'] = activityInfo.activity_price
        retValueItem['activity_introduction'] = activityInfo.activity_introduction
        retValueItem['activity_pet_type'] = activityInfo.activity_pet_type
        retValueItem['activity_start_time'] = activityInfo.activity_start_time
        retValueItem['activity_end_time'] = activityInfo.activity_end_time
            
        
        retValueItem["user_id"] = userInfo.user_id
        retValueItem["user_nickname"] = userInfo.user_nickname
        retValueItem["user_avatar"] = userInfo.user_avatar
        retValueItem["user_address"] = userInfo.user_address
        retValueItem["user_age"] = userInfo.user_age
        retValueItem["user_interest"] = userInfo.user_interest
        retValueItem["user_gender"] = userInfo.user_gender
        retValueItem["user_authenticated"] = userInfo.user_authenticated
        
        if activityType == USERFOSTERLIST:
            retValueItem["participant_status"] = resListStatus[idx]

        retValue.append(retValueItem)

    if number >= 0:
        retValue = retValue[:number]

    result = {}

    result["retValue"] = retValue
    result["retCode"] = 0
    result["retMsg"] = ""

    return json.dumps(result)
Пример #42
0
def issueAdoptPetInfo(data, files):
    EVENT_STATUS = 1
    ADOPT = 1

    try:
        userId = data["user_id"]
    except KeyError:
        return util.errorJsonWrapper("请求数据没有user_id字段")
    try:
        userToken = data["user_token"]
    except KeyError:
        return util.errorJsonWrapper("请求数据没有token字段")

    if not util.checkToken(userId, userToken):
        return util.errorJsonWrapper("token 验证失败")

    user = models.User.objects.filter(user_id=userId).first()
    if not user:
        return util.errorJsonWrapper("不存在该用户")

    if not user.user_authenticated:
        return util.errorJsonWrapper("failed")

    activityIntro = data.get("activity_introduction")
    activityAddr = data.get("activity_address")
    activityLongi = data.get("activity_longitude")
    activityLati = data.get("activity_latitude")
    activityPet = data.get("activity_pet_type")
    activityPrice = data.get("activity_price")
    activityStartTime = data.get("activity_start_time")
    activityEndTime = data.get("activity_end_time")
    activityStartTime = time.strftime(
        "%Y-%m-%d", (time.strptime(activityStartTime, "%Y-%m-%d")))
    activityEndTime = time.strftime(
        "%Y-%m-%d", (time.strptime(activityEndTime, "%Y-%m-%d")))

    resDict = {}
    resDict['activity_introduction'] = activityIntro
    resDict['activity_address'] = activityAddr
    resDict['activity_longitude'] = activityLongi
    resDict['activity_latitude'] = activityLati
    resDict['activity_pet_type'] = activityPet
    resDict['activity_price'] = activityPrice
    resDict['activity_start_time'] = activityStartTime
    resDict['activity_end_time'] = activityEndTime
    resDict["user_id"] = user.user_id
    resDict["user_nickname"] = user.user_nickname
    resDict["user_avatar"] = user.user_avatar
    resDict["user_address"] = user.user_address
    resDict["user_age"] = user.user_age
    resDict["user_interest"] = user.user_interest
    resDict["user_gender"] = user.user_gender
    resDict["user_authenticated"] = user.user_authenticated

    picName = util.savePicture(files, "activity_picture", 20 * 1024 * 1024)
    if picName == -1:
        return util.errorJsonWrapper("failed")
    activityPic = picName

    try:

        activity = models.Activity(activity_introduction=activityIntro,
                                   activity_picture=activityPic,
                                   activity_price=activityPrice,
                                   activity_pet_type=activityPet,
                                   activity_start_time=activityStartTime,
                                   activity_end_time=activityEndTime,
                                   activity_status=EVENT_STATUS,
                                   activity_latitude=activityLati,
                                   activity_longitude=activityLongi,
                                   activity_address=activityAddr)
        activity.save()
    except Exception:
        return util.errorJsonWrapper("发布收养信息出错,activity无法写入数据库")

    resDict["activity_id"] = activity.pk
    resDict["activity_picture"] = picName

    try:
        participant = models.Participant(participant_user=user,
                                         participant_activity=activity,
                                         participant_user_type=ADOPT)
        participant.save()
    except Exception:
        return util.errorJsonWrapper("发布收养信息出错,participant无法写入数据库")

    #userDict = {"user_id" : userId}
    res = dict(retCode=0, retMsg="", retValue=resDict)
    return json.dumps(res)