Exemple #1
0
def SearchActivity(request):
    '''
	描述:处理输入关键词搜索活动请求
	参数:request
	成功返回活动列表
	失败则是
	{
	"errid":xxx,
	"errmsg":"xxxx"
	}
	'''
    Success = True
    Return = {}
    Info = {}
    ErrorInfo = {}
    Reason = ""
    ErrorID = Constants.UNDEFINED_NUMBER
    TheSession = ""
    TheUserID = ""
    SearchWord = ""
    TheLastSeenID = Constants.UNDEFINED_NUMBER
    TheMostNumber = Constants.UNDEFINED_NUMBER
    #获取请求数据
    if Success:
        try:
            TheSession = request.GET.get("session")
            SearchWord = request.GET.get("searchWord")
            try:
                TheLastSeenID = int(request.GET.get("lastSeenId"))
            except:
                TheLastSeenID = Constants.UNDEFINED_NUMBER
            try:
                TheMostNumber = int(request.GET.get("most"))
                if TheMostNumber <= 0:
                    Success = False
                    Reason = "请求参数不合法!"
                    ErrorID = Constants.ERROR_CODE_INVALID_PARAMETER
            except:
                TheMostNumber = Constants.UNDEFINED_NUMBER
        except:
            Success = False
            Reason = "请求参数不合法!"
            Code = 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:
            TheSearcher = SearchAndRecommend.WhooshSearcher.Create()
            Info = TheSearcher.SearchInfo(SearchWord, TheLastSeenID,
                                          TheMostNumber)
            #print(Info)
            if "activityList" not in Info:
                Success = False
                Reason = "搜索活动失败!"
                ErrorID = Constants.ERROR_CODE_NOT_FOUND
            elif Info["activityList"] == []:
                Success = False
                Reason = "未找到任何符合条件的活动!"
                ErrorID = Constants.ERROR_CODE_RECOMMEND
        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
Exemple #2
0
def SearchActivityAdvanced(request):
    '''
	描述:处理高级搜索活动请求
	参数:request
	成功返回活动列表
	失败则是
	{
	"errid":xxx,
	"errmsg":"xxxx"
	}
	'''
    Success = True
    Return = {}
    Info = {}
    ErrorInfo = {}
    Reason = ""
    ErrorID = Constants.UNDEFINED_NUMBER
    TheSession = ""
    TheUserID = ""
    SearchWord = ""
    Data = {}
    TheLastSeenID = Constants.UNDEFINED_NUMBER
    TheMostNumber = Constants.UNDEFINED_NUMBER
    #获取请求数据
    if Success:
        try:
            TheSession = request.GET.get("session")
            Data = json.loads(request.body)
            try:
                TheLastSeenID = int(request.GET.get("lastSeenId"))
            except:
                TheLastSeenID = Constants.UNDEFINED_NUMBER
            try:
                TheMostNumber = int(request.GET.get("most"))
                if TheMostNumber <= 0:
                    Success = False
                    Reason = "请求参数不合法!"
                    ErrorID = Constants.ERROR_CODE_INVALID_PARAMETER
            except:
                TheMostNumber = Constants.UNDEFINED_NUMBER
        except:
            Success = False
            Reason = "请求参数不合法!"
            Code = 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:
            Result, ErrorInfo = ActivityManager.AdvancedSearch(
                TheUserID, Data, TheLastSeenID, TheMostNumber)
            #print(Info)
            if Result == {}:
                Success = False
                Reason = ErrorInfo["reason"]
                ErrorID = ErrorInfo["code"]
            elif Result["activityList"] == []:
                Success = False
                Reason = "未找到任何符合条件的活动!"
                ErrorID = Constants.ERROR_CODE_RECOMMEND
        except:
            Success = False
            Reason = "搜索活动失败!"
            ErrorID = Constants.ERROR_CODE_UNKNOWN

    if Success:
        Return = Result
    else:
        Return["errid"] = ErrorID
        Return["errmsg"] = Reason
    Response = JsonResponse(Return)
    if Success == True:
        Response.status_code = 200
    else:
        Response.status_code = 400
    return Response
