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 _check_student_relative(self, student_relative_info):
        name = student_relative_info.get('name', '')
        birthday = student_relative_info.get('birthday', '')
        class_id = student_relative_info.get('class_id', '')
        relative_list = student_relative_info.get("relative_list", [])

        if birthday and not convert.is_date(birthday):
            return 1, '%s: student info error.'%name
        if not name or not class_id:
            return 1, '%s: student info error.'%name

        relative_op = RelativeLogic()
        for relative_info in relative_list:
            relative_birthday = relative_info.get("birthday", "")
            if relative_birthday and not convert.is_date(convert.bs2utf8(relative_birthday)):
                return 2, '%s: relative info error.' % relative_info.get("name", "")
            phone = convert.bs2utf8(relative_info.get("phone", ""))
            if phone and not convert.is_mobile(phone):
                return 2, '%s: relative info error.' % relative_info.get("name", "")
            name = convert.bs2utf8(relative_info.get("name", ""))
            if not name:
                return 2, '%s: relative info error.' % relative_info.get("name", "")
            if phone:
                db_relative_list = relative_op.info_by_phone(phone=phone)
                if db_relative_list and convert.bs2utf8(db_relative_list[0].get("name", "")) != name:
                    LOG.info("relative info, phone:%s and name:%s error"%(phone, name))
                    return 2, '%s: relative info error.' % relative_info.get("name", "")
        return 0, 'relative ok'
Esempio n. 3
0
 def _get_grade_argument(self):
     name = convert.bs2utf8(self.get_argument('name', ''))
     school_id = convert.bs2utf8(self.get_argument('school_id', ''))
     return {
         "name": name,
         "school_id": school_id,
     }
Esempio n. 4
0
    def _save_student_relative(self, student_relative_info):
        name = student_relative_info.get('name', '')
        sex = student_relative_info.get('sex')
        birthday = student_relative_info.get('birthday', '')
        class_id = student_relative_info.get('class_id', '')
        relation_number = student_relative_info.get("relation_number")
        relative_list = student_relative_info.get("relative_list", [])

        stu_op = StudentLogic()
        relative_op = RelativeLogic()
        relation_op = RelationLogic()
        student_info = stu_op.input(name=name, sex=sex, birthday=birthday, class_id=class_id,
                                    relation_number=relation_number)
        if not student_info:
            #self.finish(json.dumps({'state': 1, 'message': 'student info error'}))
            return 1, '%s:student info error.'%name
        for relative in relative_list:
            relative_info = relative_op.input(
                name=convert.bs2utf8(relative.get("name", "")),
                sex=relative.get("sex", 0),
                birthday=convert.bs2utf8(relative.get("birthday", "")),
                phone=convert.bs2utf8(relative.get("phone", "")))
            if not relative_info:
                #self.finish(json.dumps({'state': 2, 'message': '%s: relative info error' % relative.get("name", "")}))
                return 2, '%s: relative info error.' % relative.get("name", "")
            relation_op.input(relative.get("relation", ""), student_id=student_info.get("id"),
                              relative_id=relative_info.get("id"))
        return 0, 'save student success.'
Esempio n. 5
0
    def batch_student_excel(self):
        school_id = convert.bs2utf8(self.get_argument('school_id', ''))
        class_id = convert.bs2utf8(self.get_argument('class_id', ''))
        student_excels = self.request.files.get('student_excel', '')
        if not school_id or not student_excels:
            LOG.error("teacher or school_id excel is none: %s" % school_id)
            self.finish(json.dumps({'state': 2, 'message': 'excel or school_id is none'}))
            return
        student_excel = student_excels[0]
        filename = student_excel['filename']
        filename = "student" + "." + filename.rpartition(".")[-1]
        file_path = self.static_path + self.excel_path + filename

        with open(file_path, 'wb') as up:
            up.write(student_excel['body'])
        student_data = util_excel.read_student_excel(school_id, class_id, file_path)

        #check info
        error_message = ""
        for student_relative in student_data:
            _ = self._check_student_relative(student_relative)
            if _[0] != 0:
                error_message += _[1]
        if error_message:
            self.finish(json.dumps({'state': 1, 'message': error_message}))
            return

        for student_relative in student_data:
            _ = self._save_student_relative(student_relative)
            if _[0] != 0:
                error_message += _[1]

        # 及时有错误,也把认为批量提交成功,但提供了部分错误信息。
        self.finish(json.dumps({'state': 0, 'message': error_message}))
