示例#1
0
    def insert_form(cls, data: dict = None):
        if data is None:
            data = dict()
        meta = data.get('meta', {})
        lesson_id = meta.get('lesson', {}).get('lesson_id', None)
        if lesson_id is None:
            raise CustomError(500, 200, '课程不能为空')
        if not FormService.check_lesson_meta(meta):
            raise CustomError(500, 200, '该督导在该时间段, 听过别的课!时间冲突!')
        dao.Form.insert_form(data)

        form_model = dao.Form.formatter_total(data)
        LessonService.refresh_notices(
            data.get("meta", {}).get("lesson", {}).get("lesson_id"))  #刷新听课次数
        ModelLessonService.refresh_vote_nums(
            data.get("meta", {}).get("lesson", {}).get("lesson_id"))  #刷新好评课程次数
        send_kafka_message(topic='form_service',
                           method='add_form',
                           term=meta.get('term', None),
                           bind_meta_name=form_model.get(
                               'bind_meta_name', None),
                           username=meta.get('guider', None),
                           form_id=form_model.get('_id', ''),
                           lesson_id=lesson_id)
        cls.push_new_form_message(form_model)
        return True
示例#2
0
    def update_form(cls, _id=None, data: dict = None):
        if data is None:
            data = dict()
        form = dao.Form.get_form(query_dict={'_id': _id})
        if form is None:
            raise CustomError(404, 404, 'form not found')
        dao.Form.update_form({'_id': _id}, data)
        if 'status' in data:
            form = dao.Form.get_form(query_dict={'_id': _id})
            if form is None:
                raise CustomError(404, 404, 'form not found')
            lesson_id = form.get('meta', {}).get('lesson', {}).get('lesson_id', None)
            if data.get('status') == '待提交':
                send_kafka_message(topic='form_service',
                                   method='repulse_form',
                                   term=form.get('meta', {}).get('term', None),
                                   username=form.get('meta', {}).get('guider', None),
                                   form=form,
                                   lesson_id=lesson_id)
                cls.push_put_back_form_message(form)
            if data.get('status') == '已提交':
                send_kafka_message(topic='form_service',
                                   method='add_form',
                                   lesson_id=lesson_id)

        return True
示例#3
0
    def insert_user(cls,
                    ctx: bool = True,
                    data: dict = None,
                    default_password='******'):
        if data is None:
            data = dict()
        data = cls.reformatter(data)
        username = data.get('username', None)
        if username is None:
            raise CustomError(500, 200, 'username should be given')
        try:
            dao.User.get_user(query_dict={'username': username})
        except CustomError as e:
            if e is not None:
                raise CustomError(500, 200, 'username has been used')
            elif e is not None and e.status_code != 404:
                raise e
        try:
            if data.get('password', None) is None:
                data['password'] = default_password

            role_names = data.get('role_names', [])
            role_name_dict = {
                '管理员': 'is_admin',
                '学院领导': 'is_leader',
                '校级管理员': 'is_reader'
            }
            for role_name in role_names:
                role_name_filed = role_name_dict[role_name]
                data[role_name_filed] = True

            dao.User.insert_user(ctx=ctx, data=data)
            if ctx:
                db.session.commit()
        except Exception as e:
            if ctx:
                db.session.rollback()
            if isinstance(e, CustomError):
                raise e
            else:
                raise CustomError(500, 500, str(e))
        role_names = data.get('role_names', [])
        if '督导' in role_names:
            send_kafka_message(topic='user_service',
                               method='add_supervisor',
                               usernames=[username])
        return True
示例#4
0
 def insert_form(cls, data: dict = None):
     if data is None:
         data = dict()
     meta = data.get('meta', {})
     lesson_id = meta.get('lesson', {}).get('lesson_id', None)
     if lesson_id is None:
         raise CustomError(500, 200, '课程不能为空')
     dao.Form.insert_form(data)
     form_model = dao.Form.formatter_total(data)
     send_kafka_message(topic='form_service',
                        method='add_form',
                        term=meta.get('term', None),
                        username=meta.get('guider', None),
                        form=form_model,
                        lesson_id=lesson_id)
     cls.push_new_form_message(form_model)
     return True