Example #1
0
 def delete(self, id="", **kwargs):
     if not id:
         return "id is none"
     relevance_student_count = db_api.student_count(class_id=id)
     if relevance_student_count > 0:
         return "exist student"
     relevance_teacher_count = db_api.teacher_count(class_id=id)
     if relevance_teacher_count > 0:
         return "exist teacher"
     db_api.class_deleted(id=id)
Example #2
0
    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}
Example #3
0
    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}
Example #4
0
    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}
Example #5
0
    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}