Exemplo n.º 1
0
class SignView(CVAdminModelView):
    can_create = False
    can_edit = False
    can_delete = False
    page_size = 100
    column_filters = ('target', 'member_id', 'member_name', 'date')
    column_list = ('botid', 'target', 'member', 'date', 'time', 'message')
    column_searchable_list = ('member_name', )
    column_labels = dict(botid='机器人',
                         target='目标',
                         member='成员',
                         member_id='成员账号',
                         member_name='成员名称',
                         date='日期',
                         time='时间',
                         message='消息')
    column_formatters = dict(
        botid=lambda v, c, m, p: get_botname(m.botid),
        target=lambda v, c, m, p: get_target_display(m.target),
        member=lambda v, c, m, p: get_CQ_display(m.member_id + ' : ' + m.
                                                 member_name),
        message=lambda v, c, m, p: get_CQ_display(m.message),
        date=lambda v, c, m, p: display_datetime(m.create_at, False),
        time=lambda v, c, m, p: m.time.strftime('%H:%M'))

    column_default_sort = ('id', True)

    def __init__(self, model, session):
        CVAdminModelView.__init__(self, model, session, '签到记录', '消息管理')

    def get_query(self):
        return get_list_by_botassign(Sign, SignView, self)

    def get_count_query(self):
        return get_list_count_by_botassign(Sign, SignView, self)
Exemplo n.º 2
0
class PointConfirmView(CVAdminModelView):
    can_create = False
    can_edit = False
    can_delete = True
    page_size = 100
    column_filters = ('target', 'expire_at')
    column_list = (
        'botid', 'target', 'point', 'confirm_code', 'expire_at')
    column_searchable_list = ('confirm_code',)
    column_labels = dict(botid = '机器人', target = '目标',
                         point = '报点记录', confirm_code = '确认码', expire_at = '过期时间')
    column_formatters = dict(botid = lambda v, c, m, p: get_botname(m.botid),
                             target = lambda v, c, m, p: get_target_display(m.target),
                             point = lambda v, c, m, p: m.point_id,
                             expire_at = lambda v, c, m, p: display_datetime(m.expire_at))

    column_default_sort = ('id', True)

    def __init__(self, model, session):
        CVAdminModelView.__init__(self, model, session, '待确认队列', '报点管理')

    def get_query(self):
        return get_list_by_botassign(PointConfirm, PointConfirmView, self)

    def get_count_query(self):
        return get_list_count_by_botassign(PointConfirm, PointConfirmView, self)
Exemplo n.º 3
0
class PointView(CVAdminModelView):
    can_create = False
    can_edit = False
    can_delete = False
    page_size = 100
    column_filters = ('target', 'member_id', 'member_name', 'reporter_id', 'reporter_name', 'has_confirmed', 'date')
    column_list = (
        'botid', 'target', 'member', 'reporter', 'point', 'confirm_code', 'has_confirmed',
        'date', 'time', 'update_at', 'message')
    column_searchable_list = ('member_name', 'reporter_name')
    column_labels = dict(botid = '机器人', target = '目标',
                         member = '成员', reporter = '报点人',
                         point = '点数', confirm_code = '确认码', has_confirmed = '已经确认',
                         date = '日期', time = '时间', create_at = '创建时间', update_at = '更新时间',
                         message = '消息')
    column_formatters = dict(botid = lambda v, c, m, p: get_botname(m.botid),
                             target = lambda v, c, m, p: get_target_display(m.target),
                             member = lambda v, c, m, p: get_CQ_display(m.member_id + ' : ' + m.member_name),
                             reporter = lambda v, c, m, p: get_CQ_display(m.reporter_id + ' : ' + m.reporter_name),
                             has_confirmed = lambda v, c, m, p: get_yesno_display(m.has_confirmed),
                             date = lambda v, c, m, p: display_datetime(m.create_at, False),
                             time = lambda v, c, m, p: m.time.strftime('%H:%M'),
                             update_at = lambda v, c, m, p: display_datetime(m.update_at),
                             message = lambda v, c, m, p: get_CQ_display(m.message))

    column_default_sort = ('id', True)

    def __init__(self, model, session):
        CVAdminModelView.__init__(self, model, session, '报点记录', '报点管理')

    def get_query(self):
        return get_list_by_botassign(Point, PointView, self)

    def get_count_query(self):
        return get_list_count_by_botassign(Point, PointView, self)
