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 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 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
Esempio n. 4
0
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
Esempio n. 5
0
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 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