def apiPageIndex(request, pId): token = request.COOKIES[globalVars.IToken] try: tokenObj = Token.objects.get(Token=token) taskCount = TaskModel.objects.filter(project_id=int(pId)).count() apiCount = ApiDefine.objects.filter(project_id=int(pId)).count() caseCount = TestCaseModel.objects.filter(project_id=int(pId)).count() suiteCount = TestSuiteModel.objects.filter(project_id=int(pId)).count() tasks = TaskHistoryModel.objects.filter(project_id=int(pId)) charts = [] for i in tasks: charts.append(i.getChartData()) except Token.DoesNotExist: globalVars.getLogger().error("token不存在") return HttpResponseRedirect(reverse('login')) else: data = {} data["userName"] = tokenObj.user.user data["userId"] = tokenObj.user.id data["task"] = taskCount data["api"] = apiCount data["case"] = caseCount data["suite"] = suiteCount data["pId"] = pId data["charts"] = json.dumps(charts) return render(request, "apiIndex.html", globalVars.responeContent("true", "success", data))
def register(request): """ 注册请求 :param request: :return: """ if request.method == "POST": #req = tools.json_to_dict(request.body) #user_name = tools.get_request_key(req, "user") #pwd = tools.get_request_key(req, "pwd") user_name = request.POST.get("user", "") pwd = request.POST.get("pwd", "") if not user_name or not pwd: return tools.response_failed(u"账号或者密码不能为空") user = UsersDao.get_user_by_name(user_name) if user is None: token = globalVars.generateToken(user_name) date = datetime.datetime.now() + datetime.timedelta(days=30) new_user = UsersDao.create_user(user_name, pwd) if new_user is None: return tools.response_failed(u"创建账号失败") new_token = TokenDao.create_token(new_user, token, date) if new_token is None: return tools.response_failed(u"token创建失败") cache.set(token, new_token.expireDate, settings.REDIS_TIMEOUT) return tools.response_by_json( data={"token": token, "token_name": globalVars.IToken, "token_expird": 30}) else: return tools.response_failed(u"账号已存在,请重新输入!") # 访问登录页面 else: return render(request, "register.html", globalVars.responeContent("true", "访问注册页面成功", {}))
def index(request): token = request.COOKIES[globalVars.IToken] token_obj = TokenDao.get_token_by_token(token) if token_obj is None: return HttpResponseRedirect(reverse('login')) user_name = token_obj.user.user user_id = token_obj.user.id content = globalVars.responeContent("true", "success", {"user_name": user_name, "user_id": user_id}) return render(request, "index.html", content)
def user_setting_page(request): """ 个人设置页面 :param request: :return: """ token = request.COOKIES[globalVars.IToken] token_obj = TokenDao.get_token_by_token(token) if token_obj is None: return HttpResponseRedirect(reverse('login')) else: user_name = token_obj.user.user user_id = token_obj.user.id content = globalVars.responeContent("true", "success", {"user_name": user_name, "user_id": user_id}) return render(request, "user_setting.html", content)
def apitest(request): token = request.COOKIES[globalVars.IToken] try: tokenObj = Token.objects.get(Token=token) except Token.DoesNotExist: globalVars.getLogger().error("token不存在") return HttpResponseRedirect(reverse('login')) else: userName = tokenObj.user.user userId = tokenObj.user.id return render( request, "apiIndextest.html", globalVars.responeContent("true", "success", { "userName": userName, "userId": userId }))
def getHistoryResultPage(request,hId): try: task = TaskHistoryModel.objects.get(pk=int(hId)) except Exception as e: globalVars.getLogger().error(e.message) return HttpResponseRedirect(reverse('index')) else: preResultIds = task.lastRunningPreResultIdList resultIds = task.lastRunningResultIdList data={} data["name"] = task.taskName data["version"] = task.lastResultVersion data["time"] = task.lastRunningTime data["preSql"] = __getSuitePresql(task.suiteId) data["postSql"] = __getSuitePostsql(task.suiteId) data["results"] = __getResultLists(resultIds) data["preResults"] = __getResultLists(preResultIds) data["message"] = task.lastRunningResult return render(request, "historyResult.html",globalVars.responeContent("true", "success",data))