def update(self, id="", **kwargs): if not id or not kwargs: raise ParamNone(id=id) LOG.info("kwargs 111:%r" % kwargs) user_info = db_api.user_get(id) current_user_level = kwargs.pop("current_user_level") if not user_info or current_user_level >= user_info.level: raise FormalError(current_user_level=current_user_level, level=user_info.level) if kwargs.get("school_id", ""): _ = db_api.school_get(kwargs.get("school_id", "")) if not _: raise NotFound(school_id=kwargs.get("school_id", "")) name = kwargs.get("name", "") if name and convert.bs2utf8( user_info.name) != name and db_api.user_list(name=name): raise ParamExist(name=name) phone = kwargs.get("phone", "") if phone and convert.bs2unicode( user_info.phone) != phone and db_api.user_list(phone=phone): raise ParamExist(phone=phone) if kwargs.get("pwd", ""): kwargs.pop("pwd") LOG.info("kwargs 444:%r" % kwargs) _ = db_api.user_update(id, kwargs) return _
def input(self, school_id, phone, face_token, faceset_token, filename="", relevance_type=1, alias=""): if not db_api.school_get(id=school_id): return values = { "school_id": school_id, "phone": phone, "relevance_type": relevance_type, "face_token": face_token, "faceset_token": faceset_token, "img_path": filename, "alias": alias, } if relevance_type in (1, 3): relative_infos = db_api.relative_list(phone=phone) if not relative_infos: raise exception.NotFound(phone=phone) relative_ids = [relative_info.id for relative_info in relative_infos] relation_list = db_api.relation_list(relative_id=relative_ids) if relation_list: values.update({"student_id": relation_list[0].student_id}) if relevance_type == 2: if not db_api.teacher_get_byphone(phone=phone): raise exception.NotFound(phone=phone) face_obj = db_api.face_create(values) return face_obj
def student_relative_excel(self, student_id="", student_name="", school_id="", grade_id="", class_id=""): filters = {} if student_id: filters.update({"id": student_id}) if student_name: filters.update({"name": student_name}) if school_id: filters.update({"school_id": school_id}) if grade_id: filters.update({"grade_id": grade_id}) if class_id: filters.update({"grade_id": class_id}) student_list = db_api.student_list(**filters) views_list = self.views(student_list) for view in views_list: school_info = db_api.school_get(id=view.get("school_id")) if school_info: view.update({"school_name": school_info.name}) grade_info = view.get("grade_info", None) if grade_info: view.update({"grade_name": grade_info.get("name")}) class_info = view.get("class_info", None) if class_info: view.update({"class_name": class_info.get("name")}) relation_list = self._get_relative_by_student(view.get("id")) if relation_list: view.update({"relative_list": relation_list}) return views_list
def infos(self, id="", name="", phone="", school_id="", limit=100, offset=1): offset = (offset - 1) * limit if offset > 0 else 0 filters = dict() if id: filters.update({"id": id}) if name: filters.update({"name": name}) if phone: filters.update({"phone": phone}) if school_id: filters.update({"school_id": school_id}) user_list = db_api.user_list(offset=offset, limit=limit, **filters) user_count = db_api.user_count(**filters) user_views = self.views(user_list) for user_info in user_views: school_info = db_api.school_get(id=user_info.get("school_id")) if school_info: user_info.update({"school_name": school_info.name}) return { "count": user_count, "state": 0, "message": "query success", "data": user_views }
def input(self, name="", pwd="", affirm_pwd="", activate=0, phone="", school_id="", level=1): if pwd != affirm_pwd: raise FormalError(pwd=pwd, affirm_pwd=affirm_pwd) if not convert.is_mobile(phone): raise FormalError(phone=phone) if db_api.user_list(name=name): raise ParamExist(name=name) if db_api.user_list(phone=phone): raise ParamExist(phone=phone) values = { "name": name, "pwd": encry_md5(pwd.strip()), "activate": activate, "phone": phone, "level": level } if school_id: if not db_api.school_get(school_id): raise NotFound(school_id=school_id) values.update({"school_id": school_id}) user_obj = db_api.user_create(values) return user_obj
def auth_phone(self, phone, pwd): user_list = db_api.user_list(phone=phone, pwd=encry_md5(pwd)) if user_list: user_info = self.views(user_list[0]) if user_info.get("school_id", ""): school_info = db_api.school_get(user_info.get("school_id")) user_info.update({"school_name": school_info.name}) user_info.update({"cardcode": school_info.cardcode}) return user_info
def auth_username(self, name, pwd): filters = {"name": name, "pwd": encry_md5(pwd)} user_list = db_api.user_list(**filters) if user_list: user_info = self.views(user_list[0]) if user_info.get("school_id", ""): school_info = db_api.school_get(user_info.get("school_id")) user_info.update({"school_name": school_info.name}) user_info.update({"cardcode": school_info.cardcode}) return user_info
def input(self, name="", school_id=""): # verify school_id if not db_api.school_get(school_id): raise exception.NotFound(school_id=school_id) _count = db_api.class_count(name=name) if _count > 0: raise exception.ParamExist(name=name) values = { "name": name, "school_id": school_id, } grade_obj = db_api.grade_create(values) return grade_obj
def infos_for_sign_day(self, id="", name="", school_id="", grade_id="", class_id="", relative_id="", sign_date="", limit=100, offset=1): offset = (offset - 1) * limit if offset > 0 else 0 filters = dict() if id: filters.update({"id": id}) if name: filters.update({"name": name}) if school_id: filters.update({"school_id": school_id}) if grade_id: filters.update({"grade_id": grade_id}) if class_id: filters.update({"class_id": class_id}) if relative_id: _relation_list = self._get_relations_by_relative(relative_id) if _relation_list: _ids = [_relation.student_id for _relation in _relation_list] filters.update({"id": _ids}) student_list = db_api.student_list(offset=offset, limit=limit, **filters) student_count = db_api.student_count(**filters) # 关联学校和班级,还有学生得签到(学生亲属的签到信息) views_list = self.views(student_list) for view in views_list: school_info = db_api.school_get(id=view.get("school_id")) if school_info: view.update({"school_name": school_info.name}) grade_info = view.get("grade_info", None) if grade_info: view.update({"grade_name": grade_info.get("name")}) class_info = view.get("class_info", None) if class_info: view.update({"class_name": class_info.get("name")}) sign_date = datetime.strptime(sign_date, "%Y-%m-%d") if convert.is_date(sign_date) else date.today() sign_status_list = db_api.student_sign_status_list(sign_date, sign_date, student_id=view.get("id")) if sign_status_list: view.update({ "sign_date": datetime.strftime(sign_date, "%Y-%m-%d"), "morning": sign_status_list[0].morning if sign_status_list[0].morning else "", "afternoon": sign_status_list[0].afternoon if sign_status_list[0].afternoon else "" }) return {"count": student_count, "state": 0, "message": "query success", "data": views_list}
def infos_for_sign_month(self, id="", name="", school_id="", grade_id="", class_id="", relative_id="", sign_date="", limit=100, offset=1): offset = (offset - 1) * limit if offset > 0 else 0 filters = dict() if id: filters.update({"id": id}) if name: filters.update({"name": name}) if school_id: filters.update({"school_id": school_id}) if grade_id: filters.update({"grade_id": grade_id}) if class_id: filters.update({"class_id": class_id}) if relative_id: _relation_list = self._get_relations_by_relative(relative_id) if _relation_list: _ids = [_relation.student_id for _relation in _relation_list] filters.update({"id": _ids}) student_list = db_api.student_list(offset=offset, limit=limit, **filters) student_count = db_api.student_count(**filters) # 关联学校和班级,还有学生得签到(学生亲属的签到信息) views_list = self.views(student_list) for view in views_list: school_info = db_api.school_get(id=view.get("school_id")) if school_info: view.update({"school_name": school_info.name}) grade_info = view.get("grade_info", None) if grade_info: view.update({"grade_name": grade_info.get("name")}) class_info = view.get("class_info", None) if class_info: view.update({"class_name": class_info.get("name")}) sign_count, late_count, early_count, sign_date = self.com_sign(view.get("id"), sign_date) view.update({"sign": sign_count, "late": late_count, "early": early_count, "sign_date": datetime.strftime(sign_date, "%Y-%m")}) return {"count": student_count, "state": 0, "message": "query success", "data": views_list}
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 infos(self, id="", name="", school_id="", school_name="", grade_id="", grade_name="", cardcode="", limit=100, offset=1): offset = (offset - 1) * limit if offset > 0 else 0 filters = dict() if id: filters.update({"id": id}) if name: filters.update({"name": name}) if cardcode: filters.update({"cardcode": cardcode}) if school_id or school_name: if not school_id: _school_list = db_api.school_list(name=school_name) if not _school_list: return {"count": 0, "state": 0, "message": "query success", "data": []} school_id = [school_info.id for school_info in _school_list] filters.update({"school_id": school_id}) if grade_id or grade_name: if not grade_id: _grade_list = db_api.grade_list(name=grade_name) if not _grade_list: return grade_id = [grade_info.id for grade_info in _grade_list] filters.update({"grade_id": grade_id}) class_list = db_api.class_list(offset=offset, limit=limit, **filters) #更新学生数和学校名称 views_list = self.views(class_list) for view in views_list: school_info = db_api.school_get(id=view.get("school_id", "")) if school_info: view.update({"school_name": school_info.name}) grade_info = db_api.grade_get(id=view.get("grade_id", "")) if grade_info: view.update({"grade_name": grade_info.name}) student_count = db_api.student_count(class_id=view.get("id")) view.update({"reality_number": student_count}) class_count = db_api.class_count(**filters) return {"count": class_count, "state": 0, "message": "query success", "data": views_list}
def infos_for_sign(self, id="", name="", school_id="", grade_id="", class_id="", phone="", position=0, sign_date="", limit=100, offset=1): offset = (offset - 1) * limit if offset > 0 else 0 filters = dict() if id: filters.update({"id": id}) if name: filters.update({"name": name}) if position in (1, 2): filters.update({"position": position}) if school_id: filters.update({"school_id": school_id}) if grade_id: filters.update({"grade_id": grade_id}) if class_id: filters.update({"class_id": class_id}) if phone: filters.update({"phone": phone}) # 关联班级名和学校名 teacher_list = db_api.teacher_list(offset=offset, limit=limit, **filters) # 关联学校和班级,还有学生得签到(学生亲属的签到信息) views_list = self.views(teacher_list) for view in views_list: if view.get("school_id", ""): school_info = db_api.school_get(id=view.get("school_id")) if school_info: view.update({"school_name": school_info.name}) if view.get("grade_info", None): grade_info = view.get("grade_info", None) if grade_info: view.update({"grade_name": grade_info.get("name")}) if view.get("class_info", None): class_info = view.get("class_info", None) if class_info: view.update({"class_info": self.views(class_info)}) #history teacher_history_lilst = db_api.teacher_history_list( teacher_id=view.get("id")) if teacher_history_lilst: view.update({"status": teacher_history_lilst[0].status}) sign_count, late_count, early_count, sign_date = self.com_sign( view.get("id"), sign_date) view.update({ "sign": sign_count, "late": late_count, "early": early_count, "sign_date": datetime.datetime.strftime(sign_date, "%Y-%m") }) teacher_count = db_api.teacher_count(**filters) return { "count": teacher_count, "state": 0, "message": "query success", "data": views_list }
def infos(self, id="", name="", school_id="", school_name="", grade_id="", grade_name="", class_id="", class_name="", phone="", status="", position=0, limit=100, offset=1): offset = (offset - 1) * limit if offset > 0 else 0 filters = dict() if id: filters.update({"id": id}) if name: filters.update({"name": name}) if position in (1, 2): filters.update({"position": position}) if status: filters.update({"status": status}) if school_id or school_name: if not school_id: _school_list = db_api.school_list(name=school_name) if not _school_list: return { "count": 0, "state": 0, "message": "query success", "data": [] } school_id = [school_info.id for school_info in _school_list] filters.update({"school_id": school_id}) if grade_id or grade_name: if not grade_id: _grade_list = db_api.grade_list(name=grade_name) if not _grade_list: return { "count": 0, "state": 0, "message": "query success", "data": [] } grade_id = [grade_info.id for grade_info in _grade_list] filters.update({"grade_id": grade_id}) if class_id or class_name: if not class_id: _class_list = db_api.class_list(name=class_name) if not _class_list: return { "count": 0, "state": 0, "message": "query success", "data": [] } class_id = [class_info.id for class_info in _class_list] filters.update({"class_id": class_id}) if phone: filters.update({"phone": phone}) #关联班级名和学校名 teacher_list = db_api.teacher_list(offset=offset, limit=limit, **filters) views_list = self.views(teacher_list) for view in views_list: view.update({"school_name": ""}) if view.get("school_id", ""): school_info = db_api.school_get(id=view.get("school_id")) if school_info: view.update({"school_name": school_info.name}) view.update({"grade_name": ""}) if view.get("grade_id", ""): grade_info = view.get("grade_info", None) # grade_info = db_api.grade_get(id=view.get("grade_id")) if grade_info: view.update({"grade_name": grade_info.get("name")}) view.update({"class_name": ""}) if view.get("class_id", ""): class_info = view.get("class_info", None) # class_info = db_api.class_get(id=view.get("class_id")) if class_info: view.update({"class_info": self.views(class_info)}) view.update({"class_name": class_info.get("name")}) """ #history teacher_history_lilst = db_api.teacher_history_list(teacher_id=view.get("id")) if teacher_history_lilst: view.update({"status": teacher_history_lilst[0].status}) """ teacher_count = db_api.teacher_count(**filters) return { "count": teacher_count, "state": 0, "message": "query success", "data": views_list }
def infos(self, id="", name="", school_id="", school_name="", grade_id="", grade_name="", class_id="", class_name="", relative_id="", relative_name="", phone="", limit=100, offset=1): offset = (offset - 1) * limit if offset > 0 else 0 filters = dict() if id: filters.update({"id": id}) if name: filters.update({"name": name}) if school_id or school_name: if not school_id: _school_list = db_api.school_list(name=school_name) if not _school_list: return {"count": 0, "state": 0, "message": "query success", "data": []} school_id = [school_info.id for school_info in _school_list] filters.update({"school_id": school_id}) if grade_id or grade_name: if not grade_id: _grade_list = db_api.grade_list(name=grade_name) if not _grade_list: return {"count": 0, "state": 0, "message": "query success", "data": []} grade_id = [grade_info.id for grade_info in _grade_list] filters.update({"grade_id": grade_id}) if class_id or class_name: if not class_id: _class_list = db_api.class_list(name=class_name) if not _class_list: return {"count": 0, "state": 0, "message": "query success", "data": []} class_id = [class_info.id for class_info in _class_list] filters.update({"class_id": class_id}) if relative_id or relative_name or phone: _relation_list = self._get_relations_by_relative(relative_id, relative_name, phone) if _relation_list: _ids = [_relation.student_id for _relation in _relation_list] filters.update({"id": _ids}) student_list = db_api.student_list(offset=offset, limit=limit, **filters) #关联学校和班级 views_list = self.views(student_list) for view in views_list: school_info = db_api.school_get(id=view.get("school_id")) if school_info: view.update({"school_name": school_info.name}) grade_info = view.get("grade_info", None) if grade_info: view.update({"grade_name": grade_info.get("name")}) class_info = view.get("class_info", None) if class_info: view.update({"class_name": class_info.get("name")}) relation_list = self._get_relations_by_student(view.get("id")) if relation_list: view.update({"relation_list": relation_list}) student_count = db_api.student_count(**filters) return {"count": student_count, "state": 0, "message": "query success", "data": views_list}