Exemplo n.º 4
0
class ScoreRecordView(CVAdminModelView):
    can_create = False
    can_edit = False
    can_delete = False
    page_size = 100
    column_filters = ('account', 'trans_type', 'member_id', 'amount',
                      'biz_type', 'date')
    column_list = ('account', 'biz_type', 'trans_type', 'member', 'before',
                   'amount', 'after', 'date', 'time', 'remark')
    column_searchable_list = ('member_name', 'remark')
    column_labels = dict(account='账户名',
                         biz_type='来源类型',
                         trans_type='交易类型',
                         member='成员',
                         member_id='成员账号',
                         member_name='成员名称',
                         amount='交易数量',
                         before='交易前余额',
                         after='交易后余额',
                         date='日期',
                         time='时间',
                         remark='备注')

    column_formatters = dict(
        target=lambda v, c, m, p: get_target_display(m.target),
        biz_type=lambda v, c, m, p: ScoreRule.get_rule(m.account, m.biz_type
                                                       ).description,
        trans_type=lambda v, c, m, p: get_transtype_display(
            m.trans_type, m.amount < 0),
        member=lambda v, c, m, p: get_CQ_display(m.member_id + ' : ' + m.
                                                 member_name),
        amount=lambda v, c, m, p: abs(m.amount),
        date=lambda v, c, m, p: display_datetime(m.create_at, False),
        time=lambda v, c, m, p: m.time.strftime('%H:%M'))

    column_default_sort = ('id', True)

    def __init__(self, model, session):
        CVAdminModelView.__init__(self, model, session, '积分记录', '积分管理')

    def get_query(self):
        return get_list_by_scoreaccount(ScoreRecord, ScoreRecordView, self)

    def get_count_query(self):
        return get_list_count_by_scoreaccount(ScoreRecord, ScoreRecordView,
                                              self)
Exemplo n.º 5
0
class TargetRuleView(CVAdminModelView):
    __type_list = {'allow': '允许', 'block': '拒绝'}

    can_create = True
    can_edit = True
    can_delete = True

    column_filters = ('type', )
    column_labels = dict(id='ID',
                         botid='机器人',
                         type='类型',
                         target='目标',
                         create_at='创建时间',
                         update_at='更新时间',
                         remark='备注')
    column_formatters = dict(
        create_at=lambda v, c, m, p: display_datetime(m.create_at),
        update_at=lambda v, c, m, p: display_datetime(m.update_at),
        type=lambda v, c, m, p: v.__type_list[m.type],
        target=lambda v, c, m, p: get_target_display(m.target),
        botid=lambda v, c, m, p: get_botname(m.botid))

    form_create_rules = (
        rules.FieldSet(('botid', 'type', 'remark'), '基本信息'),
        rules.FieldSet(('target_type', 'target_account'), '目标设置'),
    )
    form_edit_rules = (
        rules.FieldSet(('botid', 'type', 'remark'), '基本信息'),
        rules.FieldSet(('target_type', 'target_account'), '目标设置'),
    )

    def __init__(self, model, session):
        CVAdminModelView.__init__(self, model, session, '目标规则设置', '机器人设置')

    def get_query(self):
        return get_list_by_botassign(TargetRule, TargetRuleView, self)

    def get_count_query(self):
        return get_list_count_by_botassign(TargetRule, TargetRuleView, self)

    def get_create_form(self):
        form = self.scaffold_form()
        delattr(form, 'target')
        form.target_type = fields.SelectField('目标类型',
                                              coerce=str,
                                              choices=get_target_type_choice(),
                                              widget=Select2Widget())
        form.target_account = fields.StringField(
            '目标账号', [validators.required(message='目标账号是必填字段')])
        form.type = fields.SelectField(
            '类型', [validators.required(message='类型是必填字段')],
            coerce=str,
            choices=self.__type_list.items(),
            widget=Select2Widget())

        def query_factory():
            from flask_login import current_user
            from common.bot import BotAssign
            return [
                r.botid for r in BotAssign.find_by_user(current_user.username)
            ]

        def get_pk(obj):
            return obj

        def get_label(obj):
            return Bot.find(obj).name

        from wtforms.ext.sqlalchemy.fields import QuerySelectField
        form.botid = QuerySelectField(
            '机器人', [validators.required(message='机器人是必填字段')],
            query_factory=query_factory,
            get_label=get_label,
            get_pk=get_pk,
            widget=Select2Widget())
        return form

    def get_edit_form(self):
        form = self.scaffold_form()
        # delattr(form, 'target')
        form.target_type = fields.SelectField(
            '目标类型', [validators.required(message='目标类型是必填字段')],
            coerce=str,
            choices=get_target_type_choice(),
            widget=Select2Widget())
        form.target_account = fields.StringField(
            '目标账号', [validators.required(message='目标账号是必填字段')])
        form.type = fields.SelectField(
            '类型', [validators.required(message='类型是必填字段')],
            coerce=str,
            choices=self.__type_list.items(),
            widget=Select2Widget())
        form.botid = fields.StringField('机器人ID', render_kw={'readonly': True})

        def query_factory():
            return self.model.find_by_id()

        return form

    def on_model_change(self, form, model, is_created):
        model.target = get_target_composevalue(form.target_type.data,
                                               form.target_account.data)

    def on_form_prefill(self, form, id):
        # form.botid.label =  Bot.find(form.botid.data).name
        target = self.model.find_by_id(id).target
        form.target_account.data = target.replace(target[0:2], '')
Exemplo n.º 6
0
 def on_form_prefill(self, form, id):
     form.botid.data = Bot.find(form.botid.data).name
     form.target.data = get_target_display(form.target.data)
Exemplo n.º 7
0
 def target_get_label(obj):
     return get_target_display(obj.split('|')[1])
