def editOneProblem(): form = EditProblemForm().validateForApi() userId = g.userInfo.userId Problem.editOneProblem(ownerId=userId, problemId=form.problemId.data, form=form) return Success(information="编辑问题成功")
def editQuestionnaire(): userId = g.userInfo.userId form = QuestionnaireForm().validateForApi() Questionnaire.editQuestionnaire(ownerId=userId, questionnaireId=form.questionnaireId.data, form=form) return Success(information="编辑问卷成功")
def getAnalysisDataByPid(pid): userId = g.userInfo.userId problems = Problem.objects.filter(problemId=pid, ownerId=userId).first() if not problems: raise NoProblem res = problems.getResolution() return Success(information="获取分析数据成功", payload={'problemResolution': res})
def deleteQuestionnaire(): userId = g.userInfo.userId form = DeleteQuestionnaireForm().validateForApi() Problem.deleteProblems(ownerId=userId, questionnaireId=form.questionnaireId.data) Questionnaire.deleteQuestionnaire( ownerId=userId, questionnaireId=form.questionnaireId.data) return Success(information="删除问卷成功")
def getAllQuestionnaire(): userId = g.userInfo.userId res = Questionnaire.getAllQuestionnaire(ownerId=userId) tlen = Questionnaire.getTemplatesAmount() return Success(information="获取用户问卷数据成功", payload={ "questionnaires": res, "tAmount": tlen })
def submitCompleteData(qid): c = Complete() # 生产环境 if not current_app.config['DEBUG']: c.createCompleteData(qid=qid, data=request.json, ip=request.headers['X-Real-Ip']) # 开发环境 else: c.createCompleteData(qid=qid, data=request.json) return Success(information="提交成功 感谢您的参与~")
def userLogin(): form = UserForm().validateForApi() # 登录类型 types = { UserTypeEnum.WEB_USER: User.userLogin, UserTypeEnum.MINI_PROGRAM_USER: User.userLoginByWeChat } u = types[form.type.data](form.userName.data, form.secret.data) token = generateAuthToken(userId=u.getUserId(), clientType=form.type.data.name) return Success(information="登录成功", payload={"token": token})
def deleteOneProblem(): form = DeleteProblemForm().validateForApi() userId = g.userInfo.userId Problem.deleteOneProblem(ownerId=userId, problemId=form.problemId.data) return Success(information="删除问题成功")
def appendOneProblem(): userId = g.userInfo.userId form = ProblemForm().validateForApi() pid = Problem().appendOneProblem(ownerId=userId, form=form) return Success(information="新建问题成功", payload={"problemId": pid})
def getAnalysisData(qid): res = Questionnaire.getAnalysisData(qid) return Success(information="获取分析数据成功", payload=res)
def getTemplates(): form = GetTemplatesForm().validateForApi() data = Questionnaire.getTemplatesBasicInfo(int(form.page.data)) return Success(information='获取问卷模板成功', payload={"data": data})
def getCondition(qid): r = Questionnaire.getConditions(questionnaireId=qid, isAdmin=True) return Success(information="获取问卷状态成功", payload=r)
def checkSecretKey(qid): form = QuestionireSecretCheckForm().validateForApi() res = Questionnaire.checkSecretKey(questionnaireId=qid, key=form.secretKey.data) return Success(information="验证成功", payload=res)
def checkToken(): info = g.userInfo return Success(information="验证成功", payload={"clientType": info.clientType})
def getProfileData(): userId = g.userInfo.userId user = User.objects.filter(id=userId).first() return Success(information="信息获取成功", payload=user.getProfleJson())
def getQuestionnaire(qid): userId = g.userInfo.userId res = Questionnaire.getQuestionnaire(ownerId=userId, questionnaireId=qid, isAdmin=True) return Success(information="获取问卷成功", payload=res)
def copyTemplates(): userId = g.userInfo.userId form = CopyTemplatesForm().validateForApi() Questionnaire.copyTemplates(qid=form.templateId.data, uid=userId) return Success(information='更新成功')
def hello_world(): return Success(information="your project is running now~ (◕ᴗ◕✿)")
def getProblemByPid(problemId): userId = g.userInfo.userId res = Problem.getOneProblemByPid(pid=problemId, oid=userId) return Success(information='更新成功', payload=res)
def createQuestionnaire(): userId = g.userInfo.userId qid = Questionnaire().createQuestionnaire(ownerId=userId) return Success(information="新建问卷成功", payload={"questionnaireId": qid})
def userRegister(): form = WebRegisterForm().validateForApi() # 创建新用户 newUser = User() newUser.userRegister(userName=form.userName.data, password=form.secret.data) return Success(information="注册成功啦~")