Esempio n. 1
0
    class Form(BaseComponentForm):
        bk_biz_id = forms.IntegerField(label='business id', required=False)
        ip = TypeCheckField(label='ip', promise_type=dict, required=False)
        condition = TypeCheckField(label='condition', promise_type=list, required=False)
        page = TypeCheckField(label='page', promise_type=dict, required=False)
        pattern = forms.CharField(label='pattern', required=False)

        def clean(self):
            return self.get_cleaned_data_when_exist()
Esempio n. 2
0
    class Form(BaseComponentForm):
        bk_supplier_account = forms.CharField(label='bk supplier account', required=False)
        fields = TypeCheckField(label='fields', promise_type=list, required=False)
        condition = TypeCheckField(label='condition', promise_type=dict, required=False)
        page = TypeCheckField(label='page', promise_type=dict, required=False)

        def clean(self):
            data = self.get_cleaned_data_when_exist(keys=['bk_supplier_account'])
            data.setdefault('bk_supplier_account', configs.DEFAULT_BK_SUPPLIER_ACCOUNT)
            data['data'] = self.get_cleaned_data_when_exist(keys=['fields', 'condition', 'page'])
            return data
Esempio n. 3
0
    class Form(BaseComponentForm):
        app_id = forms.CharField(label='business ID', required=True)
        host_ids = TypeCheckField(label='host IDs', promise_type=list, required=True)
        property = TypeCheckField(label='custom property', promise_type=dict, required=True)

        def clean(self):
            data = self.cleaned_data
            return {
                'ApplicationID': data['app_id'],
                'HostID': ','.join(data['host_ids']),
                'Property': json.dumps(data['property'])
            }
Esempio n. 4
0
    class Form(BaseComponentForm):
        sdk_app_id = forms.CharField(label='tencent cloud sdkappid',
                                     required=True)
        app_key = forms.CharField(label='tencent cloud appkey', required=True)
        sign = forms.CharField(label='sms signature', required=False)
        tpl_id = forms.IntegerField(label='template id', required=True)
        params = TypeCheckField(label='template params',
                                promise_type=list,
                                required=False)
        nation_code = forms.CharField(label='nation code', required=False)
        phone_numbers = ListField(label='phone numbers', required=True)
        extend = forms.CharField(label='extend', required=False)
        ext = forms.CharField(label='ext', required=False)

        def clean(self):
            data = self.cleaned_data
            nation_code = data['nation_code'] or configs.default_nation_code
            new_data = {
                'tel': [{
                    'nationcode': nation_code,
                    'mobile': phone_number
                } for phone_number in data['phone_numbers']],
                'sign':
                data['sign'],
                'tpl_id':
                data['tpl_id'],
                'params':
                data['params'],
                'extend':
                data['extend'],
                'ext':
                data['ext'],
            }
            return new_data
Esempio n. 5
0
    class Form(BaseComponentForm):
        receiver = ListField(label='wechat receiver', required=False)
        receiver__username = ListField(label='wechat receiver', required=False)
        data = TypeCheckField(label='message data',
                              promise_type=dict,
                              required=True)

        def clean(self):
            data = self.cleaned_data

            if not (data['receiver'] or data['receiver__username']):
                raise forms.ValidationError(
                    'WeChat receiver [receiver, receiver__username] shall not be empty at the same time'
                )
            if data['receiver']:
                data['receiver__username'] = None

            return {
                'receiver':
                data['receiver'],
                'receiver__username':
                data['receiver__username'],
                'data':
                SendWeixin.DataForm(data['data']).get_cleaned_data_or_error(),
            }
Esempio n. 6
0
    class Form(BaseComponentForm):
        bk_biz_id = forms.CharField(label='Business ID', required=True)
        ip_list = TypeCheckField(label='Host IP address', promise_type=list, required=False)

        # The data returned in clean method is available through the component's form_data property
        def clean(self):
            return self.get_cleaned_data_when_exist(keys=['bk_biz_id', 'ip_list'])
Esempio n. 7
0
    class Form(BaseComponentForm):
        qcloud_app_id = forms.CharField(label='qcloud app id', required=True)
        qcloud_app_key = forms.CharField(label='qcloud app key', required=True)
        auto_read_message = forms.CharField(label='auto voice reading info',
                                            required=True)
        user_list_information = TypeCheckField(label='user list',
                                               promise_type=list,
                                               required=True)
        ext = forms.CharField(label='ext', required=False)

        def kwargs_generator(self, data):
            for user in data['user_list_information']:
                yield {
                    "user": user,
                    "promptfile": data['auto_read_message'],
                    "playtimes": configs.voice_playtimes,
                    "prompttype": configs.voice_prompttype,
                    "tel": {
                        "mobile": user['mobile_phone'],
                        "nationcode": configs.default_nation_code
                    },
                    "ext": data['ext']
                }

        def clean(self):
            data = self.cleaned_data
            return {
                "kwargs_generator": self.kwargs_generator(data),
                "qcloud_app_id": data["qcloud_app_id"],
                "qcloud_app_key": data["qcloud_app_key"]
            }
