예제 #1
0
    def _get_relations_by_relative(self, relative_id="", relative_name="", phone=""):
        if relative_id:
            _relation_list = db_api.relation_list(relative_id=relative_id)
            return _relation_list

        _relative_list = db_api.relative_list(name=relative_name)
        if not _relative_list:
            _relative_list = db_api.relative_list(phone=phone)

        relative_id = [_relative.id for _relative in _relative_list]
        _relation_list = db_api.relation_list(relative_id=relative_id)
        return _relation_list
예제 #2
0
    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
예제 #3
0
    def info_by_phone(self, phone=""):
        if not phone:
            return
        filters = dict()
        if phone:
            filters.update({"phone": phone})

        relative_infos = db_api.relative_list(**filters)
        return relative_infos
예제 #4
0
 def school_id_by_phone(self, phone=""):
     # get first school's id of student
     if not phone:
         return
     relative_infos = db_api.relative_list(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:
         student_info = db_api.student_get(relation_list[0].student_id)
         return student_info.school_id
예제 #5
0
    def input(self,
              relevance_type=1,
              phone="",
              alias="",
              file_path="",
              relevance_file_path=""):
        if relevance_type not in (1, 2, 3):
            return
        if relevance_type in (1, 3):
            #家属签到
            _sign_type = self.sign_type()
            values = {
                "phone": phone,
                "type": _sign_type,
                "alias": alias,
                "img_path": file_path,
                "relative_img_path": relevance_file_path,
            }
            _ = db_api.relative_sign_create(values)
            if _:
                relative_infos = db_api.relative_list(phone=phone)
                relative_ids = [
                    relative_info.id for relative_info in relative_infos
                ]
                relation_infos = db_api.relation_list(relative_id=relative_ids)
                for relation_info in relation_infos:
                    # 一个家属可能多个学生
                    #student_id = self._get_student_id_by_relative(relative_id=relative_id)
                    self.manage_student_sign_status(relation_info.student_id,
                                                    _sign_type)

        if relevance_type == 2:
            # 老师签到
            _sign_type = self.sign_type()
            values = {
                "phone": phone,
                "type": _sign_type,
                "alias": alias,
                "img_path": file_path,
                "teacher_img_path": relevance_file_path,
            }
            _ = db_api.teacher_sign_create(values)
            if _:
                self.manage_teacher_sign_status(phone, _sign_type)

        return True
예제 #6
0
 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
예제 #7
0
    def infos(self,
              id="",
              name="",
              student_id="",
              student_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 student_id or student_name:
            _relation_list = self._get_relations_by_student()
            if _relation_list:
                _ids = [_relation.relative_id for _relation in _relation_list]
                filters.update({"id": _ids})

        if phone:
            filters.update({"phone": phone})

        relative_list = db_api.relative_list(offset=offset,
                                             limit=limit,
                                             **filters)
        views_list = self.views(relative_list)

        relative_count = db_api.relative_count(**filters)
        return {
            "count": relative_count,
            "state": 0,
            "message": "query success",
            "data": views_list
        }