Exemple #1
0
    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 _
Exemple #2
0
    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, 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 infos(self, id="", teacher_id="", teacher_name="", status="", limit=100, offset=1):
        offset = (offset-1)*limit if offset > 0 else 0
        filters = dict()
        if id:
            filters.update({"id": id})
        if teacher_id or teacher_name:
            if not teacher_id:
                _teacher_list = db_api.teacher_list(name=teacher_name)
                if _teacher_list:
                    teacher_id = [teacher_info.id for teacher_info in _teacher_list]
            filters.update({"teacher_id": teacher_id})
        if status:
            filters.update({"status": status})

        history_list = db_api.teacher_history_list(offset=offset, limit=limit, **filters)
        views_list = self.views(history_list)
        for view in views_list:
            teacher_info = db_api.teacher_get(id=view.get("teacher_id"))
            if teacher_info:
                view.update({"teacher_name": teacher_info.name})
        history_count = db_api.teacher_history_count(**filters)
        return {"count": history_count, "state": 0, "message": "query success", "data": views_list}
Exemple #5
0
 def info(self, id=""):
     teacher_info = db_api.teacher_get(id)
     return self.views(teacher_info)