Esempio n. 6
0
    def student_relative(self):
        name = convert.bs2utf8(self.get_argument('name', ''))
        sex = int(self.get_argument('sex', 0))
        birthday = convert.bs2utf8(self.get_argument('birthday', ''))
        class_id = convert.bs2utf8(self.get_argument('class_id', ''))
        relation_number = int(self.get_argument('relation_number', 3))
        str_relative_list = convert.bs2utf8(self.get_argument('relative_list', '[]'))
        relative_list = json.loads(str_relative_list)

        student_relative_info = {
            "name": name,
            "sex": sex,
            "birthday": birthday,
            "class_id": class_id,
            "relation_number": relation_number,
            "relative_list": relative_list
        }

        #check params
        _check = self._check_student_relative(student_relative_info)
        if _check[0] != 0:
            self.finish(json.dumps({'state': _check[0], 'message': _check[1]}))
            return

        _save = self._save_student_relative(student_relative_info)
        self.finish(json.dumps({'state': _save[0], 'message': _save[1]}))
Esempio n. 7
0
    def reset_pwd(self):
        new_pwd = convert.bs2utf8(self.get_argument('new_pwd', ''))
        affirm_pwd = convert.bs2utf8(self.get_argument('affirm_pwd', ''))
        phone = convert.bs2utf8(self.get_argument('phone', ''))
        verify_code = convert.bs2utf8(self.get_argument('verify_code', ''))

        if not new_pwd or new_pwd != affirm_pwd:
            self.finish(json.dumps({'state': 1, 'message': 'pwd error'}))
            return

        verify_op = VerifyManageLogic()
        # verify code
        _ = verify_op.verify_code_phone(phone=phone, code=verify_code)
        if not _:
            self.finish(
                json.dumps({
                    'state': 2,
                    'message': 'verify code error'
                }))
            return

        user_op = UserLogic()
        _ = user_op.update_pwd_by_phone(phone, new_pwd)
        if _:
            self.finish(
                json.dumps({
                    'state': 0,
                    'message': 'reset pwd success'
                }))
        else:
            self.finish(json.dumps({'state': 3, 'message': 'reset pwd faild'}))
Esempio n. 8
0
    def get(self, user_name, file_type, fn, ref, thumb_fn="", thumb_ref="", text="", *args, **kwargs):
        des = bs2utf8(':'.join([urllib2.quote(bs2utf8(v)) for v in (user_name,  file_type, fn, ref, thumb_fn, thumb_ref,text)]))

        GMQDispRdsInts.send_cmd(*
            shortcut_mq('chat_msg',
                        push_pack(user_name, 'msg', 2, desc=des)
                        )
        )
Esempio n. 9
0
 def _get_student_history_argument(self):
     student_id = convert.bs2utf8(self.get_argument('student_id', ''))
     status = convert.bs2utf8(self.get_argument('status', ''))
     describe = convert.bs2utf8(self.get_argument('describe', ''))
     return {
         "student_id": student_id,
         "status": status,
         "describe": describe
     }
Esempio n. 10
0
 def _get_teacher_history_argument(self):
     teacher_id = convert.bs2utf8(self.get_argument('teacher_id', ''))
     status = convert.bs2utf8(self.get_argument('status', ''))
     describe = convert.bs2utf8(self.get_argument('describe', ''))
     return {
         "teacher_id": teacher_id,
         "status": status,
         "describe": describe
     }
Esempio n. 11
0
 def _get_relation_argument(self):
     relation = convert.bs2utf8(self.get_argument('relation', ''))
     student_id = convert.bs2utf8(self.get_argument('student_id', ''))
     relative_id = convert.bs2utf8(self.get_argument('relative_id', ''))
     return {
         "relation": relation,
         "student_id": student_id,
         "relative_id": relative_id
     }
Esempio n. 12
0
 def _get_grade_argument(self):
     id = convert.bs2utf8(self.get_argument('id', ''))
     name = convert.bs2utf8(self.get_argument('name', ''))
     school_id = convert.bs2utf8(self.get_argument('school_id', ''))
     result = {}
     if name:
         result.update({"name": name})
     if school_id:
         result.update({"school_id": school_id})
     return id, result
Esempio n. 13
0
 def student_sign_details(self):
     student_id = convert.bs2utf8(self.get_argument('student_id', ''))
     start_date = convert.bs2utf8(self.get_argument('start_date', ''))
     end_date = convert.bs2utf8(self.get_argument('end_date', ''))
     student_op = StudentLogic()
     _ = student_op.info_detail_for_sign(student_id, start_date, end_date)
     if _:
         self.finish(json.dumps(_))
     else:
         self.finish(json.dumps({'state': 1, 'message': 'action student_sign_details error'}))
