def AddEducation(TheEducation, ID): ''' 描述:添加一条教育信息到数据库 参数:一条教育信息(字典),用户openid 返回:成功True,失败False ''' Success = True TheStartYear = 0 TheDepartment = "" TheType = "" if Success: try: TheStartYear = int(TheEducation["enrollmentYear"]) TheDepartment = TheEducation["department"] TheType = TheEducation["enrollmentType"] except: Success = False if Success: try: TheUser = User.objects.get(OpenID=ID) Education.objects.create(StartYear=TheStartYear, Department=TheDepartment, Type=TheType, Student=TheUser) #如果有数据库中不存在的教育信息,插入 GlobalFunctions.AddEducationType(TheType) GlobalFunctions.AddDepartment(TheDepartment) except: Success = False return Success
def ShowAllMembersAdmin(TheUserID, TheActivityID): ''' 描述:查询活动所有成员---管理员 参数: 用户id,活动id 返回:第一个是一个字典,里面就一个字典数组participantList,每个字典有人员的Openid,权限,状态,报名和签到时间,失败为空 第二个是原因和错误码,如果成功就是空,否则有reason和code ''' Result = {} ErrorInfo = {} Reason = "" Code = 0 Success = True ResultList = [] if Success: try: if JudgeValid.JudgeWhetherManager(TheUserID, TheActivityID) != True: Success = False Reason = "权限不足,需要是管理员或创建者!" Code = Constants.ERROR_CODE_LACK_ACCESS TheActivity = Activity.objects.get(ID = TheActivityID) TheJoinActivityList = JoinInformation.objects.filter(ActivityId = TheActivity) except: Success = False Reason = "未找到活动!" Code = Constants.ERROR_CODE_NOT_FOUND if Success: try: for item in TheJoinActivityList: TheResult = {} TheResult["openId"] = item.UserId.OpenID TheResult["name"] = item.UserId.Name TheResult["avatarUrl"] = GlobalFunctions.GetTrueAvatarUrlUser(item.UserId.AvatarURL) TheResult["selfStatus"] = item.Status TheResult["selfRole"] = item.Role TheResult["point"] = item.UserId.Point TheResult["submitTime"] = GlobalFunctions.TimeStampToTimeString(item.SubmitTime) if item.JoinTime != Constants.UNDEFINED_NUMBER: TheResult["joinTime"] = GlobalFunctions.TimeStampToTimeString(item.JoinTime) if item.CheckTime != Constants.UNDEFINED_NUMBER: TheResult["checkTime"] = GlobalFunctions.TimeStampToTimeString(item.CheckTime) if JudgeValid.JudgeUserStatusJoined(item.Status) == True: ResultList.append(TheResult) except: Success = False Reason = "查询活动成员失败!" Code = Constants.ERROR_CODE_UNKNOWN if Success: Result["participantList"] = ResultList ErrorInfo = {} else: Result = {} ErrorInfo["reason"] = Reason ErrorInfo["code"] = Code return Result, ErrorInfo
def ShowSelfActivity(TheUserID): ''' 描述:查询自己参与过的所有活动和历史记录 参数: 自己的OpenID 返回:第一个是一个字典,里面就一个字典数组activityList,字典每个字典有活动具体信息和自己的情况,失败为空 第二个是失败状态信息,成功是空,失败有reason和code ''' Result = {} Success = True ResultList = [] ErrorInfo = {} Reason = "" Code = 0 if Success: try: TheUser = User.objects.get(OpenID = TheUserID) TheJoinActivityList = JoinInformation.objects.filter(UserId = TheUser) TheJoinActivityList = TheJoinActivityList.reverse() except: Success = False Reason = "未找到用户!" Code = Constants.ERROR_CODE_NOT_FOUND if Success: try: i = len(TheJoinActivityList) - 1 while i >= 0: item = TheJoinActivityList[i] TheResult = {} TheResult = ActivityManager.QueryActivity(item.ActivityId.ID) if TheResult == {}: continue TheResult["id"] = item.ActivityId.ID TheResult["selfStatus"] = item.Status TheResult["selfRole"] = item.Role TheResult["submitTime"] = GlobalFunctions.TimeStampToTimeString(item.SubmitTime) if item.JoinTime != Constants.UNDEFINED_NUMBER: TheResult["joinTime"] = GlobalFunctions.TimeStampToTimeString(item.JoinTime) if item.CheckTime != Constants.UNDEFINED_NUMBER: TheResult["checkTime"] = GlobalFunctions.TimeStampToTimeString(item.CheckTime) ResultList.append(TheResult) i -= 1 except: Success = False Reason = "查询历史记录失败!" Code = Constants.ERROR_CODE_UNKNOWN if Success: Result["activityList"] = ResultList ErrorInfo = {} else: Result = {} ErrorInfo["reason"] = Reason ErrorInfo["code"] = Code return Result, ErrorInfo
def AddCreatorIntoActivity(CreatorID, TheActivityID): ''' 描述:将创建者加入活动 参数:创建者id,活动id 返回:成功{result:success},失败{result:fail,reason:xxx, code:xxx} ''' Success = True Return = {} Code = Constants.UNDEFINED_NUMBER Reason = "" TheSubmitTime = -1 TheJoinTime = -1 TheCheckTime = -1 if Success: try: TheUser = User.objects.get(OpenID=CreatorID) TheActivity = Activity.objects.get(ID=TheActivityID) except: Success = False Reason = "未找到创建者或活动" Code = Constants.ERROR_CODE_NOT_FOUND if Success: try: TheSubmitTime = GlobalFunctions.GetCurrentTime() TheJoinTime = GlobalFunctions.GetCurrentTime() TheCheckTime = GlobalFunctions.GetCurrentTime() TheJoinReason = "无" TheStatus = Constants.USER_STATUS_CHECKED TheRole = Constants.USER_ROLE_CREATOR try: TheJoinInformation = JoinInformation.objects.get( UserId=TheUser, ActivityId=TheActivity) TheJoinInformation.delete() except: donothing = 0 TheJoinInformation = JoinInformation.objects.create(UserId = TheUser, ActivityId = TheActivity, Status = TheStatus,\ Role = TheRole, SubmitTime = TheSubmitTime, JoinTime = TheJoinTime, CheckTime = TheCheckTime, JoinReason = TheJoinReason) TheJoinInformation.save() TheActivity.CurrentUser = TheActivity.CurrentUser + 1 TheActivity.save() except: Success = False Reason = "将创建者加入活动失败" Code = Constants.ERROR_CODE_UNKNOWN if Success: Return["result"] = "success" else: Return["result"] = "fail" Return["reason"] = Reason Return["code"] = Code return Return
def UploadActivityQRCode(TheUserID, TheActivityID): ''' 描述:上传活动二维码 参数:用户openid,活动id 返回:结果,图片文件名(失败是None) ''' Success = True Result = {} Reason = "" TheImageName = "" Code = Constants.UNDEFINED_NUMBER print(TheUserID, TheActivityID) if Success: try: TheUser = User.objects.get(OpenID=TheUserID) TheActivity = Activity.objects.get(ID=TheActivityID) if JudgeValid.JudgeWhetherManager(TheUserID, TheActivityID) != True: Success = False Reason = "没有权限,只有管理员才能设置活动二维码!!" Code = Constants.ERROR_CODE_LACK_ACCESS except: Success = False Code = Constants.ERROR_CODE_NOT_FOUND Reason = "未找到该活动!" print(Success) if Success: if JudgeValid.JudgeActivityNormal(TheActivityID) != True: Success = False Reason = "活动状态为异常或结束,不能操作!" Code = Constants.ERROR_CODE_INVALID_CHANGE if Success: TheNewCode = GlobalFunctions.GenerateActivityCode() TheActivity.Code = TheNewCode TheActivity.save() TheImageName = GlobalFunctions.GenerateQRCode(TheActivityID, TheNewCode) if Success == True: Result["result"] = "success" else: Result["result"] = "fail" Result["reason"] = Reason Result["code"] = Code TheImageName = None return Result, TheImageName
def ChangeActivityStatusByTime(): ''' 描述:根据时间修改所有活动数据 参数: 无 返回:成功True, 失败False ''' Success = True if Success: try: Info = Activity.objects.all() except: Success = False if Success: try: for item in Info: if item.StatusGlobal != Constants.ACTIVITY_STATUS_GLOBAL_NORMAL: continue TheCurrentTime = GlobalFunctions.GetCurrentTime() TheJoinStartTime = item.SignUpStartTime TheJoinEndTime = item.SignUpEndTime TheCheckStartTime = item.StartTime TheCheckEndTime = item.EndTime TheCurrentUser = item.CurrentUser TheMinUser = item.MinUser if item.StatusJoin == Constants.ACTIVITY_STATUS_JOIN_BEFORE: if GlobalFunctions.JudgeWhetherSameMinute( TheJoinStartTime): item.StatusJoin = Constants.ACTIVITY_STATUS_JOIN_CONTINUE if item.StatusJoin != Constants.ACTIVITY_STATUS_JOIN_STOPPED: if GlobalFunctions.JudgeWhetherSameMinute(TheJoinEndTime): item.StatusJoin = Constants.ACTIVITY_STATUS_JOIN_STOPPED if item.StatusCheck == Constants.ACTIVITY_STATUS_CHECK_BEFORE: if GlobalFunctions.JudgeWhetherSameMinute( TheCheckStartTime ) and TheCurrentUser >= TheMinUser: item.StatusCheck = Constants.ACTIVITY_STATUS_CHECK_CONTINUE if item.StatusCheck != Constants.ACTIVITY_STATUS_CHECK_STOPPED: if GlobalFunctions.JudgeWhetherSameMinute(TheCheckEndTime): item.StatusCheck = Constants.ACTIVITY_STATUS_CHECK_STOPPED item.save() except: Success = False return Success
def ChangeActivityStatusFinish(): ''' 描述:根据时间(23:59)修改所有当天结束的活动为finish,并且修改成员状态 参数: 无 返回:成功True, 失败False ''' Success = True if GlobalFunctions.JudgeWhetherDayEnd() != True: return True if Success: try: Info = Activity.objects.all() except: Success = False if Success: try: for item in Info: if item.StatusGlobal != Constants.ACTIVITY_STATUS_GLOBAL_NORMAL: continue TheCheckEndTime = item.EndTime if GlobalFunctions.JudgeWhetherSameDay( TheCheckEndTime) != True: continue item.StatusGlobal = Constants.ACTIVITY_STATUS_GLOBAL_FINISH item.save() TheJoinActivityList = JoinInformation.objects.filter( ActivityId=item) for one in TheJoinActivityList: if one.Status == Constants.USER_STATUS_WAITVALIDATE: one.Status = Constants.USER_STATUS_REFUSED elif one.Status == Constants.USER_STATUS_JOINED: one.Status = Constants.USER_STATUS_FINISHED_WITHOUT_CHECK elif one.Status == Constants.USER_STATUS_CHECKED: one.Status = Constants.USER_STATUS_FINISHED if one.Role == Constants.USER_ROLE_CREATOR: one.UserId.Point += Constants.SUCCESS_GET_POINT_CREATOR else: one.UserId.Point += Constants.SUCCESS_GET_POINT_COMMON one.UserId.save() one.save() except: Success = False return Success
def AddUserActivity(TheUserID, TheActivityID, TheStatus, TheRole, TheJoinReason): ''' 描述:将一条报名信息加入数据库 参数:用户id,活动id,状态,权限,报名原因(没有就是None) 返回:成功{result:success},失败{result:fail,reason:xxx, code:xxx} ''' Success = True Return = {} Code = Constants.UNDEFINED_NUMBER Reason = "" TheSubmitTime = -1 TheJoinTime = -1 TheCheckTime = -1 if Success: try: TheUser = User.objects.get(OpenID = TheUserID) TheActivity = Activity.objects.get(ID = TheActivityID) except: Success = False Reason = "未找到用户或活动" Code = Constants.ERROR_CODE_NOT_FOUND if Success: try: TheSubmitTime = GlobalFunctions.GetCurrentTime() TheCheckTime = Constants.UNDEFINED_NUMBER if TheStatus != Constants.USER_STATUS_WAITVALIDATE: TheJoinTime = TheSubmitTime TheActivity.CurrentUser = TheActivity.CurrentUser + 1 else: TheCheckTime = Constants.UNDEFINED_NUMBER TheActivity.save() #print(TheJoinTime, TheCheckTime) if TheJoinReason == None: TheJoinReason = "无" try: TheJoinInformation = JoinInformation.objects.get(UserId = TheUser, ActivityId = TheActivity) TheJoinInformation.delete() except: donothing = 0 TheJoinInformation = JoinInformation.objects.create(UserId = TheUser, ActivityId = TheActivity, Status = TheStatus,\ Role = TheRole, SubmitTime = TheSubmitTime, JoinTime = TheJoinTime, CheckTime = TheCheckTime, JoinReason = TheJoinReason) TheJoinInformation.save() except: Success = False Reason = "添加记录失败" Code = Constants.ERROR_CODE_UNKNOWN if Success: Return["result"] = "success" else: Return["result"] = "fail" Return["reason"] = Reason Return["code"] = Code return Return
def QueryUser(ID): ''' 描述:给定用户id,查询用户具体信息 参数:用户id 返回:一个字典,里面有用户id,名字,性别,状态,教育信息(数组) 如果没有就返回空字典 { "name": "李肇阳", "campusIdentity": [ { "enrollmentYear": "2014", "department": "软件学院", "enrollmentType": "Undergraduate" }, { "enrollmentYear": "2018", "department": "软件学院", "enrollmentType": "Master" } ] } ''' Success = True Object = None #查询 if Success: try: Object = User.objects.get(OpenID=ID) except: Success = False #print(Info) Result = {} if Success: try: Result["name"] = Object.Name Result["avatarUrl"] = GlobalFunctions.GetTrueAvatarUrlUser( Object.AvatarURL) Result["status"] = Object.Status Result["point"] = Object.Point except: Success = False #处理教育信息数据 if Success: try: Result["campusIdentity"] = QueryEducation(Object.Education.all()) except: Success = False if Success == False: Result = {} return Result
def ReportActivity(TheUserID, TheActivityID, TheReportReason): ''' 描述:举报函数 参数:用户id,活动id, 举报原因 返回:成功{result: success},失败{result:fail,reason:xxx, code:xxx} ''' Success = True Reason = "" Return = {} Code = Constants.UNDEFINED_NUMBER TheStatus = -1 TheRole = -1 if Success: try: TheUser = User.objects.get(OpenID = TheUserID) TheActivity = Activity.objects.get(ID = TheActivityID) except: Success = False Reason = "未找到用户或活动" Code = Constants.ERROR_CODE_NOT_FOUND #print(Success) TheRole = Constants.USER_ROLE_COMMONER if Success: if JudgeValid.JudgeActivityNormal(TheActivityID) != True: Success = False Reason = "活动状态为异常或结束,不能操作!" Code = Constants.ERROR_CODE_INVALID_CHANGE if Success: try: TheSubmitTime = GlobalFunctions.GetCurrentTime() try: TheReportInformation = ReportInformation.objects.get(UserId = TheUser, ActivityId = TheActivity) TheReportInformation.delete() except: donothing = 0 TheReportInformation = ReportInformation.objects.create(UserId = TheUser, ActivityId = TheActivity, \ SubmitTime = TheSubmitTime, Reason = TheReportReason) TheReportInformation.save() except: Success = False Reason = "添加举报记录失败" Code = Constants.ERROR_CODE_UNKNOWN #print(Return) if Success: Return["result"] = "success" else: Return["result"] = "fail" Return["reason"] = Reason Return["code"] = Code return Return
def CheckActivitySendMessage(): ''' 描述:根据时间判断是否要推送活动即将开始的消息,并且控制消息的发送 参数: 无 返回:无 ''' Success = True if Success: if (int(time.time()) - lastAccessTokenSetTime > 5400): GlobalFunctions.SetAccessToken() if Success: try: Info = Activity.objects.all() except: Success = False if Success: try: for item in Info: if item.StatusGlobal != Constants.ACTIVITY_STATUS_GLOBAL_NORMAL: continue TheStartTime = item.StartTime if GlobalFunctions.JudgeWhetherSameMinute( TheStartTime - Constants.TIME_BEFORE_MESSAGE_ACTIVITY_WILL_START_HOUR ): SendTimedMessageActivity( item.ID, Constants.MESSAGE_TYPE_ACTIVITY_WILL_START_HOUR) elif GlobalFunctions.JudgeWhetherSameMinute( TheStartTime - Constants. TIME_BEFORE_MESSAGE_ACTIVITY_WILL_START_MINUTE): SendTimedMessageActivity( item.ID, Constants.MESSAGE_TYPE_ACTIVITY_WILL_START_MINUTE) except: Success = False return Success
def Login(TheUsername, ThePassword): ''' 描述:管理员登录的数据库函数 参数:用户名,密码 返回:成功{result:success} 失败:{result:fail,reason:xxx,code:xxx} 成功还有session ''' Success = True Reason = "" TheSession = "" Code = 0 Return = {} print(TheUsername, ThePassword) if Success: try: TheAdmin = Admin.objects.get(Username = TheUsername) except: Success = False Reason = "帐号不存在!" Code = Constants.ERROR_CODE_NOT_FOUND print(Success) if Success: try: if check_password(ThePassword, TheAdmin.Password) != True: Success = False Reason = "密码不正确!" Code = Constants.ERROR_CODE_NOT_FOUND except: Success = False Reason = "帐号不存在!" Code = Constants.ERROR_CODE_NOT_FOUND if Success: try: TheSession = GlobalFunctions.GenerateSessionID() TheAdmin.Session = TheSession TheAdmin.save() except: Success = False Reason = "登录失败!" Code = Constants.ERROR_CODE_UNKNOWN if Success: Return["result"] = "success" Return["session"] = TheSession else: Return["result"] = "fail" Return["reason"] = Reason Return["code"] = Code return Return
def ShowAllMembers(TheActivityID): ''' 描述:查询活动所有成员---一般用户 参数: 活动id 返回:第一个是一个字典,里面就一个字典数组participantList,每个字典有人员的Openid,权限,状态,失败为空 第二个是原因和错误码,如果成功就是空,否则有reason和code ''' Result = {} ErrorInfo = {} Success = True ResultList = [] Reason = "" Code = 0 if Success: try: TheActivity = Activity.objects.get(ID = TheActivityID) TheJoinActivityList = JoinInformation.objects.filter(ActivityId = TheActivity) except: Success = False Reason = "未找到活动!" Code = Constants.ERROR_CODE_NOT_FOUND if Success: try: for item in TheJoinActivityList: TheResult = {} TheResult["openId"] = item.UserId.OpenID TheResult["selfStatus"] = item.Status TheResult["selfRole"] = item.Role TheResult["name"] = item.UserId.Name TheResult["avatarUrl"] = GlobalFunctions.GetTrueAvatarUrlUser(item.UserId.AvatarURL) if JudgeValid.JudgeUserStatusJoined(item.Status): ResultList.append(TheResult) except: Success = False Reason = "查询活动成员失败!" Code = Constants.ERROR_CODE_UNKNOWN if Success: Result["participantList"] = ResultList ErrorInfo = {} else: Result = {} ErrorInfo["reason"] = Reason ErrorInfo["code"] = Code return Result, ErrorInfo
def QueryActivity(TheActivityID): ''' 描述:给定活动id,查询活动基本信息 参数:活动id 返回:一个字典,里面有活动各种信息 如果没有就返回空字典 ''' Success = True Result = {} if Success: try: Info = Activity.objects.get(ID=TheActivityID) Result["name"] = Info.Name Result["place"] = Info.Place Result["createTime"] = GlobalFunctions.TimeStampToTimeString( int(Info.CreateTime)) Result["start"] = GlobalFunctions.TimeStampToTimeString( int(Info.StartTime)) Result["end"] = GlobalFunctions.TimeStampToTimeString( int(Info.EndTime)) Result["signupBeginAt"] = GlobalFunctions.TimeStampToTimeString( int(Info.SignUpStartTime)) Result["signupStopAt"] = GlobalFunctions.TimeStampToTimeString( int(Info.SignUpEndTime)) Result["minUser"] = int(Info.MinUser) Result["maxUser"] = int(Info.MaxUser) Result["curUser"] = int(Info.CurrentUser) Result["type"] = Info.Type Result["statusGlobal"] = int(Info.StatusGlobal) Result["statusJoin"] = int(Info.StatusJoin) Result["statusCheck"] = int(Info.StatusCheck) Result["tags"] = GlobalFunctions.SplitTags(Info.Tags) Result["imageUrl"] = GlobalFunctions.GetTrueAvatarUrlActivity( Info.ImageURL) except: Success = False if Success == False: Result = {} return Result
def GetOneActivityInfo(self, TheID): TheResult = {} Success = True try: TheActivity = Activity.objects.get(ID=TheID) TheResult["id"] = TheID TheResult["name"] = TheActivity.Name TheResult["place"] = TheActivity.Place TheResult["createTime"] = GlobalFunctions.TimeStampToTimeString( int(TheActivity.CreateTime)) TheResult["start"] = GlobalFunctions.TimeStampToTimeString( int(TheActivity.StartTime)) TheResult["end"] = GlobalFunctions.TimeStampToTimeString( int(TheActivity.EndTime)) TheResult["signupBeginAt"] = GlobalFunctions.TimeStampToTimeString( int(TheActivity.SignUpStartTime)) TheResult["signupStopAt"] = GlobalFunctions.TimeStampToTimeString( int(TheActivity.SignUpEndTime)) TheResult["minUser"] = int(TheActivity.MinUser) TheResult["maxUser"] = int(TheActivity.MaxUser) TheResult["curUser"] = int(TheActivity.CurrentUser) TheResult["type"] = TheActivity.Type TheResult["statusGlobal"] = int(TheActivity.StatusGlobal) TheResult["statusJoin"] = int(TheActivity.StatusJoin) TheResult["statusCheck"] = int(TheActivity.StatusCheck) TheResult["imageUrl"] = GlobalFunctions.GetTrueAvatarUrlActivity( TheActivity.ImageURL) TheResult["tags"] = GlobalFunctions.SplitTags(TheActivity.Tags) #print(TheResult) if JudgeValid.JudgeActivityCanBeSearched(TheID) != True: Success = False except: Success = False if Success: return TheResult else: return {}
def AdvancedSearch(TheUserID, Information, TheLastSeenID, TheMost): ''' 描述:高级检索 参数:用户openid,检索信息,上一个id,最多 返回:Result, errorinfo ''' Success = True Return = {} ErrorInfo = {} Reason = "" Code = Constants.UNDEFINED_NUMBER SearchDictionary = {} if Success: try: TheUser = User.objects.get(OpenID=TheUserID) except: Success = False Reason = "用户不存在!" Code = Constants.ERROR_CODE_INVALID_PARAMETER #读取修改数据 if Success: try: if "place" in Information: SearchDictionary["place"] = Information["place"] else: SearchDictionary["place"] = "" if "startMin" in Information: SearchDictionary["startMin"] = int( GlobalFunctions.TimeStringToTimeStamp( Information["startMin"])) else: SearchDictionary["startMin"] = 0 if "startMax" in Information: SearchDictionary["startMax"] = int( GlobalFunctions.TimeStringToTimeStamp( Information["startMax"])) else: SearchDictionary["startMax"] = Constants.MAX_NUMBER if "endMin" in Information: SearchDictionary["endMin"] = int( GlobalFunctions.TimeStringToTimeStamp( Information["endMin"])) else: SearchDictionary["endMin"] = 0 if "endMax" in Information: SearchDictionary["endMax"] = int( GlobalFunctions.TimeStringToTimeStamp( Information["endMax"])) else: SearchDictionary["endMax"] = Constants.MAX_NUMBER if "signupBeginAtMin" in Information: SearchDictionary["signupBeginAtMin"] = int( GlobalFunctions.TimeStringToTimeStamp( Information["signupBeginAtMin"])) else: SearchDictionary["signupBeginAtMin"] = 0 if "signupBeginAtMax" in Information: SearchDictionary["signupBeginAtMax"] = int( GlobalFunctions.TimeStringToTimeStamp( Information["signupBeginAtMax"])) else: SearchDictionary["signupBeginAtMax"] = Constants.MAX_NUMBER if "signupStopAtMin" in Information: SearchDictionary["signupStopAtMin"] = int( GlobalFunctions.TimeStringToTimeStamp( Information["signupStopAtMin"])) else: SearchDictionary["signupStopAtMin"] = 0 if "signupStopAtMax" in Information: SearchDictionary["signupStopAtMax"] = int( GlobalFunctions.TimeStringToTimeStamp( Information["signupStopAtMax"])) else: SearchDictionary["signupStopAtMax"] = Constants.MAX_NUMBER if "type" in Information: SearchDictionary["type"] = Information["type"] else: SearchDictionary["type"] = "" if "statusGlobal" in Information: SearchDictionary["statusGlobal"] = Information["statusGlobal"] else: SearchDictionary["statusGlobal"] = Constants.UNDEFINED_NUMBER if "statusJoin" in Information: SearchDictionary["statusJoin"] = Information["statusJoin"] else: SearchDictionary["statusJoin"] = Constants.UNDEFINED_NUMBER if "statusCheck" in Information: SearchDictionary["statusCheck"] = Information["statusCheck"] else: SearchDictionary["statusCheck"] = Constants.UNDEFINED_NUMBER if "selfStatus" in Information: SearchDictionary["selfStatus"] = Information["selfStatus"] else: SearchDictionary["selfStatus"] = Constants.UNDEFINED_NUMBER - 1 if "ruleForMe" in Information: SearchDictionary["ruleForMe"] = Information["ruleForMe"] else: SearchDictionary["ruleForMe"] = Constants.UNDEFINED_NUMBER - 1 except: Success = False Reason = "高级检索格式不合法" Code = Constants.ERROR_CODE_INVALID_PARAMETER if Success: try: JudgeResult = {} JudgeResult = JudgeValid.JudgeSearchStatusValid(SearchDictionary["statusGlobal"], SearchDictionary["statusJoin"], \ SearchDictionary["statusCheck"], SearchDictionary["selfStatus"], SearchDictionary["ruleForMe"]) if JudgeResult["result"] != "success": Success = False Reason = JudgeResult["reason"] Code = JudgeResult["code"] JudgeResult = JudgeValid.JudgeSearchTimeValid( SearchDictionary["startMin"], SearchDictionary["startMax"]) if JudgeResult["result"] != "success": Success = False Reason = "最小开始时间必须小于等于最大开始时间!" Code = Constants.ERROR_CODE_INVALID_PARAMETER JudgeResult = JudgeValid.JudgeSearchTimeValid( SearchDictionary["endMin"], SearchDictionary["endMax"]) if JudgeResult["result"] != "success": Success = False Reason = "最小结束时间必须小于等于最大结束时间!" Code = Constants.ERROR_CODE_INVALID_PARAMETER JudgeResult = JudgeValid.JudgeSearchTimeValid( SearchDictionary["signupBeginAtMin"], SearchDictionary["signupBeginAtMax"]) if JudgeResult["result"] != "success": Success = False Reason = "最小开始报名时间必须小于等于最大开始报名时间!" Code = Constants.ERROR_CODE_INVALID_PARAMETER JudgeResult = JudgeValid.JudgeSearchTimeValid( SearchDictionary["signupStopAtMin"], SearchDictionary["signupStopAtMax"]) if JudgeResult["result"] != "success": Success = False Reason = "最小结束报名时间必须小于等于最大结束报名时间!" Code = Constants.ERROR_CODE_INVALID_PARAMETER except: Success = False Reason = "高级检索格式不合法" Code = Constants.ERROR_CODE_INVALID_PARAMETER SearchResult = [] #查询时间,地点,状态,直接数据库函数 if Success: try: QuerySet = Activity.objects.all() Conditions = {'StartTime__gte': SearchDictionary["startMin"], 'StartTime__lte': SearchDictionary["startMax"],\ 'EndTime__gte': SearchDictionary["endMin"], 'EndTime__lte': SearchDictionary["endMax"],\ 'SignUpStartTime__gte': SearchDictionary["signupBeginAtMin"], 'SignUpStartTime__lte': SearchDictionary["signupBeginAtMax"],\ 'SignUpEndTime__gte': SearchDictionary["signupStopAtMin"], 'SignUpEndTime__lte': SearchDictionary["signupStopAtMax"]} if SearchDictionary["statusGlobal"] != Constants.UNDEFINED_NUMBER: Conditions['StatusGlobal'] = SearchDictionary["statusGlobal"] if SearchDictionary["statusJoin"] != Constants.UNDEFINED_NUMBER: Conditions['StatusJoin'] = SearchDictionary["statusJoin"] if SearchDictionary["statusCheck"] != Constants.UNDEFINED_NUMBER: Conditions['StatusCheck'] = SearchDictionary["statusCheck"] if SearchDictionary["place"] != '': Conditions["Place__icontains"] = SearchDictionary["place"] SearchResult = QuerySet.filter(**Conditions) except: Success = False Reason = "高级检索失败" Code = Constants.ERROR_CODE_UNKNOWN #查询活动类型,加入后结果等 NewSearchResult = [] if Success: try: i = len(SearchResult) - 1 while i >= 0: item = SearchResult[i] WhetherMatch = True if SearchDictionary["type"] != "": if JudgeValid.JudgeActivityTypeMatch( SearchDictionary["type"], item.Type) != True: WhetherMatch = False if SearchDictionary[ "selfStatus"] != Constants.UNDEFINED_NUMBER - 1: TheStatus = JudgeValid.GetSelfStatus(TheUserID, item.ID) if TheStatus != SearchDictionary["selfStatus"]: WhetherMatch = False if SearchDictionary[ "ruleForMe"] != Constants.UNDEFINED_NUMBER - 1: TheRule = JudgeValid.GetSelfJoinStatus(TheUserID, item.ID) if TheRule != SearchDictionary["ruleForMe"]: WhetherMatch = False if JudgeValid.JudgeActivityCanBeSearched(item.ID) != True: WhetherMatch = False if WhetherMatch == True: print(item.ID) TheInfo = QueryActivity(item.ID) TheInfo["id"] = item.ID NewSearchResult.append(TheInfo) i -= 1 except: Success = False Reason = "高级检索失败" Code = Constants.ERROR_CODE_UNKNOWN ReturnList = [] #分页显示 if Success: CurrentNum = 0 WhetherFindStart = False if TheLastSeenID == Constants.UNDEFINED_NUMBER: WhetherFindStart = True for item in NewSearchResult: if WhetherFindStart == True: if TheMost != Constants.UNDEFINED_NUMBER and CurrentNum >= TheMost: break ReturnList.append(item) CurrentNum += 1 if TheLastSeenID != Constants.UNDEFINED_NUMBER and item[ "id"] == TheLastSeenID: WhetherFindStart = True #print(NewSearchResult) if Success == False: ErrorInfo["reason"] = Reason ErrorInfo["code"] = Code else: Return["activityList"] = ReturnList ErrorInfo = {} return Return, ErrorInfo
def UploadPicture(request): ''' 描述:处理上传图片 参数:request 成功返回url 失败则是 { "errid":xxx, "errmsg":"xxxx" } ''' Success = True Return = {} Info = {} Reason = "" ErrorID = Constants.UNDEFINED_NUMBER TheSession = "" TheUserID = "" TheData = None TheURL = "" #获取请求数据 if Success: try: TheSession = request.GET.get("session") TheData = request.FILES.get("file") except: Success = False Reason = "请求参数不合法!" ErrorID = Constants.ERROR_CODE_INVALID_PARAMETER #判断是否登录,获取待查询的openid if Success: try: TheUserID = UserManager.GetCurrentUser(TheSession) if TheUserID == None: Success = False Reason = "用户未登录!" ErrorID = Constants.ERROR_CODE_LOGIN_ERROR except: Success = False Reason = "用户未登录!" ErrorID = Constants.ERROR_CODE_LOGIN_ERROR #调用数据库函数 if Success: try: Info = GlobalFunctions.UploadPicture(TheData) #print(Info) if Info["result"] == "success": TheURL = Info["url"] else: Success = False Reason = Info["reason"] ErrorID = Info["code"] except: Success = False Reason = "上传图片失败!" ErrorID = Constants.ERROR_CODE_NOT_FOUND if Success: Return["result"] = "success" Return["url"] = TheURL else: Return["errid"] = ErrorID Return["errmsg"] = Reason Response = JsonResponse(Return) if Success == True: Response.status_code = 200 else: Response.status_code = 400 return Response
from Alumni.LogicManager import JudgeValid from Alumni.DatabaseManager import UserManager from Alumni.DatabaseManager import ActivityManager from Alumni.DatabaseManager import UserActivityManager from Alumni.DatabaseManager import SearchAndRecommend from Alumni.DatabaseManager import AdminManager from Alumni.DatabaseManager import TimeManager from Alumni.RequestHandler import UserHandler from Alumni.RequestHandler import ActivityHandler from Alumni.RequestHandler import UserActivityHandler from Alumni.RequestHandler import SearchHandler from Alumni.RequestHandler import OtherHandler from Alumni.RequestHandler import AdminHandler TheSearcher = SearchAndRecommend.WhooshSearcher.Create() print(GlobalFunctions.SetAccessToken()) print(GlobalFunctions.GetAccessToken()) AdminManager.AddAdmin("kebab", "reich") urlpatterns = [ #处理用户请求url url(r'^login$', UserHandler.LoginUser), url(r'^alumniCheck$', UserHandler.GetAlumniInfo), url(r'^qhrcallback$', UserHandler.ReceiveAlunmiInfo), url(r'^userData$', UserHandler.QueryUser), url(r'^setAvatarUrl$', UserHandler.SetAvatarURL), url(r'^setExtraData$', UserHandler.SetExtraData), #处理活动请求url url(r'^createActivity$', ActivityHandler.StartActivity), url(r'^modifyActivity$', ActivityHandler.ChangeActivity),
def AddActivity(ID, Information): ''' 描述:添加一个活动到数据库 参数:创建者ID,数据信息 返回:{result:success,activityId:xxx}/失败{result:fail,reason:xxx, code:xxx} ''' Return = {} Success = True Code = Constants.UNDEFINED_NUMBER Reason = "" CurTime = 0 StartTime = 0 EndTime = 0 StartSignTime = 0 StopSignTime = 0 TheMinUser = 0 TheMaxUser = 0 TheStatus = 0 TheSearched = False TheGlobalRule = -1 TheAcceptRule = [] TheAuditRule = [] TheRejectRule = [] TheType = "" #把时间转化为时间戳,并且判断时间和人数是否合法 if Success: try: CurTime = GlobalFunctions.GetCurrentTime() StartTime = GlobalFunctions.TimeStringToTimeStamp( Information["start"]) EndTime = GlobalFunctions.TimeStringToTimeStamp(Information["end"]) if 'signupBeginAt' in Information: StartSignTime = GlobalFunctions.TimeStringToTimeStamp( Information["signupBeginAt"]) else: StartSignTime = CurTime if 'signupStopAt' in Information: StopSignTime = GlobalFunctions.TimeStringToTimeStamp( Information["signupStopAt"]) else: StopSignTime = StartTime if 'minUser' in Information: TheMinUser = int(Information["minUser"]) else: TheMinUser = 0 if 'maxUser' in Information: TheMaxUser = int(Information["maxUser"]) else: TheMaxUser = Constants.UNDEFINED_NUMBER JudgeResult = JudgeValid.JudgeParameterValid( CurTime, StartTime, EndTime, StartSignTime, StopSignTime, 1, TheMinUser, TheMaxUser) if "imageUrl" in Information: TheImageURL = Information["imageUrl"] else: TheImageURL = "UNDEFINED" if "position" in Information: ThePosition = Information["position"] else: ThePosition = "" if JudgeResult["result"] != "success": Success = False Reason = JudgeResult["reason"] Code = Constants.ERROR_CODE_INVALID_CHANGE except: Success = False Reason = "输入的开始/结束/开始报名/报名截止时间不合理!" Code = Constants.ERROR_CODE_INVALID_PARAMETER #判断活动状态,类型等是否合法 if Success: try: TheType = Information["type"] TheSearched = bool(Information["canBeSearched"]) if JudgeValid.JudgeActivityTypeValid(TheType) == False: Success = False Reason = "活动类型不合法,添加活动失败!" Code = Constants.ERROR_CODE_INVALID_PARAMETER TheStatusGlobal = GlobalFunctions.GetStartActivityGlobalStatus( TheType) TheStatusJoin = GlobalFunctions.GetStartActivityJoinStatus( StartSignTime, StopSignTime) TheStatusCheck = GlobalFunctions.GetStartActivityCheckStatus( StartTime, EndTime) except: Success = False Reason = "参数不合法,添加活动失败!" Code = Constants.ERROR_CODE_INVALID_PARAMETER #获得标签,正文,头像 if Success: try: TheTagsList = Information["tags"] TheDescription = Information["description"] if JudgeValid.JudgeTagListValid(TheTagsList) != True: Success = False Reason = "参数不合法,标签不能带有英文逗号!" Code = Constants.ERROR_CODE_INVALID_PARAMETER TheTags = GlobalFunctions.MergeTags(TheTagsList) except: Success = False Reason = "参数不合法,添加活动失败!" Code = Constants.ERROR_CODE_INVALID_PARAMETER #获得高级报名信息 if Success: try: #判断是否合法 TheGlobalRule = Information["rules"]["ruleType"] if JudgeValid.JudgeRuleTypeValid(TheGlobalRule) != True: Success = False Reason = "参数不合法,规则类型不合法!" Code = Constants.ERROR_CODE_INVALID_PARAMETER TheJudgeAdvanceRuleResult = JudgeValid.JudgeAdvancedRuleValid( Information["rules"]) #print(TheJudgeAdvanceRuleResult) if TheJudgeAdvanceRuleResult["result"] != "success": Success = False Reason = TheJudgeAdvanceRuleResult["reason"] Code = TheJudgeAdvanceRuleResult["code"] try: TheAcceptRule = Information["rules"]["accept"] except: TheAcceptRule = [] try: TheAuditRule = Information["rules"]["needAudit"] except: TheAuditRule = [] try: TheRejectRule = Information["rules"]["reject"] except: TheRejectRule = [] except: Success = False Reason = "参数不合法,添加活动失败!" Code = Constants.ERROR_CODE_INVALID_PARAMETER #print(CurTime, StartTime, EndTime, StartSignTime, StopSignTime) #print(Success) #插入数据库 if Success: try: TheName = Information["name"] ThePlace = Information["place"] #TheCreator = User.objects.get(OpenID = ID) #print(TheCreator.ID) TheCreateTime = GlobalFunctions.GetCurrentTime() NewActivity = Activity.objects.create(Name = TheName, Place = ThePlace, CreateTime = TheCreateTime, StartTime = StartTime, EndTime = EndTime, SignUpStartTime = StartSignTime,\ SignUpEndTime = StopSignTime, MinUser = TheMinUser, MaxUser = TheMaxUser, CurrentUser = 0, Type = TheType, \ StatusGlobal = TheStatusGlobal, StatusJoin = TheStatusJoin, StatusCheck = TheStatusCheck, CanBeSearched = TheSearched, \ GlobalRule = TheGlobalRule, Tags = TheTags, Description = TheDescription, ImageURL = TheImageURL, GPSPlace = ThePosition) NewActivity.save() ActivityID = NewActivity.ID TheSearcher = SearchAndRecommend.WhooshSearcher.Create() TheSearcher.AddOneInfo(ActivityID, TheName + ',' + TheTags) except: Success = False Reason = "参数不合法,添加活动失败!" Code = Constants.ERROR_CODE_INVALID_PARAMETER if Success: if "rules" in Information: try: #添加rules for item in TheAcceptRule: AddAdvancedRules(ActivityID, item, Constants.ADVANCED_RULE_ACCEPT) for item in TheAuditRule: AddAdvancedRules(ActivityID, item, Constants.ADVANCED_RULE_AUDIT) for item in TheRejectRule: AddAdvancedRules(ActivityID, item, Constants.ADVANCED_RULE_REJECT) except: Success = False Reason = "参数不合法,添加活动失败!" Code = Constants.ERROR_CODE_INVALID_PARAMETER #print(Success) #让creator加入活动 if Success: try: #print(int(Return["id"])) JoinActivityResult = AddCreatorIntoActivity(ID, ActivityID) if JoinActivityResult["result"] != "success": Success = False Reason = JoinActivityResult["reason"] Code = JoinActivityResult["code"] else: Return["activityId"] = ActivityID except: Success = False Reason = "添加活动失败" Code = Constants.ERROR_CODE_UNKNOWN if Success: if TheStatusGlobal == Constants.ACTIVITY_STATUS_GLOBAL_NORMAL: Return["result"] = "success" else: Return["result"] = "needAudit" else: Return["result"] = "fail" Return["reason"] = Reason Return["code"] = Code return Return
def GetAlumniInfo(request): ''' 描述:获取校友信息 参数:request 成功返回: { "params": { "appId": "wx1ebe3b2266f4afe0", "path": "pages/index/index", "envVersion": "develop", "extraData": { "origin": "miniapp", "ticket": "52ec7c69-9d7c-4495-b07f-7e10ab4ad24f", "type": "oauth" } } } 失败返回: {"errid": 101, "errmsg": "身份信息不存在"} ''' Success = True Return = {} Info = {} TheParam = {} TheJson = {} ErrorId = Constants.UNDEFINED_NUMBER Reason = "" TheSession = "" TheOpenID = "" TheSessionKey = "" if Success: try: TheSession = request.GET.get("session") except: Success = False ErrorId = Constants.ERROR_CODE_INVALID_PARAMETER Reason = "请求参数不合法!" if Success: try: TheParam = GlobalFunctions.GetAppIDThis() except: Success = False ErrorId = Constants.ERROR_CODE_INVALID_PARAMETER Reason = "请求参数不合法!" #换取openid 和 key #print(TheParam) if Success: try: TheRequest = requests.post( "https://alumni-test.iterator-traits.com/fake-info-tsinghua-org/mp/oauth/initiate/miniapp", data=json.dumps(TheParam), timeout=(5, 10), allow_redirects=True) except: Success = False ErrorId = Constants.ERROR_CODE_NETWORK_ERROR Reason = "网络繁忙,访问超时!" #print(TheRequest) if Success: try: if TheRequest.status_code < 200 or TheRequest.status_code >= 400: Success = False ErrorId = Constants.ERROR_CODE_NETWORK_ERROR Reason = "网络繁忙,访问清华人失败!!" TheJson = TheRequest.json() TheRequestID = TheJson["requestId"] Info = TheJson["params"] except: Success = False ErrorId = Constants.ERROR_CODE_NETWORK_ERROR Reason = "网络繁忙,访问清华人失败!" if Success: if UserManager.AddRequestID(TheSession, TheRequestID) != True: Success = False ErrorId = Constants.ERROR_CODE_LOGIN_ERROR Reason = "用户未登录!" if Success == False: Return["errid"] = ErrorId Return["errmsg"] = Reason else: Return["params"] = Info Response = JsonResponse(Return) if Success == True: Response.status_code = 200 else: Response.status_code = 400 return Response
def LoginUser(request): ''' 描述:处理登录请求 参数:request 成功返回: { "result": "success", "session": "123456abcdef", "openId": "asfsfs" } 失败返回: {"errid": 101, "errmsg": "身份信息不存在"} ''' Success = True Return = {} Info = {} TheParam = {} ErrorId = Constants.UNDEFINED_NUMBER Reason = "" TheCode = "" TheSession = "" TheOpenID = "" TheSessionKey = "" if Success: try: TheCode = request.GET.get("code") except: Success = False ErrorId = Constants.ERROR_CODE_INVALID_PARAMETER Reason = "请求参数不合法!" if Success: try: TheParam = {} TheParam = GlobalFunctions.GetAppIDWechat() TheParam["js_code"] = TheCode TheParam["grant_type"] = "authorization_code" except: Success = False ErrorId = Constants.ERROR_CODE_INVALID_PARAMETER Reason = "请求参数不合法!" #换取openid 和 key #print(TheParam) if Success: try: TheRequest = requests.get( "https://api.weixin.qq.com/sns/jscode2session", params=TheParam, timeout=(5, 10), allow_redirects=True) except: Success = False ErrorId = Constants.ERROR_CODE_NETWORK_ERROR Reason = "网络繁忙,访问超时!" if Success: try: if TheRequest.status_code < 200 or TheRequest.status_code >= 400: Success = False ErrorId = Constants.ERROR_CODE_NETWORK_ERROR Reason = "网络繁忙,访问微信失败!!" TheJson = TheRequest.json() #print(TheJson) if "errcode" in TheJson: if TheJson["errcode"] == -1: Success = False ErrorId = Constants.ERROR_CODE_NETWORK_ERROR Reason = "网络繁忙,访问微信失败!" elif TheJson["errcode"] == 40029: Success = False ErrorId = Constants.ERROR_CODE_INVALID_PARAMETER Reason = "Code无效!" elif TheJson["errcode"] == 45011: Success = False ErrorId = Constants.ERROR_CODE_INVALID_CHANGE Reason = "访问过于频繁,每个用户每分钟最多访问100次!" elif TheJson["errcode"] != 0: Success = False ErrorId = Constants.ERROR_CODE_NETWORK_ERROR Reason = TheJson["errmsg"] except: Success = False ErrorId = Constants.ERROR_CODE_NETWORK_ERROR Reason = "网络繁忙,访问微信失败!" if Success: try: TheOpenID = TheJson["openid"] TheSessionKey = TheJson["session_key"] except: Success = False ErrorId = Constants.ERROR_CODE_NETWORK_ERROR Reason = "网络繁忙,访问微信失败!" if Success: try: TheSession = GlobalFunctions.GenerateSessionID() except: Success = False ErrorId = Constants.ERROR_CODE_UNKNOWN Reason = "生成session失败!" if Success: try: Return = UserManager.AddUserID(TheOpenID, TheSessionKey, TheSession) except: Success = False ErrorId = Constants.ERROR_CODE_UNKNOWN Reason = "访问数据库失败!" if Success == False: Return["errid"] = ErrorId Return["errmsg"] = Reason Response = JsonResponse(Return) if Success == True: Response.status_code = 200 else: Response.status_code = 400 return Response
def ShowAllAuditMembers(TheUserID, TheActivityID): ''' 描述:查询活动所有待审核成员---管理员 参数: 用户id,活动id 返回: 第一个是一个字典,失败为空,成功格式如下 { "members": [ { "openId": "xxxxxxx", "name": "李大爷", "submitTime": "2019-11-01 08:00:00", "submitMsg": "我是管理员的爸爸,不让我参加?" } ] } 第二个是错误信息,成功空字典,否则有reason和code ''' Result = {} ErrorInfo = {} Reason = "" Code = 0 Success = True ResultList = [] if Success: try: if JudgeValid.JudgeWhetherManager(TheUserID, TheActivityID) != True: Success = False Reason = "权限不足,需要是管理员或创建者!" Code = Constants.ERROR_CODE_LACK_ACCESS TheActivity = Activity.objects.get(ID = TheActivityID) TheJoinActivityList = JoinInformation.objects.filter(ActivityId = TheActivity) if TheActivity.CanBeSearched != True: Success = False Reason = "未找到活动!" Code = Constants.ERROR_CODE_NOT_FOUND except: Success = False Reason = "未找到活动!" Code = Constants.ERROR_CODE_NOT_FOUND if Success: try: for item in TheJoinActivityList: TheResult = {} if item.Status == Constants.USER_STATUS_WAITVALIDATE: TheResult["openId"] = item.UserId.OpenID TheResult["name"] = item.UserId.Name TheResult["avatarUrl"] = GlobalFunctions.GetTrueAvatarUrlUser(item.UserId.AvatarURL) TheResult["submitTime"] = GlobalFunctions.TimeStampToTimeString(item.SubmitTime) TheResult["point"] = item.UserId.Point TheResult["submitMsg"] = item.JoinReason ResultList.append(TheResult) except: Success = False Reason = "查询待审核成员失败!" Code = Constants.ERROR_CODE_UNKNOWN if Success: Result["users"] = ResultList ErrorInfo = {} else: Result = {} ErrorInfo["reason"] = Reason ErrorInfo["code"] = Code return Result, ErrorInfo
def ChangeActivity(TheUserID, Information): ''' 描述:修改活动信息 参数:用户openid,待修改信息 返回:{result:success}/{result:fail,reason:xxx, code:xxx} ''' Success = True Return = {} Reason = "" Code = Constants.UNDEFINED_NUMBER ChangeDictionary = {} #判断是否能找到这个活动 if Success: try: TheUser = User.objects.get(OpenID=TheUserID) TheActivity = Activity.objects.get(ID=Information["id"]) if JudgeValid.JudgeWhetherManager(TheUserID, Information["id"]) != True: Success = False Reason = "没有修改权限,需要是管理员或者创建者!" Code = Constants.ERROR_CODE_LACK_ACCESS except: Success = False Reason = "没有修改权限" Code = Constants.ERROR_CODE_LACK_ACCESS if Success: if JudgeValid.JudgeActivityNormal(Information["id"]) != True: Success = False Reason = "活动状态为异常或结束,不能操作!" Code = Constants.ERROR_CODE_INVALID_CHANGE #读取修改数据 WhetherJudgeTime = False if Success: try: if "name" in Information: ChangeDictionary["name"] = Information["name"] else: ChangeDictionary["name"] = TheActivity.Name if "place" in Information: ChangeDictionary["place"] = Information["place"] else: ChangeDictionary["place"] = TheActivity.Place if "start" in Information: WhetherJudgeTime = True ChangeDictionary["start"] = int( GlobalFunctions.TimeStringToTimeStamp( Information["start"])) else: ChangeDictionary["start"] = TheActivity.StartTime if "end" in Information: WhetherJudgeTime = True ChangeDictionary["end"] = int( GlobalFunctions.TimeStringToTimeStamp(Information["end"])) else: ChangeDictionary["end"] = TheActivity.EndTime if "signupBeginAt" in Information: WhetherJudgeTime = True ChangeDictionary["signupBeginAt"] = int( GlobalFunctions.TimeStringToTimeStamp( Information["signupBeginAt"])) else: ChangeDictionary["signupBeginAt"] = TheActivity.SignUpStartTime if "signupStopAt" in Information: WhetherJudgeTime = True ChangeDictionary["signupStopAt"] = int( GlobalFunctions.TimeStringToTimeStamp( Information["signupStopAt"])) else: ChangeDictionary["signupStopAt"] = TheActivity.SignUpEndTime if "minUser" in Information: ChangeDictionary["minUser"] = int(Information["minUser"]) else: ChangeDictionary["minUser"] = TheActivity.MinUser if "maxUser" in Information: ChangeDictionary["maxUser"] = int(Information["maxUser"]) else: ChangeDictionary["maxUser"] = TheActivity.MaxUser if "type" in Information: ChangeDictionary["type"] = Information["type"] else: ChangeDictionary["type"] = TheActivity.Type if "statusGlobal" in Information: ChangeDictionary["statusGlobal"] = Information["statusGlobal"] else: ChangeDictionary["statusGlobal"] = TheActivity.StatusGlobal if "statusJoin" in Information: ChangeDictionary["statusJoin"] = Information["statusJoin"] else: ChangeDictionary["statusJoin"] = TheActivity.StatusJoin if "statusCheck" in Information: ChangeDictionary["statusCheck"] = Information["statusCheck"] else: ChangeDictionary["statusCheck"] = TheActivity.StatusCheck if "canBeSearched" in Information: ChangeDictionary["canBeSearched"] = bool( Information["canBeSearched"]) else: ChangeDictionary["canBeSearched"] = TheActivity.CanBeSearched if "imageUrl" in Information: ChangeDictionary["imageUrl"] = Information["imageUrl"] else: ChangeDictionary["imageUrl"] = TheActivity.ImageURL if "position" in Information: ChangeDictionary["position"] = Information["position"] else: ChangeDictionary["position"] = TheActivity.GPSPlace if "tags" in Information: if JudgeValid.JudgeTagListValid(Information["tags"]) != True: Success = False Reason = "参数不合法,标签不能带有英文逗号!" Code = Constants.ERROR_CODE_INVALID_PARAMETER ChangeDictionary["tags"] = GlobalFunctions.MergeTags( Information["tags"]) else: ChangeDictionary["tags"] = TheActivity.Tags #如果rules不存在就changedictionary为空,要判断 if "rules" in Information: if "ruleType" in Information["rules"]: ChangeDictionary["ruleType"] = Information["rules"][ "ruleType"] else: ChangeDictionary["ruleType"] = TheActivity.GlobalRule ChangeDictionary["rules"] = Information["rules"] else: ChangeDictionary["rules"] = [] ChangeDictionary["ruleType"] = TheActivity.GlobalRule ChangeDictionary["curTime"] = GlobalFunctions.GetCurrentTime() ChangeDictionary["curUser"] = TheActivity.CurrentUser except: Success = False Reason = "待修改数据格式不合法" Code = Constants.ERROR_CODE_INVALID_PARAMETER #print(Success) #判断活动type修改后是否有效 if Success: try: JudgeResult = JudgeValid.JudgeTypeChangeValid( TheActivity.Type, ChangeDictionary["type"], TheActivity.StatusGlobal) if JudgeResult["result"] != "success": Success = False Reason = JudgeResult["reason"] Code = JudgeResult["code"] except: Success = False Reason = "待修改数据格式不合法" Code = Constants.ERROR_CODE_INVALID_PARAMETER #判断时间,人数等修改后是否有效 if Success and WhetherJudgeTime: try: JudgeResult = JudgeValid.JudgeParameterValid(ChangeDictionary["curTime"], ChangeDictionary["start"], ChangeDictionary["end"], \ ChangeDictionary["signupBeginAt"], ChangeDictionary["signupStopAt"], ChangeDictionary["curUser"], ChangeDictionary["minUser"], \ ChangeDictionary["maxUser"]) if JudgeResult["result"] != "success": Success = False Reason = JudgeResult["reason"] Code = Constants.ERROR_CODE_INVALID_CHANGE except: Success = False Reason = "待修改数据格式不合法" Code = Constants.ERROR_CODE_INVALID_PARAMETER if Success and ChangeDictionary["maxUser"] != Constants.UNDEFINED_NUMBER: try: if ChangeDictionary["minUser"] > ChangeDictionary["maxUser"]: Success = False Reason = "最小人数不能大于最大人数!" Code = Constants.ERROR_CODE_INVALID_CHANGE if ChangeDictionary["curUser"] > ChangeDictionary["maxUser"]: Success = False Reason = "当前人数不能大于最大人数!" Code = Constants.ERROR_CODE_INVALID_CHANGE except: Success = False Reason = "待修改数据格式不合法" Code = Constants.ERROR_CODE_INVALID_PARAMETER #判断状态等改后是否有效 if Success: try: JudgeResult = JudgeValid.JudgeActivityStatusChangeValid( TheActivity.StatusGlobal, ChangeDictionary["statusGlobal"]) if JudgeResult["result"] != "success": Success = False Reason = JudgeResult["reason"] Code = Constants.ERROR_CODE_INVALID_CHANGE if JudgeValid.JudgeActivityStatusJoinValid( ChangeDictionary["statusJoin"]) != True: Success = False Reason = "待修改的活动加入状态不合法" Code = Constants.ERROR_CODE_INVALID_PARAMETER if JudgeValid.JudgeActivityStatusCheckValid( ChangeDictionary["statusCheck"]) != True: Success = False Reason = "待修改的活动签到状态不合法" Code = Constants.ERROR_CODE_INVALID_PARAMETER if JudgeValid.JudgeRuleTypeValid( ChangeDictionary["ruleType"]) != True: Success = False Reason = "待修改的活动规则类型不合法!" Code = Constants.ERROR_CODE_INVALID_PARAMETER except: Success = False Reason = "待修改数据格式不合法" Code = Constants.ERROR_CODE_INVALID_PARAMETER #判断高级规则等改后是否有效 if Success: try: if ChangeDictionary["rules"] != []: JudgeResult = JudgeValid.JudgeAdvancedRuleValid( ChangeDictionary["rules"]) if JudgeResult["result"] != "success": Success = False Reason = JudgeResult["reason"] Code = Constants.ERROR_CODE_INVALID_CHANGE except: Success = False Reason = "待修改数据格式不合法" Code = Constants.ERROR_CODE_INVALID_PARAMETER #修改 #print(Success) if Success: try: TheActivity.Name = ChangeDictionary["name"] TheActivity.Place = ChangeDictionary["place"] TheActivity.StartTime = ChangeDictionary["start"] TheActivity.EndTime = ChangeDictionary["end"] TheActivity.SignUpStartTime = ChangeDictionary["signupBeginAt"] TheActivity.SignUpEndTime = ChangeDictionary["signupStopAt"] TheActivity.MinUser = ChangeDictionary["minUser"] TheActivity.MaxUser = ChangeDictionary["maxUser"] TheActivity.Type = ChangeDictionary["type"] TheActivity.StatusGlobal = ChangeDictionary["statusGlobal"] TheActivity.StatusJoin = ChangeDictionary["statusJoin"] TheActivity.StatusCheck = ChangeDictionary["statusCheck"] TheActivity.CanBeSearched = ChangeDictionary["canBeSearched"] TheActivity.GlobalRule = ChangeDictionary["ruleType"] TheActivity.Tags = ChangeDictionary["tags"] TheActivity.ImageURL = ChangeDictionary["imageUrl"] TheActivity.GPSPlace = ChangeDictionary["position"] TheActivity.save() TheSearcher = SearchAndRecommend.WhooshSearcher.Create() TheSearcher.UpdateOneInfo( Information["id"], TheActivity.Name + ',' + TheActivity.Tags) except: Success = False Reason = "修改数据失败" Code = Constants.ERROR_CODE_UNKNOWN if Success: try: #print(ChangeDictionary["rules"], Information["id"]) if ChangeDictionary["rules"] != []: #修改高级报名规则 if ChangeAdvancedRules(Information["id"], ChangeDictionary["rules"]) != True: Success = False Reason = "修改数据失败" Code = Constants.ERROR_CODE_UNKNOWN except: Success = False Reason = "修改数据失败" Code = Constants.ERROR_CODE_UNKNOWN if Success == False: Return["result"] = "fail" Return["reason"] = Reason Return["code"] = Code else: Return["result"] = "success" return Return
def AuditUser(TheManagerID, TheUserID, TheActivityID, WhetherPass): ''' 描述:审核用户 参数:管理员openid,用户openid,活动id,是否通过(0或1) 返回:成功{result:success} 失败:{result:fail,reason:xxx,code:xxx} ''' Return = {} Reason = "" Code = 0 Success = True ThePass = -1 ResultList = [] if Success: try: if JudgeValid.JudgeWhetherManager(TheManagerID, TheActivityID) != True: Success = False Reason = "权限不足,需要是管理员或创建者!" Code = Constants.ERROR_CODE_LACK_ACCESS TheActivity = Activity.objects.get(ID = TheActivityID) TheUser = User.objects.get(OpenID = TheUserID) except: Success = False Reason = "未找到用户或活动!" Code = Constants.ERROR_CODE_NOT_FOUND if Success: if JudgeValid.JudgeActivityNormal(TheActivityID) != True: Success = False Reason = "活动状态为异常或结束,不能操作!" Code = Constants.ERROR_CODE_INVALID_CHANGE if Success: try: TheJoinActivity = JoinInformation.objects.get(ActivityId = TheActivity, UserId = TheUser) TheStatus = TheJoinActivity.Status if TheStatus != Constants.USER_STATUS_WAITVALIDATE: Success = False Reason = "该用户不是待审核状态" Code = Constants.ERROR_CODE_INVALID_CHANGE except: Success = False Reason = "用户未参加该活动!" Code = Constants.ERROR_CODE_NOT_FOUND if Success: try: ThePass = int(WhetherPass) if ThePass != 0 and ThePass != 1: Success = False Reason = "参数不合法!" Code = Constants.ERROR_CODE_INVALID_PARAMETER except: Success = False Reason = "参数不合法!" Code = Constants.ERROR_CODE_INVALID_PARAMETER if Success: try: if ThePass == 0: TheJoinActivity.Status = Constants.USER_STATUS_REFUSED TheJoinActivity.save() else: if TheActivity.MaxUser != Constants.UNDEFINED_NUMBER and TheActivity.CurrentUser >= TheActivity.MaxUser: Success = False Reason = "当前人数已满,不能审核通过!" Code = Constants.ERROR_CODE_INVALID_CHANGE else: CurrentTime = GlobalFunctions.GetCurrentTime() TheJoinActivity.Status = Constants.USER_STATUS_JOINED TheJoinActivity.JoinTime = CurrentTime TheJoinActivity.JoinReason = "无" TheActivity.CurrentUser = TheActivity.CurrentUser + 1 TheActivity.save() TheJoinActivity.save() except: Success = False Reason = "审核失败!" Code = Constants.ERROR_CODE_UNKNOWN if Success: Return["result"] = "success" else: Return["result"] = "fail" Return["reason"] = Reason Return["code"] = Code return Return
def SendTimedMessage(TheActivityItem, TheUserItem, TheMessageType): ''' 描述:推送活动消息函数 参数: 活动的对象,用户对象,消息类型(作为数字定义在constants.py里) 返回:无 ''' Success = True obj = {} data = {} pagePrefix = "/pages/ActivityList/ActivityDetail/ActivityDetail?activityId=" if Success: try: if (TheMessageType == Constants.MESSAGE_TYPE_ACTIVITY_CHANGE or TheMessageType == Constants.MESSAGE_TYPE_KICK or TheMessageType == Constants.MESSAGE_TYPE_ACTIVITY_CANCEL or TheMessageType == Constants.MESSAGE_TYPE_ACTIVITY_FORBIDDEN): obj["template_id"] = "LEoLo9UsF2by_4UGypKf2v7YLXeYRRGGjskOa0iJzZY" data["thing2"] = {"value": TheActivityItem.Name} data["date4"] = { "value": time.strftime("%Y{y}%m{m}%d{d} %H:%M", time.localtime( TheActivityItem.StartTime)).format(y='年', m='月', d='日') } data["thing5"] = {"value": TheActivityItem.Place} detail = None if (TheMessageType == Constants.MESSAGE_TYPE_KICK): detail = "您被活动主办方踢出了该活动。" elif (TheMessageType == Constants.MESSAGE_TYPE_ACTIVITY_CANCEL ): detail = "活动主办方取消了该活动。" elif (TheMessageType == Constants.MESSAGE_TYPE_ACTIVITY_FORBIDDEN): detail = "由于违规行为,该活动已被封禁。" elif (TheMessageType == Constants.MESSAGE_TYPE_ACTIVITY_CHANGE ): detail = "活动安排发生了变更。点击可查看详情。" data["thing6"] = {"value": detail} elif (TheMessageType == Constants.MESSAGE_TYPE_AUDIT_PASS or TheMessageType == Constants.MESSAGE_TYPE_AUDIT_FAIL): obj["template_id"] = "j9EPrZx9MAQ5SjbN1aCYHImxymn6ZEziJLgQEcbuXSk" data["thing2"] = {"value": TheActivityItem.Name} data["date3"] = { "value": time.strftime("%Y{y}%m{m}%d{d} %H:%M", time.localtime( TheActivityItem.StartTime)).format(y='年', m='月', d='日') } if (TheMessageType == Constants.MESSAGE_TYPE_AUDIT_PASS): data["thing7"] = {"value": "您的加入申请已被通过"} data["phrase1"] = {"value": "通过"} elif (TheMessageType == Constants.MESSAGE_TYPE_AUDIT_FAIL): data["thing7"] = {"value": "如有疑问请联系活动主办方。"} data["phrase1"] = {"value": "不通过"} elif (TheMessageType == Constants.MESSAGE_TYPE_NEW_ACTIVITY_PASS or TheMessageType == Constants.MESSAGE_TYPE_NEW_ACTIVITY_FAIL): obj["template_id"] = "j9EPrZx9MAQ5SjbN1aCYHImxymn6ZEziJLgQEcbuXSk" data["thing2"] = {"value": TheActivityItem.Name} data["date3"] = { "value": time.strftime("%Y{y}%m{m}%d{d} %H:%M", time.localtime( TheActivityItem.StartTime)).format(y='年', m='月', d='日') } if (TheMessageType == Constants.MESSAGE_TYPE_NEW_ACTIVITY_PASS ): data["thing7"] = {"value": "校友总会已审核通过您发起的活动。"} data["phrase1"] = {"value": "通过"} elif (TheMessageType == Constants.MESSAGE_TYPE_NEW_ACTIVITY_FAIL): data["thing7"] = {"value": "校友总会拒绝了您发起的活动。"} data["phrase1"] = {"value": "不通过"} elif (TheMessageType == Constants.MESSAGE_TYPE_ACTIVITY_WILL_START_HOUR): obj["template_id"] = "u-UA76noUE9_9g2ZVX53W9DQKz3x-Tn1914KHphfRXM" data["thing7"] = {"value": "您报名的活动将在明天举行,请合理安排行程"} data["thing4"] = {"value": TheActivityItem.Name} data["date3"] = { "value": time.strftime("%Y{y}%m{m}%d{d} %H:%M", time.localtime( TheActivityItem.StartTime)).format(y='年', m='月', d='日') } data["thing6"] = {"value": TheActivityItem.Place} elif (TheMessageType == Constants.MESSAGE_TYPE_ACTIVITY_WILL_START_MINUTE): obj["template_id"] = "u-UA76noUE9_9g2ZVX53Wz3QZ-IgE4ECwLVxWLIJlZ8" data["thing7"] = {"value": "您报名的活动即将举行,请按时到场并签到"} data["thing4"] = {"value": TheActivityItem.Name} data["date5"] = { "value": time.strftime("%Y{y}%m{m}%d{d} %H:%M", time.localtime( TheActivityItem.StartTime)).format(y='年', m='月', d='日') } data["thing6"] = {"value": TheActivityItem.Place} else: Success = False Reason = "没有对应的消息类型" except: Success = False Reason = "产生消息阶段异常" if Success: try: obj["touser"] = TheUserItem.OpenID obj["page"] = pagePrefix + str(TheActivityItem.ID) obj["data"] = data except: Success = False Reason = "产生消息阶段2异常" if Success: try: url = "https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=" + GlobalFunctions.GetAccessToken( ) TheRequest = requests.post(url, data=json.dumps(obj), timeout=(5, 10), allow_redirects=True) except: Success = False ErrorId = Constants.ERROR_CODE_NETWORK_ERROR Reason = "网络繁忙,访问超时!" if Success: try: if TheRequest.status_code < 200 or TheRequest.status_code >= 400: Success = False ErrorId = Constants.ERROR_CODE_NETWORK_ERROR Reason = "网络繁忙,访问微信失败!!" TheJson = TheRequest.json() #print(TheJson) if "errcode" in TheJson: if TheJson["errcode"] == -1: Success = False ErrorId = Constants.ERROR_CODE_NETWORK_ERROR Reason = "网络繁忙,访问微信失败!" elif TheJson["errcode"] != 0: Success = False ErrorId = Constants.ERROR_CODE_NETWORK_ERROR Reason = TheJson["errmsg"] except: Success = False ErrorId = Constants.ERROR_CODE_NETWORK_ERROR Reason = "网络繁忙,访问微信失败!" return Success
def CheckInActivity(TheUserID, TheActivityID, TheCode, TheDistance): ''' 描述:用户签到 参数:用户openid,活动id,二维码code, 距离 返回:成功{result:success} 失败:{result:fail,reason:xxx,code:xxx} ''' Return = {} Reason = "" Code = 0 Success = True ThePass = -1 ResultList = [] if Success: try: TheActivity = Activity.objects.get(ID = TheActivityID) TheUser = User.objects.get(OpenID = TheUserID) if TheCode != None: if TheCode != TheActivity.Code: Success = False Reason = "二维码和活动不匹配!" Code = Constants.ERROR_CODE_INVALID_CHANGE elif TheDistance != None: if TheDistance > Constants.SUCCESS_THRESHOLD: Success = False Reason = "距离太远,签到失败!" Code = Constants.ERROR_CODE_INVALID_CHANGE else: Success = False Reason = "请求参数不合法!" Code = Constants.ERROR_CODE_INVALID_PARAMETER except: Success = False Reason = "未找到用户或活动!" Code = Constants.ERROR_CODE_NOT_FOUND if Success: if JudgeValid.JudgeActivityNormal(TheActivityID) != True: Success = False Reason = "活动状态为异常或结束,不能操作!" Code = Constants.ERROR_CODE_INVALID_CHANGE if Success: try: TheJoinActivity = JoinInformation.objects.get(ActivityId = TheActivity, UserId = TheUser) TheStatus = TheJoinActivity.Status TheRole = TheJoinActivity.Role if JudgeValid.JudgeUserStatusDoingActivity(TheStatus) != True: Success = False Reason = "该用户不是活动正式成员" Code = Constants.ERROR_CODE_INVALID_CHANGE elif TheStatus == Constants.USER_STATUS_CHECKED: Success = False Reason = "该用户已经签到!" Code = Constants.ERROR_CODE_INVALID_CHANGE except: Success = False Reason = "用户未参加该活动!" Code = Constants.ERROR_CODE_NOT_FOUND #判断状态是否可行 if Success: if JudgeValid.JudgeActivityCanCheck(TheActivityID)!= True: Success = False Reason = "当前活动不在可以签到状态,可能签到未开始,已暂停或已经截止" Code = Constants.ERROR_CODE_INVALID_CHANGE if Success: try: TheCheckTime = GlobalFunctions.GetCurrentTime() TheJoinActivity.CheckTime = TheCheckTime TheJoinActivity.Status = Constants.USER_STATUS_CHECKED TheJoinActivity.save() except: Success = False Reason = "签到失败!" Code = Constants.ERROR_CODE_UNKNOWN if Success: Return["result"] = "success" else: Return["result"] = "fail" Return["reason"] = Reason Return["code"] = Code return Return
def ShowAllUsers(TheLastSeenID, TheMostNumber): ''' 描述:查询所有用户 参数: 最后一个id,最多显示的数目 返回:第一个是一个字典,里面就一个字典数组userList,字典每个字典有用户具体信息,失败为空 第二个是失败状态信息,成功是空,失败有reason和code ''' #查询 Success = True if Success: try: Info = User.objects.all() except: Success = False #处理数据并且返回 Return = {} ErrorInfo = {} Result = [] #print(TheLastID, TheMostNumber) if Success: try: CurrentNumber = 0 i = len(Info) - 1 while i >= 0: item = Info[i] if TheLastSeenID != Constants.UNDEFINED_NUMBER: if item.ID >= TheLastSeenID: i -= 1 continue TheResult = {} TheResult["id"] = item.ID TheResult["name"] = item.Name TheResult["openId"] = item.OpenID TheResult["avatarUrl"] = GlobalFunctions.GetTrueAvatarUrlUser(item.AvatarURL) TheResult["status"] = item.Status TheResult["extraData"] = item.ExtraData TheResult["point"] = item.Point TheEducation = [] TheEducationInfo = item.Education.all() for oneEducation in TheEducationInfo: OneResult = {} OneResult["enrollmentYear"] = oneEducation.StartYear OneResult["department"] = oneEducation.Department OneResult["enrollmentType"] = oneEducation.Type TheEducation.append(OneResult) TheResult["campusIdentity"] = TheEducation Result.append(TheResult) CurrentNumber = CurrentNumber + 1 if TheMostNumber != Constants.UNDEFINED_NUMBER and CurrentNumber >= TheMostNumber: break i -= 1 except: Success = False if Success == True: Return["userList"] = Result ErrorInfo = {} else: Return = {} ErrorInfo["reason"] = "查询用户失败!" ErrorInfo["code"] = Constants.ERROR_CODE_UNKNOWN return Return, ErrorInfo
def ShowOneActivity(TheActivityID): ''' 描述:给定活动id,查询活动具体信息 参数:用户id和活动id 返回:一个字典,里面有活动各种信息,错误信息 成功:错误信息空 失败:返回字典空,错误信息存在 ''' Success = True Result = {} ErrorInfo = {} Reason = "" Code = 0 if Success: try: TheActivity = Activity.objects.get(ID = TheActivityID) except: Success = False Reason = "未找到该活动!" Code = Constants.ERROR_CODE_NOT_FOUND if Success: Result = ActivityManager.QueryActivity(TheActivityID) if Result == {}: Success = False Reason = "查询活动失败!" Code = Constants.ERROR_CODE_UNKNOWN if Success: if 1: Result["position"] = TheActivity.GPSPlace TheJoinActivityList = JoinInformation.objects.filter(ActivityId = TheActivity) Result["participants"] = [] NumberNeedAudit = 0 for item in TheJoinActivityList: TheUserInfo = {} TheId = item.UserId.OpenID TheStatus = item.Status TheUserInfo["openId"] = TheId TheUserInfo["name"] = item.UserId.Name TheUserInfo["avatarUrl"] = GlobalFunctions.GetTrueAvatarUrlUser(item.UserId.AvatarURL) TheUserInfo["userStatus"] = TheStatus TheUserInfo["userRole"] = item.Role TheUserInfo["point"] = item.UserId.Point if JudgeValid.JudgeUserStatusJoined(TheStatus): Result["participants"].append(TheUserInfo) if item.Role == Constants.USER_ROLE_CREATOR: Result["creator"] = TheId if item.Status == Constants.USER_STATUS_WAITVALIDATE: NumberNeedAudit += 1 Result["needAuditCount"] = NumberNeedAudit else: Success = False Reason = "查询活动失败!" Code = Constants.ERROR_CODE_UNKNOWN if Success: try: TheReportActivityList = ReportInformation.objects.filter(ActivityId = TheActivity) Result["reporters"] = [] for item in TheReportActivityList: TheUserInfo = {} TheUserInfo["openId"] = item.UserId.OpenID TheUserInfo["name"] = item.UserId.Name TheUserInfo["avatarUrl"] = GlobalFunctions.GetTrueAvatarUrlUser(item.UserId.AvatarURL) TheUserInfo["submitMsg"] = item.Reason TheUserInfo["submitTime"] = GlobalFunctions.TimeStampToTimeString(item.SubmitTime) Result["reporters"].append(TheUserInfo) Result["reportCount"] = len(Result["reporters"]) except: Success = False Reason = "查询活动失败!" Code = Constants.ERROR_CODE_UNKNOWN if Success: try: Result["rules"] = {} Result["rules"] = ActivityManager.ShowAllAdvancedRules(TheActivityID) Result["rules"]["ruleType"] = TheActivity.GlobalRule except: Success = False Reason = "查询活动失败!" Code = Constants.ERROR_CODE_UNKNOWN if Success: return Result, {} else: ErrorInfo["reason"] = Reason ErrorInfo["code"] = Code return {}, ErrorInfo
def ShowAllActivity(TheLastID, TheMostNumber): ''' 描述:查询所有活动 参数: 最后一个id,最多显示的数目 返回:第一个是一个字典,里面就一个字典数组activityList,字典每个字典有活动具体信息,失败为空 第二个是失败状态信息,成功是空,失败有reason和code ''' #查询 Success = True if Success: try: Info = Activity.objects.all() except: Success = False #处理数据并且返回 Return = {} ErrorInfo = {} Result = [] #print(TheLastID, TheMostNumber) if Success: try: CurrentNumber = 0 i = len(Info) - 1 while i >= 0: item = Info[i] if TheLastID != Constants.UNDEFINED_NUMBER: if item.ID >= TheLastID: i -= 1 continue TheResult = {} TheResult["id"] = item.ID TheResult["name"] = item.Name TheResult["place"] = item.Place TheResult["createTime"] = GlobalFunctions.TimeStampToTimeString(int(item.CreateTime)) TheResult["start"] = GlobalFunctions.TimeStampToTimeString(int(item.StartTime)) TheResult["end"] = GlobalFunctions.TimeStampToTimeString(int(item.EndTime)) TheResult["signupBeginAt"] = GlobalFunctions.TimeStampToTimeString(int(item.SignUpStartTime)) TheResult["signupStopAt"] = GlobalFunctions.TimeStampToTimeString(int(item.SignUpEndTime)) TheResult["minUser"] = int(item.MinUser) TheResult["maxUser"] = int(item.MaxUser) TheResult["curUser"] = int(item.CurrentUser) TheResult["type"] = item.Type TheResult["statusGlobal"] = int(item.StatusGlobal) TheResult["statusJoin"] = int(item.StatusJoin) TheResult["statusCheck"] = int(item.StatusCheck) TheResult["tags"] = GlobalFunctions.SplitTags(item.Tags) TheResult["imageUrl"] = GlobalFunctions.GetTrueAvatarUrlActivity(item.ImageURL) TheReportActivityList = ReportInformation.objects.filter(ActivityId = item) TheResult["reportCount"] = len(TheReportActivityList) Result.append(TheResult) CurrentNumber = CurrentNumber + 1 if TheMostNumber != Constants.UNDEFINED_NUMBER and CurrentNumber >= TheMostNumber: break i -= 1 except: Success = False if Success == True: Return["activityList"] = Result ErrorInfo = {} else: Return = {} ErrorInfo["reason"] = "查询活动失败!" ErrorInfo["code"] = Constants.ERROR_CODE_UNKNOWN return Return, ErrorInfo
def QueryEducationTypes(request): ''' 描述:处理查询所有教育类型 参数:request 成功返回全部教育类型 失败则是 { "errid":xxx, "errmsg":"xxxx" } ''' Success = True Return = {} Info = {} Reason = "" ErrorID = Constants.UNDEFINED_NUMBER TheSession = "" TheUserID = "" #获取请求数据 if Success: try: TheSession = request.GET.get("session") except: Success = False Reason = "请求参数不合法!" ErrorID = Constants.ERROR_CODE_INVALID_PARAMETER #判断是否登录,获取待查询的openid if Success: try: TheUserID = UserManager.GetCurrentUser(TheSession) if TheUserID == None: Success = False Reason = "用户未登录!" ErrorID = Constants.ERROR_CODE_LOGIN_ERROR except: Success = False Reason = "用户未登录!" ErrorID = Constants.ERROR_CODE_LOGIN_ERROR #调用数据库函数 if Success: try: Info = GlobalFunctions.ShowAllEducationType() #print(Info) if Info == {}: Success = False Reason = "查询教育类型列表失败!" ErrorID = Constants.ERROR_CODE_NOT_FOUND except: Success = False Reason = "查询教育类型列表失败!" ErrorID = Constants.ERROR_CODE_NOT_FOUND if Success: Return = Info else: Return["errid"] = ErrorID Return["errmsg"] = Reason Response = JsonResponse(Return) if Success == True: Response.status_code = 200 else: Response.status_code = 400 return Response