def signInByAjaxAction(request): logging.info("requestWith:"+str(RequestUtil.getAllParams(request))) retCode = HTTPRSPCode.OK msg = "ok" data = {} userName = RequestUtil.getParamFromRequest(request,'username') password = RequestUtil.getParamFromRequest(request,'password') if userName == None: msg = "username must not be nil" retCode = HTTPRSPCode.INVALID_USERNAME else : users = CTRUser.objects.filter(userName = userName) if len(users) == 0: msg = "there is no data for user:"******"request.META['HTTP_ORIGIN']:" + str(request.META['HTTP_ORIGIN']) homeUrl = str(request.META['HTTP_HOST']) if not ("http" in homeUrl or "https" in homeUrl): homeUrl = "http://"+homeUrl data = {'userName':users[0].userName,'userId':str(users[0].userId),'url':homeUrl} SessionUtil.setUserNameToSession(request.session,userName) SessionUtil.setUserIdToSession(request.session,users[0].userId) logging.info("set name:" + userName + "to session success") logging.info("return:"+str(data)) return ResponseUtil.onJsonResponse(retCode,data,msg)
def signInByAction(request): logging.info("requestWith:"+str(RequestUtil.getAllParams(request))) name = RequestUtil.getParamFromRequest(request,'username') # users = CTRUser.objects.filter(userName = name) # if len(users) == 0: # print "db without userName:"******"there is no data for user:"******"set name:" + name + "to session success") return home(request)
def queryRequestForUserRecords(request): logging.info("requestWith:"+str(RequestUtil.getAllParams(request))) # time.sleep(2) retCode = HTTPRSPCode.OK msg = "ok" data = {} userId = RequestUtil.getParamFromRequest(request,"userId") tag = RequestUtil.getParamFromRequest(request,"tag") recordDate = RequestUtil.getParamFromRequest(request,"recordDate") start = RequestUtil.getParamFromRequest(request,"start") end = RequestUtil.getParamFromRequest(request,"end") if not userId: userId = SessionUtil.getUserIdFromSession(request.session) if not userId: retCode = HTTPRSPCode.NOT_LOGIN msg = "please log in first" return ResponseUtil.onJsonResponse(retCode,data,msg) if start>end or start<0: retCode = HTTPRSPCode.INVALID_PARAMS msg = "userId or start&end is valid" return ResponseUtil.onJsonResponse(retCode,data,msg) #data from db dbRecords = CTRecordModel.queryRecordsWithFragment(userId,tag,recordDate,start,end,10) recordData = [] for i in range(len(dbRecords)): chartDateItem = ChartDataUtil.getChartDataFromDBRecordsArr(dbRecords[i]) recordData.append(chartDateItem) data["records"] = recordData; data["count"] = len(recordData) logging.info("return:"+str(data)) return ResponseUtil.onJsonResponse(retCode,data,msg)
def records_stackedBar(request): logging.info("requestWith:"+str(RequestUtil.getAllParams(request))) userId = SessionUtil.getUserIdFromSession(request.session) tag = RequestUtil.getParamFromRequest(request,"tag") date = RequestUtil.getParamFromRequest(request,"date") logging.info("userId :" + str(userId)) if not userId or (not tag and not date): logging.error("request:" + str(request) + "--return home") return home(request) returnData = {"date":date,"tag":tag} logging.info("return:"+str(returnData)) return render(request,'stackedBarChart.html',returnData)
def home(request): logging.info("requestWith:"+str(RequestUtil.getAllParams(request))) userName = SessionUtil.getUserNameFromSession(request.session) if userName == None: logging.error("session without userName") return login(request) #获取当前对象 logging.info("get name from session:" + userName) users = CTRUser.objects.filter(userName = userName) if len(users) == 0: logging.error("db without userName:" + userName) return login(request) return render(request,'home.html')
def my_dates(request): logging.info("requestWith:"+str(RequestUtil.getAllParams(request))) userId = SessionUtil.getUserIdFromSession(request.session) dates = [] tags = [] queryRecords = [] resultRecords = [] logging.info("my_dates :userId " + str(userId)) if not userId: logging.error("not log in") return login(request) else : dates,records = queryAllRecorderDates(userId) data = {'dates':dates,'records':records} logging.info("return:"+str(data)) return render(request,'records-by-date.html',data)
def my_tags(request): logging.info("requestWith:"+str(RequestUtil.getAllParams(request))) userId = SessionUtil.getUserIdFromSession(request.session) tags = [] queryRecords = [] resultRecords = [] countsDic = {} logging.info("my_tags :userId " + str(userId)) if not userId: return login(request) else : tags,queryRecords,countsDic = queryAllRecorderTags(userId) for i in range(len(queryRecords)): # print queryRecords[i] item = {"recordId":queryRecords[i].recordId,"count":countsDic[queryRecords[i].recordTag],"recordTag":queryRecords[i].recordTag,"user_id":queryRecords[i].user_id,"recordDate":float(queryRecords[i].recordDate)/1000.0,"recordDateStr":DateUtil.getDateDayStrFromTimeInterval(float(queryRecords[i].recordDate)/1000.0)} resultRecords.append(item) data = {'tags':tags,'records':resultRecords} logging.info("return:"+str(data)) return render(request,'record-tags.html',data)
def queryRequetForAllRecorderTags(request): logging.info("requestWith:"+str(RequestUtil.getAllParams(request))) retCode = HTTPRSPCode.OK msg = "ok" data = {} userId = SessionUtil.getUserIdFromSession(request.session) tags = [] queryRecords = [] resultRecords = [] logging.info("userId " + str(userId)) if not userId: retCode = HTTPRSPCode.NOT_LOGIN msg = "user not login" else : tags,queryRecords,counts = queryAllRecorderTags(userId) for i in range(len(queryRecords)): item = {"recordId":queryRecords[i].recordId,"recordTag":queryRecords[i].recordTag,"user_id":queryRecords[i].user_id,"recordDate":queryRecords[i].recordDate,"recordDateStr":DateUtil.getDateDayStrFromTimeInterval(float(queryRecords[i].recordDate)/1000.0)} resultRecords.append(item) data = {'tags':tags,'records':resultRecords} logging.info("return:"+str(data)) return ResponseUtil.onJsonResponse(retCode,data,msg)