Exemple #3
0
def RecommendActivityByUser(request):
    '''
	描述:处理按照用户推荐请求
	参数:request
	成功返回活动列表
	失败则是
	{
	"errid":xxx,
	"errmsg":"xxxx"
	}
	'''
    Success = True
    Return = {}
    Info = {}
    ErrorInfo = {}
    Reason = ""
    ErrorID = Cons = ""
    TheUserID = ""
    SearchWord = ""
    Most = Constants.UNDEFINED_NUMBER

    #获取请求数据
    if Success:
        try:
            TheSession = request.GET.get("session")
            Most = int(request.GET.get("most"))
        except:
            Success = False
            Reason = "请求参数不合法!"
            Code = 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, ErrorInfo = SearchAndRecommend.RecommendActivityByUser(
                TheUserID)
            #print(Info)
            if Info == {}:
                Success = False
                Reason = ErrorInfo["reason"]
                ErrorID = ErrorInfo["code"]
            else:
                Info["activityList"] = SearchAndRecommend.ShowRandomInfo(
                    Info["activityList"], Most)
        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
def ChangeActivityDetail(request):
    '''
    描述:处理修改活动请求
    参数:request
    成功只返回
    {
    "result": "success"
    }   
    失败则是
    {
    "errid":xxx,
    "errmsg":"xxxx"
    }
    '''
    Success = True
    Return = {}
    Reason = ""
    ErrorID = Constants.UNDEFINED_NUMBER
    TheSession = ""
    TheActivity = 0
    TheUserID = ""
    Data = {}
    #获取请求数据
    if Success:
        try:
            TheSession = request.GET.get("session")
            TheActivity = int(request.GET.get("activityId"))
            Data = json.loads(request.body)
        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:
        JudgeResult = JudgeValid.JudgeUserValid(TheUserID)
        if JudgeResult != True:
            Success = False
            Reason = "用户已被封禁,不能操作!!"
            ErrorID = Constants.ERROR_CODE_INVALID_CHANGE

    #调用数据库函数
    if Success:
        try:
            Info = ActivityManager.ChangeActivityDetail(
                TheUserID, TheActivity, Data)
            if Info["result"] != "success":
                Success = False
                Reason = Info["reason"]
                ErrorID = Info["code"]
        except:
            Success = False
            Reason = "修改活动详情失败"
            ErrorID = Constants.ERROR_CODE_UNKNOWN

    if Success:
        Return["result"] = "success"
    else:
        Return["errmsg"] = Reason
        Return["errid"] = ErrorID
    Response = JsonResponse(Return)
    if Success == True:
        Response.status_code = 200
    else:
        Response.status_code = 400
    return Response
def UploadActivityQRCode(request):
    '''
    描述:处理更新活动二维码请求
    参数:request
    成功返回
    {
    图片
    }
    失败则是
    {
    "errid":xxx,
    "errmsg":"xxxx"
    }
    '''
    Success = True
    Return = {}
    Info = {}
    Reason = ""
    TheImageName = ""
    TheImage = None
    ErrorID = Constants.UNDEFINED_NUMBER
    TheSession = ""
    TheActivity = Constants.UNDEFINED_NUMBER
    TheUserID = ""
    #获取请求数据
    if Success:
        try:
            TheSession = request.GET.get("session")
            TheActivity = int(request.GET.get("activityId"))
        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:
        JudgeResult = JudgeValid.JudgeUserValid(TheUserID)
        if JudgeResult != True:
            Success = False
            Reason = "用户已被封禁,不能操作!!"
            ErrorID = Constants.ERROR_CODE_INVALID_CHANGE

    #调用数据库函数
    if Success:
        try:
            Info, TheImageName = ActivityManager.UploadActivityQRCode(
                TheUserID, TheActivity)
            #print(Info)
            if Info["result"] != "success":
                Success = False
                Reason = Info["reason"]
                ErrorID = Info["code"]
        except:
            Success = False
            Reason = "更新活动二维码失败!"
            ErrorID = Constants.ERROR_CODE_NOT_FOUND

    if Success:
        TheImage = open(TheImageName, "rb").read()
        Response = HttpResponse(TheImage, content_type="image/png")
    else:
        Return["errid"] = ErrorID
        Return["errmsg"] = Reason
        Response = JsonResponse(Return)
    if Success == True:
        Response.status_code = 200
    else:
        Response.status_code = 400
    return Response
