Esempio n. 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 _
Esempio n. 2
0
 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
Esempio n. 3
0
    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
Esempio n. 4
0
 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 _
Esempio n. 5
0
    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 _