Esempio n. 8
0
    class Form(BaseComponentForm):
        sdk_app_id = forms.CharField(label=u'腾讯云sdkappid', required=True)
        app_key = forms.CharField(label=u'腾讯云appkey', required=True)
        sign = forms.CharField(label=u'短信签名', required=False)
        tpl_id = forms.IntegerField(label=u'短信模版ID', required=True)
        params = TypeCheckField(label=u'模版参数', promise_type=list, required=False)
        nation_code = forms.CharField(label=u'国家码', required=False)
        phone_numbers = ListField(label=u'不带国家码的手机号', required=True)
        extend = forms.CharField(label=u'通道扩展码', required=False)
        ext = forms.CharField(label=u'服务端原样返回的参数', required=False)

        def clean(self):
            data = self.cleaned_data
            nation_code = data['nation_code'] or configs.default_nation_code
            new_data = {
                'tel': [
                    {'nationcode': nation_code, 'mobile': phone_number}
                    for phone_number in data['phone_numbers']
                ],
                'sign': data['sign'],
                'tpl_id': data['tpl_id'],
                'params': data['params'],
                'extend': data['extend'],
                'ext': data['ext'],
            }
            return new_data
Esempio n. 9
0
    class Form(BaseComponentForm):
        msg_type = forms.CharField(label='msg type', required=True)
        receiver__username = ListField(label='recipients', required=True)
        sender = forms.CharField(label='mail sender', required=False)
        cc__username = ListField(label='CC', required=False)
        title = forms.CharField(label='subject', required=True)
        content = forms.CharField(label='content', required=True)
        body_format = forms.CharField(label='email format', required=False)
        attachments = TypeCheckField(label='attachments', promise_type=list, required=False)
        date = forms.CharField(label='notification sending time', required=False)
        remark = forms.CharField(label='notification tail text', required=False)
        wx_qy_agentid = forms.CharField(label='enterprise wechat agentid', required=False)
        wx_qy_corpsecret = forms.CharField(label='enterprise wechat corpsecret', required=False)
        is_content_base64 = DefaultBooleanField(
            label='content is encoded by base64 or not', default=False, required=False)

        def clean(self):
            data = self.cleaned_data
            if data['msg_type'] == "voice":
                data['auto_read_message'] = data['content']

            if data['msg_type'] == "weixin":
                data['data'] = {
                    'heading': data['title'],
                    'message': data['content'],
                    'date': data['date'],
                    'remark': data['remark'],
                    'is_message_base64': data['is_content_base64']
                }

            return data
Esempio n. 10
0
    class Form(BaseComponentForm):
        app_id = forms.CharField(label='business ID', required=True)
        set_ids = TypeCheckField(label='set IDs',
                                 promise_type=list,
                                 required=True)
        set_name = forms.CharField(label='set name', required=False)
        chn_name = forms.CharField(label='chinese name', required=False)
        group_flag = forms.CharField(label='group flag', required=False)
        env_type = forms.IntegerField(label='environment type', required=False)
        service_status = forms.IntegerField(label='service status',
                                            required=False)
        capacity = forms.IntegerField(label='capacity', required=False)
        des = forms.CharField(label='description', required=False)

        def clean(self):
            data = self.cleaned_data
            ret_data = {
                'ApplicationID': data['app_id'],
                'SetID': ','.join(data['set_ids']),
                'SetName': data['set_name'],
                'ChnName': data.get('chn_name'),
                'GroupFlag': data.get('group_flag'),
                'SetEnviType': data.get('env_type'),
                'ServiceStatus': data.get('service_status'),
                'Capacity': data.get('capacity'),
                'Des': data.get('des')
            }
            return {
                key: val
                for key, val in ret_data.iteritems() if val or val == 0
            }
Esempio n. 11
0
 class Form(BaseComponentForm):
     appid = forms.CharField(label='wechat appid', required=True)
     secret = forms.CharField(label='wechat app secret', required=True)
     touser = ListField(label='touser', required=True)
     template_id = forms.CharField(label='template ID', required=True)
     data = TypeCheckField(label='message data',
                           promise_type=dict,
                           required=False)