def DeleteActivity(request):
    '''
    描述:处理删除单个活动信息请求
    参数:request
    成功返回
    {
    "result": "success"
    }
    失败则是
    {
    "errid":xxx,
    "errmsg":"xxxx"
    }
    '''
    Success = True
    Return = {}
    Info = {}
    Reason = ""
    ErrorID = Constants.UNDEFINED_NUMBER
    TheSession = ""
    TheActivity = Constants.UNDEFINED_NUMBER
    TheUserID = ""
    #获取请求数据
    if Success:
        try:
            TheSession = request.GET.get("session")
            TheActivity = int(request.GET.get("activityId"))
        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:
        JudgeResult = JudgeValid.JudgeUserValid(TheUserID)
        if JudgeResult != True:
            Success = False
            Reason = "用户已被封禁,不能操作!!"
            ErrorID = Constants.ERROR_CODE_INVALID_CHANGE

    #调用数据库函数
    if Success:
        try:
            Info = ActivityManager.DeleteActivity(TheUserID, TheActivity)
            #print(Info)
            if Info["result"] != "success":
                Success = False
                Reason = Info["reason"]
                ErrorID = Info["code"]
        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
    if Success:
        TimeManager.SendTimedMessageActivity(
            TheActivity, Constants.MESSAGE_TYPE_ACTIVITY_CANCEL)
        print("send cancel")

    return Response
def ChangeActivity(request):
    '''
    描述:处理修改活动请求
    参数:request
    成功只返回
    {
    "result": "success"
    }   
    失败则是
    {
    "errid":xxx,
    "errmsg":"xxxx"
    }
    '''
    Success = True
    Return = {}
    Reason = ""
    ErrorID = Constants.UNDEFINED_NUMBER
    TheSession = ""
    TheUserID = ""
    Data = {}
    NeedPush = False
    #获取请求数据
    if Success:
        try:
            TheSession = request.GET.get("session")
            Data = json.loads(request.body)
            try:
                TheNeedPush = request.GET.get("needPush")
                if int(TheNeedPush) > 0:
                    NeedPush = True
            except:
                NeedPush = False
        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:
        JudgeResult = JudgeValid.JudgeUserValid(TheUserID)
        if JudgeResult != True:
            Success = False
            Reason = "用户已被封禁,不能操作!!"
            ErrorID = Constants.ERROR_CODE_INVALID_CHANGE

    #调用数据库函数
    if Success:
        try:
            Info = ActivityManager.ChangeActivity(TheUserID, Data)
            if Info["result"] != "success":
                Success = False
                Reason = Info["reason"]
                ErrorID = Info["code"]
        except:
            Success = False
            Reason = "修改活动失败"
            ErrorID = Constants.ERROR_CODE_UNKNOWN

    if Success:
        Return["result"] = "success"
    else:
        Return["errmsg"] = Reason
        Return["errid"] = ErrorID
    Response = JsonResponse(Return)
    if Success == True:
        Response.status_code = 200
    else:
        Response.status_code = 400

    #发送消息
    if Success and NeedPush:
        TimeManager.SendTimedMessageActivity(
            Data["id"], Constants.MESSAGE_TYPE_ACTIVITY_CHANGE)
        print("send change")

    return Response