Esempio n. 14
0
 def _get_class_argument(self):
     name = convert.bs2utf8(self.get_argument('name', ''))
     cardcode = convert.bs2utf8(self.get_argument('cardcode', ''))
     grade_id = convert.bs2utf8(self.get_argument('grade_id', ''))
     student_number = int(self.get_argument('study_number', 0))
     return {
         "name": name,
         "cardcode": cardcode,
         "grade_id": grade_id,
         "student_number": student_number
     }
Esempio n. 15
0
def wechat_msg_bcast(author, file_type, fn, ref, thumb_fn="", thumb_ref="", text=""):
    logger.debug('wechat_msg_bcast author={0}, type={1}, fn={2}, ref={3}, thumb_fn={4}, thumb_ref={5}, text={6}'.format(author, file_type, fn, ref, thumb_fn, thumb_ref, text))

    des = bs2utf8(':'.join([urllib2.quote(bs2utf8(v)) for v in (author,  file_type, fn, ref, thumb_fn, thumb_ref, text)]))

    GMQDispRdsInts.send_cmd(
        *shortcut_mq(
            'chat_msg',
            push_pack(author, 'msg', 2, des)
        )
    )
Esempio n. 16
0
    def batch_teacher_excel(self):
        school_id = convert.bs2utf8(self.get_argument('school_id', ''))
        grade_id = convert.bs2utf8(self.get_argument('grade_id', ''))
        status = convert.bs2utf8(self.get_argument('status', ''))
        teacher_op = TeacherLogic()
        _data = teacher_op.infos(school_id=school_id, grade_id=grade_id, status=status,limit=1000)

        _excel = util_excel.make_teacher_excel(_data.get("data", []))
        self.write(_excel)
        self.set_header('Content-Type', 'application/octet-stream')
        self.set_header('Content-Disposition', 'attachment; filename=teacher.xls')
        self.finish()
Esempio n. 17
0
    def post(self, account, pwd, val, *args, **kwargs):
        """
        检查注册验证码
        """
        user_agent = urllib.unquote(bs2utf8(
            self.request.headers['user-agent']))

        reg_ip = bs2utf8(self.request.remote_ip)
        if not is_email(account):
            return {'status': 1}

        mobile = account.partition('@')[0]
        if not is_mobile(mobile):
            return {'status': 2}

        if not is_reg_val_code(val):
            return {'status': 3}

        expect_code = GAccRdsInts.send_cmd(*get_newacc_reg_val(mobile))
        if not expect_code:
            return {'status': 4}
        expect_code = expect_code.split(':')[0]
        if expect_code != val:
            return {'status': 4}

        pwd_mask = cipher_pwd(pwd)
        ok = GAccRdsInts.send_cmd(*set_account_pwd(account, pwd_mask))
        if not ok:
            return {'status': 5}

        reg_ts = time.strftime(fmt, time.gmtime())
        GMQDispRdsInts.send_multi_cmd(*combine_redis_cmds(
            shortcut_mq(
                'gen_mysql',
                mysql_pack(DB_TBL_SSP_USR_LOGIN, {
                    'username': account,
                    'password': pwd_mask,
                    'mobile': mobile,
                }, 0)),
            shortcut_mq(
                'gen_mysql',
                mysql_pack(
                    DB_TBL_SSP_USR_LOGIN,
                    {
                        'username': account,
                        'reg_agent': user_agent,
                        'reg_ts': reg_ts,
                        'reg_ip': reg_ip,
                    },
                    action=0,
                ))))
        return {'status': 0}
Esempio n. 18
0
 def _get_relative_argument(self):
     name = convert.bs2utf8(self.get_argument('name', ''))
     sex = int(self.get_argument('sex', 0))
     birthday = convert.bs2utf8(self.get_argument('birthday', 0))
     phone = convert.bs2utf8(self.get_argument('phone', ''))
     describe = convert.bs2utf8(self.get_argument('describe', ''))
     return {
         "name": name,
         "sex": sex,
         "birthday": birthday,
         "phone": phone,
         "describe": describe,
     }
Esempio n. 19
0
 def _get_school_argument(self):
     id = convert.bs2utf8(self.get_argument('id', ''))
     name = convert.bs2utf8(self.get_argument('name', ''))
     cardcode = convert.bs2utf8(self.get_argument('cardcode', ''))
     describe = convert.bs2utf8(self.get_argument('describe', ''))
     result = {}
     if name:
         result.update({"name": name})
     if cardcode:
         result.update({"cardcode": cardcode})
     if describe:
         result.update({"describe": describe})
     return id, result