Esempio n. 12
0
    class Form(BaseComponentForm):
        bk_host_id = ListField(label='host ids', required=True)
        data = TypeCheckField(label='data', promise_type=dict, required=False)

        def clean(self):
            data = self.cleaned_data
            data['data'].update(bk_host_id=','.join(map(str, data['bk_host_id'])))
            return data['data']
Esempio n. 13
0
    class Form(BaseComponentForm):
        bk_supplier_account = forms.CharField(label='bk supplier account',
                                              required=False)
        host_info = TypeCheckField(label='host info', required=True)
        bk_biz_id = forms.IntegerField(label='business ID', required=False)

        def clean(self):
            return self.get_cleaned_data_when_exist()
Esempio n. 14
0
    class Form(BaseComponentForm):
        app_id = forms.IntegerField(label='business ID', required=True)
        host_id = forms.IntegerField(label='host ID', required=True)
        std_property = TypeCheckField(label='standard property',
                                      promise_type=dict,
                                      required=False)
        cus_property = TypeCheckField(label='custom property',
                                      promise_type=dict,
                                      required=False)

        def clean(self):
            data = self.cleaned_data
            return {
                'ApplicationID': data['app_id'],
                'HostID': data['host_id'],
                'stdProperty': json.dumps(data['std_property']),
                'cusProperty': json.dumps(data['cus_property']),
            }
Esempio n. 15
0
    class Form(BaseComponentForm):
        bk_supplier_account = forms.CharField(label='bk supplier account', required=False)
        bk_biz_id = forms.IntegerField(label='business id', required=True)
        data = TypeCheckField(label='data', promise_type=dict, required=False)

        def clean(self):
            data = self.get_cleaned_data_when_exist()
            data.setdefault('bk_supplier_account', configs.DEFAULT_BK_SUPPLIER_ACCOUNT)
            return data
Esempio n. 16
0
    class Form(BaseComponentForm):
        bk_biz_id = forms.CharField(label=u'业务ID', required=True)
        ip_list = TypeCheckField(label=u'主机IP地址',
                                 promise_type=list,
                                 required=False)

        # clean方法返回的数据可通过组件的form_data属性获取
        def clean(self):
            return self.get_cleaned_data_when_exist(
                keys=['bk_biz_id', 'ip_list'])
Esempio n. 17
0
    class Form(BaseComponentForm):
        app_id = forms.CharField(label='business ID', required=True)
        set_ids = TypeCheckField(label='set IDs', promise_type=list, required=True)

        def clean(self):
            data = self.cleaned_data
            return {
                'ApplicationID': data['app_id'],
                'SetID': ','.join(data['set_ids'])
            }
Esempio n. 18
0
    class Form(BaseComponentForm):
        receiver = ListField(label='wechat receiver', required=True)
        data = TypeCheckField(label='message data',
                              promise_type=dict,
                              required=True)

        def clean(self):
            data = self.cleaned_data
            return {
                'touser':
                data['receiver'],
                'data':
                SendMpWeixin.DataForm(
                    data['data']).get_cleaned_data_or_error(),
            }
Esempio n. 19
0
    class Form(BaseComponentForm):
        bk_biz_id = forms.IntegerField(label='business id', required=True)
        condition = TypeCheckField(label='condition', promise_type=dict, required=True)
        start = forms.IntegerField(label='start', required=True)
        limit = forms.IntegerField(label='limit', required=True)

        def clean(self):
            data = self.cleaned_data
            return {
                'bk_biz_id': data['bk_biz_id'],
                'data': {
                    'condition': data['condition'],
                    'start': data['start'],
                    'limit': data['limit']
                }
            }
Esempio n. 20
0
    class Form(BaseComponentForm):
        auto_read_message = forms.CharField(label='auto voice reading info', required=True)
        user_list_information = TypeCheckField(label='user list', promise_type=list, required=False)
        receiver__username = ListField(label='BlueKing user list', required=False)

        def clean(self):
            data = self.cleaned_data
            user_list_information = [
                SendVoiceMsg.UserListInfoForm(user_info).get_cleaned_data_or_error()
                for user_info in data['user_list_information']
                if user_info
            ]
            if not (data.get('receiver__username') or user_list_information):
                raise forms.ValidationError(
                    'The parameters [user_list_information and receiver__username] shall not be empty at the same time')
            data['user_list_information'] = user_list_information
            if user_list_information:
                data['receiver__username'] = None
            return data