def QueryActivityDetail(request):
    '''
    描述:处理查询单个活动详情请求
    参数:request
    成功返回活动信息
    失败则是
    {
    "errid":xxx,
    "errmsg":"xxxx"
    }
    '''
    Success = True
    Return = {}
    Info = {}
    SelfInfo = {}
    Reason = ""
    ErrorID = Constants.UNDEFINED_NUMBER
    TheSession = ""
    TheActivity = Constants.UNDEFINED_NUMBER
    TheUserID = ""
    #获取请求数据
    if Success:
        try:
            TheSession = request.GET.get("session")
            TheActivity = int(request.GET.get("activityId"))
        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 = ActivityManager.ShowActivityDetail(TheActivity)
            if Info["result"] != "success":
                Success = False
                Reason = Info["reason"]
                ErrorID = Info["code"]
        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
def StartActivity(request):
    '''
    描述:处理添加活动请求
    参数:request

    成功返回:
    {
    “id”:”0000001”(活动id)
    }
    失败返回:
    {"errid": 101, "errmsg": "身份信息不存在"}
    '''
    Success = True
    Return = {}
    Info = {}
    RequestBody = {}
    ErrorId = Constants.UNDEFINED_NUMBER
    Reason = ""
    TheSession = ""
    SelfOpenID = ""
    #print(request.POST)

    #获取请求数据
    if Success:
        try:
            TheSession = request.GET.get("session")
        except:
            Success = False
            Reason = "请求参数不合法!"
            ErrorId = Constants.ERROR_CODE_INVALID_PARAMETER

    #判断是否登录, 获取待查询的openid
    if Success:
        try:
            SelfOpenID = UserManager.GetCurrentUser(TheSession)
            if SelfOpenID == None:
                Success = False
                Reason = "用户未登录!"
                ErrorId = Constants.ERROR_CODE_LOGIN_ERROR

        except:
            Success = False
            Reason = "用户未登录!"
            ErrorId = Constants.ERROR_CODE_LOGIN_ERROR

    #判断是否被封禁
    if Success:
        JudgeResult = JudgeValid.JudgeUserValid(SelfOpenID)
        if JudgeResult != True:
            Success = False
            Reason = "用户已被封禁,不能操作!!"
            ErrorId = Constants.ERROR_CODE_INVALID_CHANGE

    #调用数据库函数进行操作
    if Success:
        try:
            RequestBody = json.loads(request.body)
            Info = ActivityManager.AddActivity(SelfOpenID, RequestBody)
        except:
            Success = False
            Reason = "请求参数不合法!"
            ErrorId = Constants.ERROR_CODE_INVALID_PARAMETER

    if Success:
        if Info["result"] == "success" or Info["result"] == "needAudit":
            Return["activityId"] = str(Info["activityId"])
            Return["result"] = Info["result"]
        else:
            if ErrorId == Constants.UNDEFINED_NUMBER:
                Success = False
                Return["errmsg"] = Info["reason"]
                Return["errid"] = Info["code"]
    else:
        Return["errid"] = ErrorId
        Return["errmsg"] = Reason
    Response = JsonResponse(Return)

    if Success:
        Response.status_code = 200
    else:
        Response.status_code = 400
    return Response
