def input(self, name="", sex=0, birthday="", class_id="", status="apply", relation_number=3, describe=""): if birthday and not convert.is_date(birthday): raise exception.FormalError(birthday=birthday) if not name: raise exception.ParamNone(name="") if not class_id: raise exception.ParamNone(name="") class_info = db_api.class_get(id=class_id) if not class_info: raise exception.NotFound(code=class_id) values = { "name": name, "sex": sex, #"birthday": birthday, "school_id": class_info.school_id, "grade_id": class_info.grade_id, "class_id": class_id, "describe": describe, #"status": status, "relation_number": relation_number } if birthday: values.update({"birthday": birthday}) student_obj = db_api.student_create(values) if student_obj: history_values={ "student_id": student_obj.get("id"), "staus": status } db_api.student_history_create(history_values) student_obj.update({"status": status}) return student_obj
def update(self, id="", **kwargs): if not id or not kwargs: raise exception.ParamNone(id=id) teacher_info = db_api.teacher_get(id) if not teacher_info: raise exception.NotFound(id=id) if kwargs.get("class_id", ""): class_info = db_api.class_get(id=kwargs.get("class_id")) if not class_info: raise exception.NotFound(class_id=kwargs.get("class_id", "")) kwargs.update({ "school_id": class_info.school_id, "grade_id": class_info.grade_id, }) name = kwargs.get("name", "") if name and convert.bs2utf8( teacher_info.name) != name and db_api.teacher_list(name=name): raise exception.ParamExist(name=name) phone = kwargs.get("phone", "") if phone and convert.bs2utf8( teacher_info.phone) != phone and db_api.teacher_list( phone=phone): raise exception.ParamExist(phone=phone) _ = db_api.teacher_update(id, kwargs) if kwargs.get("status", ""): history_values = { "teacher_id": id, "status": kwargs.get("status", "") } db_api.teacher_history_create(history_values) return _
def info_detail_for_sign(self, id="", start_date="", end_date=""): if not id: raise exception.ParamNone(id=id) teacher_info = db_api.teacher_get(id) if not teacher_info: raise exception.NotFound(id=id) # 关联学校和班级,还有学生得签到(学生亲属的签到信息) teacher_info = self.views(teacher_info) sign_detail = self.com_sign_detail(id, start_date, end_date) sign_data = [] for sign_status in sign_detail: sign_data.append({ "date": datetime.datetime.strftime(sign_status.sign_date, "%Y-%m-%d"), "status": sign_status.status, "morning": sign_status.morning if sign_status.morning else "", "afternoon": sign_status.afternoon if sign_status.afternoon else "" }) teacher_info.update({"sign_data": sign_data}) return teacher_info
def input(self, name="", sex=0, birthday="", school_id="", class_id="", phone="", position=2, describe="", status="education"): if birthday and not convert.is_date(birthday): raise exception.FormalError(birthday=birthday) if not name: raise exception.ParamNone(name="") if phone: _count = db_api.teacher_count(phone=phone) if _count > 0: raise exception.ParamExist(phone=phone) values = { "name": name, "sex": sex, #"birthday": birthday, "school_id": school_id, "phone": phone, "describe": describe, "status": status } if class_id: class_info = db_api.class_get(id=class_id) if class_info: values.update({ "school_id": class_info.school_id, "grade_id": class_info.grade_id, "class_id": class_id, }) if birthday: values.update({"birthday": birthday}) if position != 0: values.update({"position": position}) teacher_obj = db_api.teacher_create(values) if teacher_obj: history_values = { "teacher_id": teacher_obj.get("id"), "status": status } db_api.teacher_history_create(history_values) #teacher_obj.update({"status": status}) return teacher_obj
def input(self, teacher_id, status, describe=""): if not teacher_id or not status: raise exception.ParamNone(teacher_id=teacher_id, status=status) if not db_api.teacher_get(id=teacher_id): raise exception.NotFound(teacher_id=teacher_id) values = { "teacher_id": teacher_id, "status": status, "describe": describe } _ = db_api.teacher_history_create(values) if _: # get latest status db_api.teacher_update(teacher_id, {"status": status}) return values
def batch_input(self, teacher_data): # verify phone if not teacher_data or not isinstance(teacher_data, list): raise exception.ParamNone(teacher_data="") phone_data = [] for teacher_info in teacher_data: if teacher_info.get("phone", ""): phone_data.append(teacher_info.get("phone")) exist_teacher_data = db_api.teacher_list(phone=phone_data) if exist_teacher_data: exist_phones = [ teacher_info.phone for teacher_info in exist_teacher_data ] return False, "phone exist" + ",".join(exist_phones) combination_api.batch_input_teacher(exist_teacher_data) return True, "batch success"
def update(self, id="", **kwargs): if not id or not kwargs: raise exception.ParamNone(id=id) if kwargs.get("class_id"): class_info = db_api.class_get(id=kwargs.get("class_id")) kwargs.update({ "school_id": class_info.school_id, "grade_id": class_info.grade_id, }) status = kwargs.pop("status", "") _ = db_api.student_update(id, kwargs) if status: history_values = { "student_id": id, "staus": status } db_api.student_history_create(history_values) return _
def update(self, id="", **kwargs): if not id or not kwargs: raise exception.ParamNone(grade_id=id) garde_info = db_api.grade_get(id) if not garde_info: raise exception.NotFound(grade_id=id) if kwargs.get("school_id", ""): _ = db_api.school_get(kwargs.get("school_id", "")) if not _: raise exception.NotFound(school_id=kwargs.get("school_id", "")) name = kwargs.get("name", "") if name and convert.bs2utf8(garde_info.name) != name and db_api.teacher_list(name=name): raise exception.ParamExist(grade_name=name) _ = db_api.grade_update(id, kwargs) return _
def update(self, id="", **kwargs): if not id or not kwargs: raise exception.ParamNone(id=id) class_info = db_api.class_get(id) if not class_info: raise exception.NotFound(class_id=id) if kwargs.get("grade_id", ""): _ = db_api.grade_get(kwargs.get("grade_id", "")) if not _: raise exception.NotFound(grade_id=kwargs.get("grade_id", "")) kwargs.update({"school_id": _.school_id}) name = kwargs.get("name", "") if name and convert.bs2utf8(class_info.name) != name and db_api.class_list(name=name): raise exception.ParamExist(class_name=name) _ = db_api.class_update(id, kwargs) return _
def input(self, name="", sex=0, birthday="", phone="", describe=""): if birthday and not convert.is_date(birthday): raise exception.FormalError(birthday=birthday) if phone and not convert.is_mobile(phone): raise exception.FormalError(phone=phone) if not name: raise exception.ParamNone(name=convert.bs2unicode(name)) if phone: relative_list = db_api.relative_list(phone=phone) if relative_list and convert.bs2utf8( relative_list[0].name) != name: raise exception.ParamExist(name=name, phone=phone) values = {"name": name, "sex": sex, "describe": describe} if phone: values.update({"phone": phone}) if birthday: values.update({"birthday": birthday}) relativel_obj = db_api.relative_create(values) return relativel_obj