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("该用户不存在")
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("该用户不存在")
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("该用户不存在")
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("该用户不存在")
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 数据写入数据库出错")
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)
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)
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)
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()
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()
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)
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 数据写入数据库出错")
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("请求信息列表失败")
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)
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("请求信息列表失败")
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("请求信息列表失败")
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)
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)