Exemplo n.º 8
0
class ScoreAccountView(CVAdminModelView):
    can_create = True
    can_edit = True
    can_delete = True
    page_size = 100
    column_filters = (
        'target',
        # 'type',
        'is_default',
        'income',
        'outgo',
        'balance')
    column_list = (
        'botid',
        'name',
        'description',
        # 'type',
        'is_default',
        'target',
        'income',
        'outgo',
        'balance',
        'create_at',
        'update_at',
        'remark')
    column_searchable_list = ('name', 'description', 'remark')
    column_labels = dict(
        botid='机器人',
        name='账户名',
        description='账户描述',
        # type = '账户类型',
        is_default='缺省账户',
        target='目标',
        income='总收入',
        outgo='总支出',
        balance='余额',
        create_at='创建时间',
        update_at='更新时间',
        remark='备注')
    column_formatters = dict(
        botid=lambda v, c, m, p: get_botname(m.botid),
        target=lambda v, c, m, p: get_target_display(m.target),
        create_at=lambda v, c, m, p: display_datetime(m.create_at),
        update_at=lambda v, c, m, p: display_datetime(m.update_at),
        # type = lambda v, c, m, p: get_acttype_display(m.type),
        is_default=lambda v, c, m, p: get_yesno_display(m.is_default))
    form_columns = (
        'botid',
        'name',
        'description',
        # 'type',
        'is_default',
        'target',
        'remark')
    form_create_rules = (
        rules.FieldSet(('botid', 'target'), '目标设置'),
        rules.FieldSet(('name', 'description', 'remark'), '基本信息'),
        rules.FieldSet(
            (
                # 'type',
                'is_default', ),
            '其他选项'))
    form_edit_rules = (
        rules.FieldSet(('botid', 'target'), '目标设置'),
        rules.FieldSet(('name', 'description', 'remark'), '基本信息'),
        rules.FieldSet(
            (
                # 'type',
                'is_default', ),
            '其他选项'))

    # form_choices = {'is_default': get_yesno_choice(),
    #                 'type': get_acttype_choice()}

    def __init__(self, model, session):
        CVAdminModelView.__init__(self, model, session, '积分账户设置', '机器人设置')

    def get_query(self):
        return get_list_by_botassign(ScoreAccount, ScoreAccountView, self)

    def get_count_query(self):
        return get_list_count_by_botassign(ScoreAccount, ScoreAccountView,
                                           self)

    def get_create_form(self):
        form = self.scaffold_form()
        # delattr(form, 'target')
        # form.target_type = fields.SelectField('目标类型', coerce = str, choices = get_target_type_choice())
        # form.target_account = fields.StringField('目标账号', [validators.required(message = '目标账号是必填字段')])
        form.type = fields.SelectField('类型',
                                       coerce=str,
                                       choices=get_acttype_choice(),
                                       widget=Select2Widget())
        form.is_default = fields.BooleanField('缺省账户')

        def bot_query_factory():
            from flask_login import current_user
            from common.bot import BotAssign
            return [
                r.botid for r in BotAssign.find_by_user(current_user.username)
            ]

        def bot_get_pk(obj):
            return obj

        def bot_get_label(obj):
            from common.bot import Bot
            return Bot.find(obj).name

        from wtforms.ext.sqlalchemy.fields import QuerySelectField
        form.botid = QuerySelectField(
            '机器人', [validators.required(message='机器人是必填字段')],
            query_factory=bot_query_factory,
            get_label=bot_get_label,
            get_pk=bot_get_pk,
            widget=Select2Widget())

        def target_query_factory():
            from flask_login import current_user
            from plugins.setting import TargetRule
            return [
                r.botid + '|' + r.target
                for r in TargetRule.find_allow_by_user(current_user.username)
            ]

        def target_get_pk(obj):
            return obj

        def target_get_label(obj):
            return get_target_display(obj.split('|')[1])

        from wtforms.ext.sqlalchemy.fields import QuerySelectField
        form.target = QuerySelectField(
            '目标', [validators.required(message='目标是必填字段')],
            query_factory=target_query_factory,
            get_label=target_get_label,
            get_pk=target_get_pk,
            widget=Select2Widget())
        return form

    def get_edit_form(self):
        form = self.scaffold_form()
        form.botid = fields.StringField('机器人', render_kw={'readonly': True})
        form.target = fields.StringField('目标', render_kw={'readonly': True})
        form.name = fields.StringField('账户名', render_kw={'readonly': True})
        form.type = fields.SelectField('类型',
                                       coerce=str,
                                       choices=get_acttype_choice(),
                                       widget=Select2Widget())
        form.is_default = fields.BooleanField('缺省账户')

        return form

    def on_model_change(self, form, model, is_created):
        if is_created:
            model.target = form.target.data.split('|')[1]
        else:
            model.botid = Bot.find_by_name(model.botid).id
            model.target = recover_target_value(model.target)

    def on_form_prefill(self, form, id):
        form.botid.data = Bot.find(form.botid.data).name
        form.target.data = get_target_display(form.target.data)