def post(self, request, num, psd, name, **kwargs): """ 注册 :param request: :return: """ try: Teacher.objects.get(pk=num) return response.err_response(1) except Teacher.DoesNotExist: Teacher.objects.create(num=num, psd=psd, name=name) return response.correct_response()
def post(self, request, num, name, **kwargs): """ 注册 :param request: :return: """ try: Admin.objects.get(pk=num) return response.err_response(1) except Admin.DoesNotExist: Admin.objects.create(num=num, psd=generate_md5('123'), name=name) return response.correct_response()
def post(self, request, me, old, new): """ 修改密码 :param request: :param me: :param old: :param new: :return: """ result = modify_psd(Teacher, me, old, new) if result: return response.correct_response() else: return response.err_response(1)
def post(self, request, num, psd, name, clazz, **kwargs): """ 注册 :param request: :return: 错误code 1,学号已存在 """ try: Student.objects.get(pk=num) return response.err_response(1) except Student.DoesNotExist: Student.objects.create(num=num, psd=psd, name=name, clazz=clazz) return response.correct_response()
def post(self, request, clazz, me): """ 老师添加自己管理的班级 :param request: :param clazz: :param me: :return: 错误code 1,班级已经有班主任 """ if clazz.teacher is not None: return response.err_response(1) else: me.classes.add(clazz) return response.correct_response()
def post(self, request, me, old, new): """ 修改密码 :param request: :param me: :param old: :param new: :return: 错误code 1,原密码错误 """ result = modify_psd(Student, me, old, new) if result: return response.correct_response() else: return response.err_response(1)
def get(self, request, num, psd): """ 登录 :param request: :return: 错误code 1:账号或密码错误 """ try: user = Teacher.objects.get(pk=num, psd=psd) token = user.update_token() res = response.correct_response() res.set_cookie('TOKEN', token) res.set_cookie('role', User.ROLE_TEACHER) return res except Teacher.DoesNotExist: return response.err_response(1)
def post(self, request, me, leave, allow=False): """ 审核请假 :param request: :param me: :return: 错误code 1,该请假申请已审核,不能修改 """ if leave.state != Leave.STATE_WAITING: return response.err_response(1) if leave.student.clazz.teacher.num == me.num: if allow: Leave.objects.filter(pk=leave.id).update(state=Leave.STATE_YES) else: Leave.objects.filter(pk=leave.id).update(state=Leave.STATE_NO) return response.correct_response() else: return response.err_response_not_belong('teacher', me.num, 'leave', leave.id)