Esempio n. 20
0
    def batch_student_excel(self):
        student_id = convert.bs2utf8(self.get_argument('student_id', ''))
        student_name = convert.bs2utf8(self.get_argument('student_name', ''))
        school_id = convert.bs2utf8(self.get_argument('school_id', ''))
        grade_id = convert.bs2utf8(self.get_argument('grade_id', ''))
        class_id = convert.bs2utf8(self.get_argument('class_id', ''))
        student_op = StudentLogic()

        _data = student_op.student_relative_excel(student_id, student_name, school_id, grade_id, class_id)
        _excel = util_excel.make_student_excel(_data)
        self.write(_excel)
        self.set_header('Content-Type', 'application/octet-stream')
        self.set_header('Content-Disposition', 'attachment; filename=student.xls')
        self.finish()
Esempio n. 21
0
    def verify_phone_code(self):
        phone = convert.bs2utf8(self.get_argument('phone', ''))
        verify_code = convert.bs2utf8(self.get_argument('verify_code', ''))
        verify_op = VerifyManageLogic()

        # verify code
        _ = verify_op.verify_code_phone(phone=phone, code=verify_code)
        if not _:
            self.finish(
                json.dumps({
                    'state': 1,
                    'message': 'verify code error'
                }))
        else:
            self.finish(json.dumps({'state': 0, 'message': 'verify code ok'}))
Esempio n. 22
0
def dev_alias(dev_filter, pid, cur_account, alias):
    """
    设置别名
    :param dev_filter:
    :param pid:
    :param cur_account:
    :param alias:
    :return:
    """
    if not (isinstance(cur_account, str) and isinstance(alias, basestring)):
        return

    pid = rawid_tuple(pid, True)
    if not pid or len(alias) > 15 or ':' in alias:
        return

    alias = bs2utf8(alias)
    pid, typ, sn, io = pid
    #子帐号是否关注,主帐号拥有
    is_sub_fo, primary_account = dev_filter.send_multi_cmd(*combine_redis_cmds(
        is_dev_subaccounted(pid, cur_account), test_primary_bound(pid)))

    if not primary_account:
        return
    _, _, primary_account = primary_account.split(':')
    if not (primary_account == cur_account or is_sub_fo):
        return
    dev_filter.send_cmd(*set_alias(pid, cur_account, alias))
    return True
Esempio n. 23
0
def ul_args_ok(redis_cal, tk, src, usage):
    """
    确认参数
    :param redis_cal: redis计算对象
    :param tk:
    :param src:
    :param usage:
    :return:
    """
    tk_params = extract_tk(tk, True)
    if not tk_params:
        logger.warn('extract token fail')
        return None
    file_type = bs2utf8(src)
    if not is_num(file_type):
        logger.warn('src type invalid: {0}'.format(file_type))
        return None
    file_type = int(file_type)
    if file_type not in APP_VALID_SOURCE:
        logger.warn('src unknown: {0}'.format(file_type))
        return None

    share, by_app, pid, fn = tk_params
    unique_sn = 0
    if 0b100 == file_type:
        # 手机到手表,双向语音
        if not USAGE_PATTERN.search(usage):
            return None
        unique_sn = redis_cal.send_cmd(*incre_unique_sn())
        #忽略app的fn参数,重新设置
        fn = '_'.join(('bi', '%x' % unique_sn))

    #重新创建tk_params
    return (share, by_app, pid, fn), file_type, usage, unique_sn
Esempio n. 24
0
    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 _
