def checkPass(request): """ @api {post} /specificApis/user/checkPass checkPass @apiVersion 1.0.0 @apiDescription checkPass @apiName checkPass @apiGroup user @apiParam {string} password password @apiSuccessExample {json} Success-Response: HTTP/1.1 200 OK { "error": 0, "result": "login" } @apiErrorExample {json} Error-Response: HTTP/1.1 200 OK { "error": 1, "reason": "error reason here" } """ if request.method == "POST": password = request.POST.get('password') username = request.session.get('username') try: password = function.hash(password) if function.check_UserPass(username, password): return function.retJson(error=0, result='check password success') else: return function.retJson(error=3, reason='wrong password') except Exception as e: return function.retJson(error=2, reason=str(e)) else: return function.retJson(error=1, reason='please use post')
def getConfig(request): """ @api {get} /specificApis/admin/getConfig getConfig @apiVersion 1.0.0 @apiDescription 查看开始结束时间、要求时长等配置信息 @apiName getConfig @apiGroup admin @apiSuccessExample {json} Success-Response: HTTP/1.1 200 OK { "error": 0, "result": "{'startTime':'xxx', ……}" } @apiErrorExample {json} Error-Response: HTTP/1.1 200 OK { "error": 1, "reason": "error reason here" } """ try: if not function.check_adminSession(request): return function.retJson(error=-1, reason='have not login') conf = Config.objects.get(name='default') rets = {'startTime': str(conf.startTime), 'endTime': str(conf.endTime), 'requiredPoints': conf.requiredPoints, 'pointsPerHour': conf.pointsPerHour} return function.retJson(error=0, result=rets) except Exception as e: return function.retJson(error=1, reason=str(e))
def getUsername(request): """ @api {get} /specificApis/user/getUsername getUsername @apiVersion 1.0.0 @apiDescription get username @apiName getUsername @apiGroup user @apiSuccessExample {json} Success-Response: HTTP/1.1 200 OK { "error": 0, "result": "get username success" } @apiErrorExample {json} Error-Response: HTTP/1.1 200 OK { "error": 1, "reason": "error reason here" } """ if not function.check_Session(request) and not function.check_gradeAdminSession(request): return function.retJson(error=-1, reason='have not login') if function.check_Session(request): username = request.session.get('username') role = 'user' elif function.check_gradeAdminSession(request): username = request.session.get('username_grade') role = 'gradeAdmin' return function.retJson(error=0, result=username, role=role)
def gradeAdd(request): """ @api {POST} /specificApis/grade/gradeAdd gradeAdd @apiVersion 1.0.0 @apiDescription add a grade @apiName gradeAdd @apiGroup grade @apiParam {string} grade grade @apiParam {string} college college @apiSuccessExample {json} Success-Response: HTTP/1.1 200 OK { "error": 0, "result": "create grade success" } @apiErrorExample {json} Error-Response: HTTP/1.1 200 OK { "error": 1, "reason": "error reason here" } """ if not function.check_adminSession(request): return function.retJson(error=-1, reason='have not login') if request.method == "POST": try: grade = request.POST.get('grade') college = request.POST.get('college') gradeAccount = Grade(grade=grade, college=college) gradeAccount.save() return function.retJson(error=0, result="create grade success") except Exception as e: return function.retJson(error=3, reason=str(e)) else: return function.retJson(error=1, reason='need method: post')
def gradeGetAll(request): """ @api {get} /specificApis/grade/gradeGetAll gradeGetAll @apiVersion 1.0.0 @apiDescription get All grade @apiName gradeGetAll @apiGroup grade @apiSuccessExample {json} Success-Response: HTTP/1.1 200 OK { "error": 0, "result": "{"grade": admin2018, "college": "2018"}" } @apiErrorExample {json} Error-Response: HTTP/1.1 200 OK { "error": 1, "reason": "error reason here" } """ try: grade = list(Grade.objects.filter().values()) return function.retJson(error=0, result=grade) except Exception as e: return function.retJson(error=3, reason=str(e))
def getUserClassNumber(request): """ @api {get} /specificApis/user/getUserClassNumber getUserClassNumber @apiVersion 1.0.0 @apiDescription getUserClassNumber @apiName getUserClassNumber @apiGroup user @apiSuccessExample {json} Success-Response: HTTP/1.1 200 OK { "error": 0, "result": "get UserClassNumber success" } @apiErrorExample {json} Error-Response: HTTP/1.1 200 OK { "error": 1, "reason": "error reason here" } """ if not function.check_Session(request): return function.retJson(error=-1, reason='have not login') try: username = request.session.get('username') classNumber = User.objects.filter(username=username).values()[ 0]['classNumber'] return function.retJson(error=0, classNumber=classNumber) except Exception as e: return function.retJson(error=1, reason=str(e))
def signOutCron(request): """ @api {get} /specificApis/studentData/signOutCron signOutCron @apiVersion 1.0.0 @apiDescription signOutCron @apiName signOutCron @apiGroup studentData @apiSuccessExample {json} Success-Response: HTTP/1.1 200 OK { "error": 0, "result": "success" } @apiErrorExample {json} Error-Response: HTTP/1.1 200 OK { "error": 1, "reason": "error reason here" } """ try: ret = function.cron_signOut() return function.retJson(error=0, result=ret) except Exception as e: return function.retJson(error=2, reason=str(e))
def logout(request): """ @api {get} /specificApis/admin/logout logout @apiVersion 1.0.0 @apiDescription 系统管理员退出登录 @apiName logout @apiGroup admin @apiSuccessExample {json} Success-Response: HTTP/1.1 200 OK { "error": 0, "result": "logout" } @apiErrorExample {json} Error-Response: HTTP/1.1 200 OK { "error": 1, "reason": "error reason here" } """ try: if not function.check_adminSession(request): return function.retJson(error=-1, reason='have not login') request.session.flush() return function.retJson(error=0, resule='logout') except Exception as e: return function.retJson(error=1, reason=str(e))
def gradeAdminGetAll(request): """ @api {get} /specificApis/gradeAdmin/gradeAdminGetAll gradeAdminGetAll @apiVersion 1.0.0 @apiDescription get All gradeAdmin @apiName gradeAdminGetAll @apiGroup gradeAdmin @apiSuccessExample {json} Success-Response: HTTP/1.1 200 OK { "error": 0, "result": "{"username": admin2018, "grade": "2018"}" } @apiErrorExample {json} Error-Response: HTTP/1.1 200 OK { "error": 1, "reason": "error reason here" } """ if not function.check_adminSession(request): return function.retJson(error=-1, reason='have not login') try: gradeAdminList = list(GradeAdmin.objects.filter().values()) for gradeAdmin in gradeAdminList: gradeAdmin.pop("id") gradeAdmin.pop("password") return function.retJson(error=0, result=gradeAdminList) except Exception as e: return function.retJson(error=3, reason=str(e))
def GAclassDelete(request): """ @api {post} /specificApis/gradeAdmin/GAclassDelete GAclassDelete @apiVersion 1.0.0 @apiDescription 删除班级,班级有同学的时候,拒绝删除 @apiName GAclassDelete @apiGroup gradeAdmin @apiParam {string} classNumber classNumber @apiSuccessExample {json} Success-Response: HTTP/1.1 200 OK { "error": 0, "result": "delete class success" } @apiErrorExample {json} Error-Response: HTTP/1.1 200 OK { "error": 1, "reason": "error reason here" } """ if not function.check_gradeAdminSession(request): return function.retJson(error=-1, reason='have not login') if request.method == "POST": try: classNumber = request.POST.get('classNumber') Classes.objects.get(classNumber=classNumber).delete() return function.retJson(error=0, result="delete class success") except Exception as e: return function.retJson(error=2, reason=str(e)) else: return function.retJson(error=1, reason='needmethod: get')
def gradeAdminDelete(request): """ @api {post} /specificApis/gradeAdmin/gradeAdminDelete gradeAdminDelete @apiVersion 1.0.0 @apiDescription delete gradeAdmin @apiName gradeAdminDelete @apiGroup gradeAdmin @apiParam {string} username grade admin username @apiSuccessExample {json} Success-Response: HTTP/1.1 200 OK { "error": 0, "result": "delete admin success" } @apiErrorExample {json} Error-Response: HTTP/1.1 200 OK { "error": 1, "reason": "error reason here" } """ if not function.check_adminSession(request): return function.retJson(error=-1, reason='have not login') if request.method == "POST": username = request.POST.get('username') try: GradeAdmin.objects.get(username=username).delete() return function.retJson(error=0, result="delete grade admin success") except Exception as e: return function.retJson(error=3, reason=str(e)) else: return function.retJson(error=1, reason='need method: post')
def studentGet(request): """ @api {get} /specificApis/student/get studentGet @apiVersion 1.0.0 @apiDescription studentGet @apiName studentGet @apiGroup student @apiSuccessExample {json} Success-Response: HTTP/1.1 200 OK { "error": 0, "result": value } @apiErrorExample {json} Error-Response: HTTP/1.1 200 OK { "error": 1, "reason": "error reason here" } """ if not function.check_Session( request) and not function.check_gradeAdminSession(request): return function.retJson(error=-1, reason='have not login') if request.method == "GET": value = list(Student.objects.all().values()) return function.retJson(error=0, result=value, mycls=function.MyEncoder) else: return function.retJson(error=1, reason='needmethod: get')
def changePass(request): """ @api {post} /specificApis/admin/changePass changePass @apiVersion 1.0.0 @apiDescription 修改密码 @apiName changePass @apiGroup admin @apiParam {string} password password @apiSuccessExample {json} Success-Response: HTTP/1.1 200 OK { "error": 0, "result": "change admin's password success" } @apiErrorExample {json} Error-Response: HTTP/1.1 200 OK { "error": 1, "reason": "error reason here" } """ if not function.check_adminSession(request): return function.retJson(error=-1, reason='have not login') if request.method == "POST": password = request.POST.get('password') username = request.session.get('username_admin') password = function.hash(password) try: admin_Account = Administrator.objects.filter(username=username) admin_Account.update(password=password) return function.retJson(error=0, result="change admin's password success") except Exception as e: return function.retJson(error=2, reason=str(e)) else: return function.retJson(error=3, reason='needmethod: post')
def export(request): """ @api {get} /specificApis/export export @apiVersion 1.0.0 @apiDescription export student info @apiName export @apiGroup export @apiSuccessExample {json} Success-Response: HTTP/1.1 200 OK { "error": 0, "result": "get all class info success" } @apiErrorExample {json} Error-Response: HTTP/1.1 200 OK { "error": 1, "reason": "error reason here" } """ if not function.check_gradeAdminSession(request): return function.retJson(error=-1, reason='have not login') if request.method == "GET": try: now = datetime.now().strftime('%Y_%m_%d') filename = 'student_info_' + now + '.xlsx' base_dir = os.path.dirname( os.path.dirname(os.path.abspath(__file__))) file_path = os.path.join(base_dir, 'file', 'download', filename) # 下载文件的绝对路径 # 写入 students = list(Student.objects.all().values()) for stuInfo in students: info = function.getStudentData(stuInfo["studentId"])[0] stuInfo.update(info) ret = function.write_excel_xlsx(file_path, students) if ret != 'success': return function.retJson(error=3, reason=ret) # 输出 file = open(file_path, 'rb') response = FileResponse(file) response['Content-Type'] = 'application/octet-stream' response[ 'Content-Disposition'] = 'attachment;filename="{}"'.format( filename).encode('utf-8') return response except Exception as e: return function.retJson(error=2, reason=str(e)) else: return function.retJson(error=1, reason='needmethod: get')
def userAdd(request): """ @api {post} /specificApis/user/add userAdd @apiVersion 1.0.0 @apiDescription userAdd @apiName userAdd @apiGroup user @apiParam {string} username username unique @apiParam {string} password password @apiParam {string} classNumber classNumber unique @apiParam {string} grade grade @apiSuccessExample {json} Success-Response: HTTP/1.1 200 OK { "error": 0, "result": "create user success" } @apiErrorExample {json} Error-Response: HTTP/1.1 200 OK { "error": 1, "reason": "error reason here" } """ if not function.check_gradeAdminSession(request): return function.retJson(error=-1, reason='have not login') if request.method == "POST": username = request.POST.get('username') password = request.POST.get('password') classNumber = request.POST.get('classNumber') grade = request.POST.get('grade') # TODO password decode password = function.hash(password) try: gradeAccount = Grade.objects.get(grade=grade) user_Account = User(username=username, password=password, classNumber=classNumber) user_Account.save() try: class_Account = Classes(classNumber=user_Account, grade=gradeAccount) class_Account.save() return function.retJson(error=0, result="create user success") except Exception as e: return function.retJson(error=1, reason=str(e)) except Exception as e: return function.retJson(error=2, reason=str(e)) else: return function.retJson(error=3, reason='needmethod: post')
def studentAdd(request): """ @api {post} /specificApis/student/add studentAdd @apiVersion 1.0.0 @apiDescription studentAdd @apiName studentAdd @apiGroup student @apiParam {string} studentId studentId unique @apiParam {string} name name @apiParam {int} sex sex @apiParam {int} state state @apiParam {int} initPoints initial points @apiParam {string} classNumber classNumber 外键 @apiSuccessExample {json} Success-Response: HTTP/1.1 200 OK { "error": 0, "result": "create student success" } @apiErrorExample {json} Error-Response: HTTP/1.1 200 OK { "error": 1, "reason": "error reason here" } """ if not function.check_Session(request): return function.retJson(error=-1, reason='have not login') if request.method == "POST": studentId = request.POST.get('studentId') name = request.POST.get('name') sex = request.POST.get('sex') state = request.POST.get('state') initPoints = request.POST.get('initPoints') classNumber = request.POST.get('classNumber') try: class_Account = Classes.objects.get(classNumber=classNumber) student_Account__ = Student(classNumber=class_Account, sex=sex, studentId=studentId, name=name, state=state, initPoints=initPoints) student_Account__.save() return function.retJson(error=0, result="create student success") except Exception as e: return function.retJson(error=2, reason=str(e)) else: return function.retJson(error=1, reason='needmethod: post')
def GAclassAdd(request): """ @api {post} /specificApis/gradeAdmin/GAclassAdd GAclassAdd @apiVersion 1.0.0 @apiDescription 添加班级,并将会创建一个默认班级负责人,此管理员用户名和初始密码与班号相同。 @apiName GAclassAdd @apiGroup gradeAdmin @apiParam {string} classNumber classNumber @apiSuccessExample {json} Success-Response: HTTP/1.1 200 OK { "error": 0, "result": "create class and user success" } @apiErrorExample {json} Error-Response: HTTP/1.1 200 OK { "error": 1, "reason": "error reason here" } """ if not function.check_gradeAdminSession(request): return function.retJson(error=-1, reason='have not login') if request.method == "POST": try: grade = GradeAdmin.objects.get( username=request.session.get('username_grade')).grade.grade classNumber = request.POST.get('classNumber') username = classNumber password = classNumber password = function.hash(password) gradeAccount = Grade.objects.get(grade=grade) user_Account = User(username=username, password=password, classNumber=classNumber) user_Account.save() try: class_Account = Classes(classNumber=user_Account, grade=gradeAccount) class_Account.save() return function.retJson(error=0, result="create class and user success") except Exception as e: return function.retJson(error=1, reason=str(e)) except Exception as e: return function.retJson(error=2, reason=str(e)) else: return function.retJson(error=3, reason='needmethod: post')
def studentChange(request): """ @api {post} /specificApis/student/change studentChange @apiVersion 1.0.0 @apiDescription studentChange @apiName studentChange @apiGroup student @apiParam {string} studentId studentId unique @apiParam {string} name name @apiParam {int} sex sex @apiParam {string} classNumber classNumber 外键 @apiSuccessExample {json} Success-Response: HTTP/1.1 200 OK { "error": 0, "result": change student success } @apiErrorExample {json} Error-Response: HTTP/1.1 200 OK { "error": 1, "reason": "error reason here" } """ if not function.check_Session(request): return function.retJson(error=-1, reason='have not login') if request.method == "POST": studentId = request.POST.get('studentId') name = request.POST.get('name') sex = request.POST.get('sex') sex = 1 if (sex == "男") else 0 initPoints = request.POST.get('initPoints') # classNumber = request.POST.get('classNumber') if function.checkExist_student(studentId): try: stud = Student.objects.filter(studentId=studentId) stud.update(name=name, sex=sex, initPoints=initPoints) # class_Account = Classes.objects.get(classNumber=classNumber) # stud.update(classNumber=class_Account, name=name, sex=sex) return function.retJson(error=0, result="change student success") except Exception as e: return function.retJson(error=3, reason=str(e)) else: return function.retJson(error=2, reason='Students dont exist') else: return function.retJson(error=1, reason='needmethod: post')
def login(request): """ @api {post} /specificApis/admin/login login @apiVersion 1.0.0 @apiDescription 系统管理员和年级管理员 登录 @apiName login @apiGroup admin @apiParam {string} username username unique @apiParam {string} password password @apiSuccessExample {json} Success-Response: HTTP/1.1 200 OK { "error": 0, "result": "grade admin" or "admin" } @apiErrorExample {json} Error-Response: HTTP/1.1 200 OK { "error": 1, "reason": "error reason here" } """ if request.method == "POST": username = request.POST.get('username') password = request.POST.get('password') try: request.session.flush() password = function.hash(password) res_admin = function.check_adminPass(username, password) res_grade = function.check_gradeAdminPass(username, password) if res_admin: request.session['is_login_admin'] = True request.session['username_admin'] = username return function.retJson(error=0, result='admin login success', types='admin') elif res_grade: request.session['is_login_grade'] = True request.session['username_grade'] = username return function.retJson(error=0, result='grade admin login success', types='grade') else: return function.retJson(error=3, reason='wrong username or password') except Exception as e: return function.retJson(error=2, reason=str(e)) else: return function.retJson(error=1, reason='wrong method')
def getAllClass(request): """ @api {get} /specificApis/show/getAllClass getAllClass @apiVersion 1.0.0 @apiDescription get all class info @apiName getAllClass @apiGroup show @apiSuccessExample {json} Success-Response: HTTP/1.1 200 OK { "error": 0, "result": "get all class info success" } @apiErrorExample {json} Error-Response: HTTP/1.1 200 OK { "error": 1, "reason": "error reason here" } """ if not function.check_gradeAdminSession(request): return function.retJson(error=-1, reason='have not login') if request.method == "GET": try: classes = Classes.objects.filter().values() people = 0 requiredPeople = 0 classInfo = [] for cl in classes: classNumber = cl['classNumber_id'] info = function.getClassData(classNumber)[0] people += info['number'] requiredPeople += info['requiredPeople'] classInfo.append(info) result = {'people': people, 'requiredPeople': requiredPeople} return function.retJson(error=0, result=result, classInfo=classInfo, mycls=function.MyEncoder) except Exception as e: return function.retJson(error=2, reason=str(e)) else: return function.retJson(error=1, reason='needmethod: get')
def GAchangePass(request): """ @api {post} /specificApis/gradeAdmin/GAchangePass GAchangePass @apiVersion 1.0.0 @apiDescription 修改密码 @apiName GAchangePass @apiGroup gradeAdmin @apiParam {string} password_new password_new @apiParam {string} password_old password_old @apiSuccessExample {json} Success-Response: HTTP/1.1 200 OK { "error": 0, "result": "change grade_admin's password success" } @apiErrorExample {json} Error-Response: HTTP/1.1 200 OK { "error": 1, "reason": "error reason here" } """ if not function.check_gradeAdminSession(request): return function.retJson(error=-1, reason='have not login') if request.method == "POST": try: username = request.session.get('username_grade') password_new = request.POST.get('password_new') password_new = function.hash(password_new) password_old = request.POST.get('password_old') password_old = function.hash(password_old) if not function.check_gradeAdminPass(username, password_old): return function.retJson(error=3, reason='wrong password') else: admin_Account = GradeAdmin.objects.filter(username=username) admin_Account.update(password=password_new) return function.retJson( error=0, result="change grade_admin's password success") except Exception as e: return function.retJson(error=2, reason=str(e)) else: return function.retJson(error=1, reason='needmethod: post')
def gradeAdminAdd(request): """ @api {post} /specificApis/gradeAdmin/gradeAdminAdd gradeAdminAdd @apiVersion 1.0.0 @apiDescription add grade admin @apiName gradeAdminAdd @apiGroup gradeAdmin @apiParam {string} username username unique @apiParam {string} password password @apiParam {string} gradeId gradeId @apiSuccessExample {json} Success-Response: HTTP/1.1 200 OK { "error": 0, "result": "create admin success" } @apiErrorExample {json} Error-Response: HTTP/1.1 200 OK { "error": 1, "reason": "error reason here" } """ if not function.check_adminSession(request): return function.retJson(error=-1, reason='have not login') if request.method == "POST": username = request.POST.get('username') gradeId = request.POST.get('gradeId') password = request.POST.get('password') password = function.hash(password) try: gradeInfo = Grade.objects.get(id=gradeId) admin_Account = GradeAdmin(username=username, password=password, grade=gradeInfo) admin_Account.save() return function.retJson(error=0, result="create grade admin success") except Exception as e: return function.retJson(error=2, reason=str(e)) else: return function.retJson(error=3, reason='need method: post')
def GAgetClasses(request): """ @api {get} /specificApis/gradeAdmin/GAgetClasses GAgetClasses @apiVersion 1.0.0 @apiDescription 获取当前年级管理员管理的年级下的所有班级 @apiName GAgetClasses @apiGroup gradeAdmin @apiSuccessExample {json} Success-Response: HTTP/1.1 200 OK { "error": 0, "result": "" } @apiErrorExample {json} Error-Response: HTTP/1.1 200 OK { "error": 1, "reason": "error reason here" } """ if not function.check_gradeAdminSession(request): return function.retJson(error=-1, reason='have not login') if request.method == "GET": try: username = request.session.get('username_grade') grade = GradeAdmin.objects.get(username=username).grade.grade classes = list(Classes.objects.filter(grade=grade).values()) users = [] for item in classes: info = item['classNumber_id'] userInfo = list(User.objects.filter(classNumber=info).values()) users.append({'user': userInfo[0]['username'], 'class': info}) return function.retJson(error=0, classes=classes, users=users, grade=grade, mycls=function.MyEncoder) except Exception as e: return function.retJson(error=2, reason=str(e)) else: return function.retJson(error=1, reason='needmethod: get')
def editConfig(request): """ @api {post} /specificApis/admin/editConfig editConfig @apiVersion 1.0.0 @apiDescription 修改开始结束时间、要求时长等配置信息 @apiName editConfig @apiGroup admin @apiParam {string} endTime endTime @apiParam {string} startTime startTime @apiParam {string} requiredPoints requiredPoints @apiSuccessExample {json} Success-Response: HTTP/1.1 200 OK { "error": 0, "result": "edit config success" } @apiErrorExample {json} Error-Response: HTTP/1.1 200 OK { "error": 1, "reason": "error reason here" } """ try: if not function.check_adminSession(request): return function.retJson(error=-1, reason='have not login') if request.method == "POST": conf = Config.objects.get(name='default') conf.endTime = request.POST.get('endTime') conf.startTime = request.POST.get('startTime') conf.requiredPoints = request.POST.get('requiredPoints') # conf.pointsPerHour = request.POST.get('pointsPerHour') conf.save() return function.retJson(error=0, resule="edit config success") else: return function.retJson(error=3, reason='needmethod: post') except Exception as e: return function.retJson(error=1, reason=str(e))
def login(request): """ @api {post} /specificApis/login/login login @apiVersion 1.0.0 @apiDescription login @apiName login @apiGroup user @apiParam {string} username username unique @apiParam {string} password password @apiSuccessExample {json} Success-Response: HTTP/1.1 200 OK { "error": 0, "result": "login" } @apiErrorExample {json} Error-Response: HTTP/1.1 200 OK { "error": 1, "reason": "error reason here" } """ if request.method == 'POST': try: username = request.POST.get('username') password = request.POST.get('password') request.session.flush() password = function.hash(password) if function.check_UserPass(username, password): request.session['is_login'] = True request.session['username'] = username return function.retJson(error=0, result='login') else: return function.retJson(error=3, reason='wrong username or password') except Exception as e: return function.retJson(error=2, reason=str(e)) else: return function.retJson(error=1, reason='wrong method')
def getClassData(request): """ @api {post} /specificApis/show/getClassData getClassData @apiVersion 1.0.0 @apiDescription getClassData @apiName getClassData @apiGroup show @apiParam {string} classNumber classNumber @apiSuccessExample {json} Success-Response: HTTP/1.1 200 OK { "error": 0, "result": "get all class info success" } @apiErrorExample {json} Error-Response: HTTP/1.1 200 OK { "error": 1, "reason": "error reason here" } """ if not function.check_Session( request) and not function.check_gradeAdminSession(request): return function.retJson(error=-1, reason='have not login') if request.method == "POST": try: classNumber = request.POST.get('classNumber') classs, students = function.getClassData(classNumber) return function.retJson(error=0, classs=classs, data=list(students), mycls=function.MyEncoder) except Exception as e: return function.retJson(error=2, reason=str(e)) else: return function.retJson(error=1, reason='needmethod: get')
def GAcheckPass(request): """ @api {post} /specificApis/gradeAdmin/GAcheckPass GAcheckPass @apiVersion 1.0.0 @apiDescription 修改密码时检查原密码正确性 @apiName GAcheckPass @apiGroup gradeAdmin @apiParam {string} password password @apiSuccessExample {json} Success-Response: HTTP/1.1 200 OK { "error": 0, "result": "check password success" } @apiErrorExample {json} Error-Response: HTTP/1.1 200 OK { "error": 1, "reason": "error reason here" } """ if not function.check_gradeAdminSession(request): return function.retJson(error=-1, reason='have not login') if request.method == "POST": try: username = request.session.get('username_grade') password = request.POST.get('password') password = function.hash(password) if function.check_gradeAdminPass(username, password): return function.retJson(error=0, result='check password success') else: return function.retJson(error=3, reason='wrong password') except Exception as e: return function.retJson(error=2, reason=str(e)) else: return function.retJson(error=1, reason='please use post')
def adminAdd(request): """ @api {post} /specificApis/admin/add adminAdd @apiVersion 1.0.0 @apiDescription adminAdd @apiName adminAdd @apiGroup admin @apiParam {string} username username unique @apiParam {string} password password @apiSuccessExample {json} Success-Response: HTTP/1.1 200 OK { "error": 0, "result": "create admin success" } @apiErrorExample {json} Error-Response: HTTP/1.1 200 OK { "error": 1, "reason": "error reason here" } """ if request.method == "POST": username = request.POST.get('username') password = request.POST.get('password') password = function.hash(password) try: admin_Account = Administrator( username=username, password=password) admin_Account.save() return function.retJson(error=0, result="create admin success") except Exception as e: return function.retJson(error=2, reason=str(e)) else: return function.retJson(error=3, reason='need method: post')
def getClassStudents(request): """ @api {get} /specificApis/studentData/getClassStudents getClassStudents @apiVersion 1.0.0 @apiDescription get this class's students @apiName getClassStudents @apiGroup studentData @apiSuccessExample {json} Success-Response: HTTP/1.1 200 OK { "error": 0, "result": "ask for leave success" } @apiErrorExample {json} Error-Response: HTTP/1.1 200 OK { "error": 1, "reason": "error reason here" } """ if not function.check_Session(request): return function.retJson(error=-1, reason='have not login') if request.method == "GET": try: username = request.session.get('username') classNumber = User.objects.filter( username=username).values()[0]['classNumber'] stu = Student.objects.filter( classNumber__classNumber=classNumber).values() return function.retJson(error=0, result=list(stu), mycls=function.MyEncoder) except Exception as e: return function.retJson(error=2, reason=str(e)) else: return function.retJson(error=1, reason='needmethod: get')
def studentDelete(request): """ @api {post} /specificApis/student/delete studentDelete @apiVersion 1.0.0 @apiDescription Delete student @apiName studentDelete @apiGroup student @apiParam {string} studentId studentId unique @apiSuccessExample {json} Success-Response: HTTP/1.1 200 OK { "error": 0, "result": "delete student success" } @apiErrorExample {json} Error-Response: HTTP/1.1 200 OK { "error": 1, "reason": "error reason here" } """ if not function.check_Session(request): return function.retJson(error=-1, reason='have not login') if request.method == "POST": studentId = request.POST.get('studentId') if function.checkExist_student(studentId): try: Student.objects.filter(studentId=studentId).delete() return function.retJson(error=0, result="delete student success") except Exception as e: return function.retJson(error=3, reason=str(e)) else: return function.retJson(error=2, reason='Students dont exist') else: return function.retJson(error=1, reason='needmethod: post')