Exemple #10
0
def SetExtraData(request):
    '''
    描述:处理设置用户补充信息请求
    参数:request
    成功返回:
    {
    “result”:“success”
    }
    失败返回:
    {"errid": 101, "errmsg": "身份信息不存在"}
    '''
    Success = True
    Return = {}
    Info = {}
    RequestBody = {}
    ErrorId = Constants.UNDEFINED_NUMBER
    Reason = ""
    TheSession = ""
    SelfOpenID = ""
    TheURL = ""
    #获取请求数据
    if Success:
        try:
            TheSession = request.GET.get("session")
        except:
            Success = False
            Reason = "请求参数不合法!"
            ErrorId = Constants.ERROR_CODE_INVALID_PARAMETER
    #判断是否登录,获取待查询的openid
    if Success:
        try:
            SelfOpenID = UserManager.GetCurrentUser(TheSession)
            if SelfOpenID == None:
                Success = False
                Reason = "用户未登录!"
                ErrorId = Constants.ERROR_CODE_LOGIN_ERROR
        except:
            Success = False
            Reason = "用户未登录!"
            ErrorId = Constants.ERROR_CODE_LOGIN_ERROR

    #判断是否被封禁
    if Success:
        JudgeResult = JudgeValid.JudgeUserValid(SelfOpenID)
        if JudgeResult != True:
            Success = False
            Reason = "用户已被封禁,不能操作!!"
            ErrorId = Constants.ERROR_CODE_INVALID_CHANGE

    #调用数据库函数进行操作
    if Success:
        try:
            RequestBody = json.loads(request.body)
        except:
            Success = False
            Reason = "请求参数不合法!"
            ErrorId = Constants.ERROR_CODE_INVALID_PARAMETER
    if Success:
        try:
            QueryResult = UserManager.SetUserExtraData(SelfOpenID, RequestBody)
            if QueryResult["result"] != "success":
                Success = False
                Reason = QueryResult["reason"]
                ErrorId = QueryResult["code"]
        except:
            Success = False
            Reason = "设置头像url失败!"
            ErrorId = Constants.ERROR_CODE_UNKNOWN
    if Success:
        Return["result"] = "success"
    else:
        Return["errid"] = ErrorId
        Return["errmsg"] = Reason
    Response = JsonResponse(Return)
    if Success == True:
        Response.status_code = 200
    else:
        Response.status_code = 400
    return Response
def GetActivityList(request):
    '''
    描述:处理查询全部活动请求
    参数:request
    成功返回活动列表
    失败则是
    {
    "errid":xxx,
    "errmsg":"xxxx"
    }
    '''
    Success = True
    Return = {}
    Info = {}
    ErrorInfo = {}
    Reason = ""
    ErrorID = Constants.UNDEFINED_NUMBER
    TheSession = ""
    TheUserID = ""
    TheLastID = Constants.UNDEFINED_NUMBER
    TheMostNumber = Constants.UNDEFINED_NUMBER
    #获取请求数据
    if Success:
        try:
            TheSession = request.GET.get("session")
            try:
                TheLastID = int(request.GET.get("lastSeenId"))
            except:
                TheLastID = Constants.UNDEFINED_NUMBER
            try:
                TheMostNumber = int(request.GET.get("most"))
                if TheMostNumber <= 0:
                    Success = False
                    Reason = "请求参数不合法!"
                    ErrorID = Constants.ERROR_CODE_INVALID_PARAMETER
            except:
                TheMostNumber = Constants.UNDEFINED_NUMBER
        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, ErrorInfo = ActivityManager.ShowAllActivity(
                TheLastID, TheMostNumber)
            #print(Info)
            if Info == {}:
                Success = False
                Reason = ErrorInfo["reason"]
                ErrorID = ErrorInfo["code"]
        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
Exemple #12
0
def CheckInActivity(request):
    '''
    描述:处理签到活动请求
    参数:request
    成功只返回
    {
    "result": "success"
    }   
    失败则是
    {
    "errid":xxx,
    "errmsg":"xxxx"
    }
    '''
    Success = True
    Return = {}
    Reason = ""
    ErrorID = Constants.UNDEFINED_NUMBER
    TheSession = ""
    TheActivity = Constants.UNDEFINED_NUMBER
    TheUserID = ""
    TheJoinReason = None
    #获取请求数据
    if Success:
        try:
            TheSession = request.GET.get("session")
            TheActivity = int(request.GET.get("activityId"))
            try:
                TheCode = request.GET.get("code")
            except:
                TheCode = None
            try:
                TheDistance = int(request.GET.get("distance"))
            except:
                TheDistance = None
        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:
        JudgeResult = JudgeValid.JudgeUserValid(TheUserID)
        if JudgeResult != True:
            Success = False
            Reason = "用户已被封禁,不能操作!!"
            ErrorID = Constants.ERROR_CODE_INVALID_CHANGE

    #调用数据库函数添加活动
    if Success:
        try:
            Info = UserActivityManager.CheckInActivity(TheUserID, TheActivity,
                                                       TheCode, TheDistance)
            #print(Info)
            if Info["result"] != "success":
                Success = False
                Reason = Info["reason"]
                ErrorID = Info["code"]
        except:
            Success = False
            Reason = "签到失败"
            ErrorID = Constants.ERROR_CODE_UNKNOWN

    if Success:
        Return["result"] = "success"
    else:
        Return["errid"] = ErrorID
        Return["errmsg"] = Reason
    Response = JsonResponse(Return)
    if Success == True:
        Response.status_code = 200
    else:
        Response.status_code = 400
    return Response