Esempio n. 25
0
    def post(self, user_name, share_id, *args, **kwargs):
        gid = ''
        sl = share_id.split(':')
        author = ''
        if len(sl) == 4:
            _, _, gid, author = sl
        elif len(sl) == 3:
            _, _, author = sl

        logger.debug(u'delete share, gid={0}, author={1}, acc={2}'.format(
            gid, author, user_name))

        if not self.can_delete(gid, author, user_name):
            return {'status': 1}

        share_info = GDevRdsInts.send_cmd(*retrieve_share_info(share_id))
        if share_info is None:
            return {'status': 2}

        files = share_info.get('files')
        if files:
            fns = json.loads(files)
            logger.debug(
                u'delete share, share_id={0}, gid={1}, fns={2}'.format(
                    share_id, gid, fns))
            for k, v in fns.items():
                urllib2.urlopen(BEIQI_FILE_DELETE_URL.format(file=bs2utf8(v)))

        comment_id_list = GDevRdsInts.send_cmd(*get_comment(share_id))
        if comment_id_list is not None:
            for comment_id in comment_id_list:
                fn = GDevRdsInts.send_cmd(
                    *get_comment_file(share_id, comment_id))
                urllib2.urlopen(BEIQI_FILE_DELETE_URL.format(file=fn))
                GDevRdsInts.send_cmd(*del_comment_info(share_id, comment_id))

        GDevRdsInts.send_multi_cmd(*combine_redis_cmds(
            del_share(user_name, share_id), del_comment(share_id),
            del_share_info(share_id)))

        if gid:
            sn = GDevRdsInts.send_cmd(*get_sn_of_gid(gid))

            accounts = GDevRdsInts.send_cmd(*get_group_followers(gid))
            primary_account = GDevRdsInts.send_cmd(*get_group_primary(gid))
            accounts.add(primary_account)
            accounts.add(sn)

            logger.debug(u'accounts={0}'.format(accounts))
            for user in accounts:
                if user_name == user:
                    continue
                GDevRdsInts.send_cmd(*del_share(user, share_id))
                GMQDispRdsInts.send_cmd(*shortcut_mq(
                    'cloud_push',
                    push_pack(
                        user_name, 'delete_share', 2, share_id, account=user)))

        return {'status': 0}
Esempio n. 26
0
 def update(self, id="", **kwargs):
     if not id or not kwargs:
         return False
     phone = convert.bs2utf8(kwargs.get("phone", ""))
     if phone and not convert.is_mobile(phone):
         raise exception.FormalError(phone=phone)
     _ = db_api.relative_update(id, kwargs)
     return _
Esempio n. 27
0
 def _get_student_argument(self):
     name = convert.bs2utf8(self.get_argument('name', ''))
     sex = int(self.get_argument('sex', 0))
     birthday = convert.bs2utf8(self.get_argument('birthday', ''))
     class_id = convert.bs2utf8(self.get_argument('class_id', ''))
     status = convert.bs2utf8(self.get_argument('status', 'apply'))
     relation_number = int(self.get_argument('relation_number', 3))
     describe = convert.bs2utf8(self.get_argument('describe', ''))
     return {
         "name": name,
         "sex": sex,
         "birthday": birthday,
         "class_id": class_id,
         "status": status,
         "relation_number": relation_number,
         "describe": describe,
     }
Esempio n. 28
0
 def _get_user_argument(self):
     name = convert.bs2utf8(self.get_argument('name', ''))
     pwd = convert.bs2utf8(self.get_argument('pwd', ''))
     affirm_pwd = convert.bs2utf8(self.get_argument('affirm_pwd', ''))
     phone = convert.bs2utf8(self.get_argument('phone', ''))
     level = int(self.get_argument('level', 1))
     school_id = convert.bs2utf8(self.get_argument('school_id', ''))
     activate = 1
     return {
         "name": name,
         "pwd": pwd,
         "affirm_pwd": affirm_pwd,
         "activate": activate,
         "phone": phone,
         "level": level,
         "school_id": school_id,
     }
Esempio n. 29
0
 def _get_teacher_argument(self):
     id = convert.bs2utf8(self.get_argument('id', ''))
     name = convert.bs2utf8(self.get_argument('name', ''))
     sex = int(self.get_argument('sex', -1))
     position = int(self.get_argument('position', 0))
     birthday = convert.bs2utf8(self.get_argument('birthday', ""))
     class_id = convert.bs2utf8(self.get_argument('class_id', ''))
     phone = convert.bs2utf8(self.get_argument('phone', ''))
     status = convert.bs2utf8(self.get_argument('status', ''))
     describe = convert.bs2utf8(self.get_argument('describe', ''))
     result = {}
     if name:
         result.update({"name": name})
     if sex > -1:
         result.update({"sex": sex})
     if position > 0:
         result.update({"position": position})
     if birthday:
         result.update({"birthday": birthday})
     if class_id:
         result.update({"class_id": class_id})
     if phone:
         result.update({"phone": phone})
     if status:
         result.update({"status": status})
     if describe:
         result.update({"describe": describe})
     return id, result
Esempio n. 30
0
    def get(self, user_list, *args, **kwargs):
        user_list = ujson.loads(user_list)

        ret = {}
        for user in user_list:
            user = bs2utf8(user)
            status = GDevRdsInts.send_cmd(*get_mqtt_status(user))
            ret[user] = status
        return ret