Esempio n. 21
0
    class Form(BaseComponentForm):
        app_id = forms.IntegerField(label='business ID', required=True)
        set_id = forms.IntegerField(label='set ID', required=True)
        module_name = ListField(label='module name', required=False)
        operator = forms.CharField(label='operator', required=False)
        bak_operator = forms.CharField(label='backup operator', required=False)
        module_type = forms.IntegerField(label='module type', required=False)
        properties = TypeCheckField(label='module properties', promise_type=dict, required=False)

        def clean(self):
            data = self.cleaned_data
            return {
                'ApplicationID': data['app_id'],
                'SetID': data['set_id'],
                'ModuleName': ','.join(data['module_name']),
                'Operator': data['operator'],
                'BakOperator': data['bak_operator'],
                'ModuleType': data['module_type'],
                'properties': json.dumps(data['properties']),
            }
Esempio n. 22
0
    class Form(BaseComponentForm):
        auto_read_message = forms.CharField(label=u'自动语音读字信息', required=True)
        user_list_information = TypeCheckField(label=u'用户列表',
                                               promise_type=list,
                                               required=False)
        receiver__username = ListField(label=u'蓝鲸用户列表', required=False)

        def clean(self):
            data = self.cleaned_data
            user_list_information = [
                NocNotice.UserListInfoForm(
                    user_info).get_cleaned_data_or_error()
                for user_info in data['user_list_information'] if user_info
            ]
            if not (data.get('receiver__username') or user_list_information):
                raise forms.ValidationError(
                    u'参数[user_list_information、receiver__username]不能同时为空')
            data['user_list_information'] = user_list_information
            if user_list_information:
                data['receiver__username'] = None
            return data
Esempio n. 23
0
    class Form(BaseComponentForm):
        app_id = forms.IntegerField(label='business ID', required=True)
        plat_id = forms.IntegerField(label='subnet ID', required=True)
        proxy_list = TypeCheckField(label='Proxy info',
                                    promise_type=list,
                                    required=True)

        def clean(self):
            data = self.cleaned_data
            return {
                'appId':
                data['app_id'],
                'platId':
                data['plat_id'],
                'proxyList':
                json.dumps([
                    UpdateHostByAppId.ProxyForm(
                        host).get_cleaned_data_or_error()
                    for host in data['proxy_list']
                ]),
            }
Esempio n. 24
0
    class Form(BaseComponentForm):
        sender = forms.CharField(label='sender', required=False)
        receiver = ListField(label='email recipients', required=False)
        receiver__username = ListField(label='email recipients',
                                       required=False)
        cc = ListField(label='CC', required=False)
        cc__username = ListField(label='CC', required=False)
        title = forms.CharField(label='email subject', required=True)
        content = forms.CharField(label='email content', required=True)
        is_content_base64 = DefaultBooleanField(
            label='content is encoded by base64 or not',
            default=False,
            required=False)
        body_format = forms.CharField(label='email format', required=False)
        attachments = TypeCheckField(label='attachments',
                                     promise_type=list,
                                     required=False)

        def clean(self):
            data = self.cleaned_data
            if not (data['receiver'] or data['receiver__username']):
                raise forms.ValidationError(
                    'Receiver [receiver, receiver__username] shall not be empty at the same time'
                )
            if data['receiver']:
                data['receiver__username'] = None
            if data['cc']:
                data['cc__username'] = None
            if data['is_content_base64']:
                try:
                    data['content'] = base64.b64decode(data['content'])
                except Exception:
                    pass
            if data['attachments']:
                data['attachments'] = [
                    SendMail.AttachmentForm(
                        attachment).get_cleaned_data_or_error()
                    for attachment in data['attachments']
                ]
            return data
Esempio n. 25
0
 class Form(BaseComponentForm):
     scope_type = forms.CharField(label='scope type', required=True)
     scope_id = forms.CharField(label='scope id', required=True)
     action = forms.CharField(label='action', required=True)
     data = TypeCheckField(label='data', promise_type=list, required=True)
Esempio n. 26
0
 class Form(BaseComponentForm):
     bk_biz_id = forms.IntegerField(label='business id', required=True)
     bk_host_id = TypeCheckField(label='host id', promise_type=list, required=True)
     bk_module_id = TypeCheckField(label='module id', promise_type=list, required=True)
     is_increment = TypeCheckField(label='is increment', promise_type=bool, required=True)
Esempio n. 27
0
 class Form(BaseComponentForm):
     bk_biz_id = forms.IntegerField(label='business id', required=True)
     bk_set_id = forms.IntegerField(label='set id', required=True)
     data = TypeCheckField(label='data', promise_type=dict, required=False)
 class Form(BaseComponentForm):
     bk_biz_id = forms.IntegerField(label='business id', required=True)
     bk_host_id = TypeCheckField(label='host id',
                                 promise_type=list,
                                 required=True)