Exemple #13
0
def RemoveFromActivity(request):
    '''
    描述:将用户踢出活动
    参数:request
    返回:成功{result:success}
        失败:{result:fail,errmsg:xxx,errid:xxx}
    '''
    Success = True
    Return = {}
    Reason = ""
    ErrorID = Constants.UNDEFINED_NUMBER
    TheSession = ""
    TheManagerID = ""
    TheUserID = ""
    TheActivityID = -1
    WhetherPass = ""
    #获取请求数据
    if Success:
        try:
            TheSession = request.GET.get("session")
            TheUserID = request.GET.get("userId")
            TheActivityID = int(request.GET.get("activityId"))
        except:
            Success = False
            Reason = "请求参数不合法!"
            ErrorID = Constants.ERROR_CODE_INVALID_PARAMETER

    #判断是否登录, 获取待查询的openid
    if Success:
        try:
            TheManagerID = UserManager.GetCurrentUser(TheSession)
            if TheManagerID == None:
                Success = False
                Reason = "用户未登录!"
                ErrorID = Constants.ERROR_CODE_LOGIN_ERROR
        except:
            Success = False
            Reason = "用户未登录!"
            ErrorID = Constants.ERROR_CODE_LOGIN_ERROR

    #判断是否被封禁
    if Success:
        JudgeResult = JudgeValid.JudgeUserValid(TheManagerID)
        if JudgeResult != True:
            Success = False
            Reason = "用户已被封禁,不能操作!!"
            ErrorID = Constants.ERROR_CODE_INVALID_CHANGE

    #调用数据库函数
    if Success:
        try:
            Info = UserActivityManager.RemoveUser(TheManagerID, TheUserID,
                                                  TheActivityID)
            if Info["result"] != "success":
                Success = False
                Reason = Info["reason"]
                ErrorID = Info["code"]
        except:
            Success = False
            Reason = "将用户移出活动失败"
            ErrorID = Constants.ERROR_CODE_UNKNOWN

    if Success:
        Return["result"] = "success"
    else:
        Return["errmsg"] = Reason
        Return["errid"] = ErrorID
    Response = JsonResponse(Return)
    if Success == True:
        Response.status_code = 200
    else:
        Response.status_code = 400
    if Success:
        TimeManager.SendTimedMessageUser(TheActivityID, TheUserID,
                                         Constants.MESSAGE_TYPE_KICK)
        print("send kick")
    return Response
Exemple #14
0
def QueryAllAuditParticipants(request):
    '''
    描述:处理查询单个活动全部待审核成员信息请求--管理员
    参数:request
    成功返回待审核成员信息
    失败则是
    {
    "errid":xxx,
    "errmsg":"xxxx"
    }
    '''
    Success = True
    Return = {}
    Info = {}
    ErrorInfo = {}
    Reason = ""
    ErrorID = Constants.UNDEFINED_NUMBER
    TheSession = ""
    TheActivity = Constants.UNDEFINED_NUMBER
    TheUserID = ""
    #获取请求数据
    if Success:
        try:
            TheSession = request.GET.get("session")
            TheActivity = int(request.GET.get("activityId"))
        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, ErrorInfo = UserActivityManager.ShowAllAuditMembers(
                TheUserID, TheActivity)
            if Info == {}:
                Success = False
                Reason = ErrorInfo["reason"]
                ErrorID = ErrorInfo["code"]
        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
Exemple #15
0
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
Exemple #16
0
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