def clean(self): cd = self.cleaned_data op_name = cd['strategy_op'] threshold = cd['strategy_threshold'] func_name = cd['strategy_func'] var_name = cd['strategy_var'] supported_ops = BuiltInFuncs.name_supported_ops[func_name] required_args = BuiltInFuncs.get_required_args(func_name) if self.is_exists(cd): self.errors['strategy_name'] = [u"该条记录已存在,请勿重复添加"] if var_name not in required_args: self.errors['strategy_var'] = [ u'函数{}支持的内置变量为{}'.format( func_name, self._get_display_names(required_args)) ] if op_name not in supported_ops: self.errors['strategy_op'] = [u'函数{}不支持此操作码'.format(func_name)] if op_name in ('is', 'is_not') and threshold: self.errors['strategy_op'] = [u'[{}]该操作码不接受阈值'.format(op_name)] if op_name in {'lt', 'le', 'eq', 'ne', 'ge', 'gt'}: if not threshold: self.errors['strategy_threshold'] = [ u'操作码{}必须包含阈值'.format(op_name) ] return cd
def _get_bool_strategy_args(self, uuids, client): ret = set() strategy_funcs = self._get_one_kind_fields_from_uuids( uuids, 'bool_strategy', 'strategy_func', client) for name in strategy_funcs: for arg in BuiltInFuncs.get_required_args(name): ret.add(arg) return ret
def post(self, request, *args, **kwargs): uuid = request.POST.get('uuid', None) if uuid: client = get_redis_client() name = 'bool_strategy:{}'.format(uuid) d = client.hgetall(name) strategy_func = d['strategy_func'] required_args = BuiltInFuncs.get_required_args(strategy_func) req_body = {} for member in required_args: req_body[member] = "xxxxxx" return self.render_json_response({ 'state': True, 'req_body': req_body }) else: return self.render_json_response({'state': False})
def clean(self): cd = self.cleaned_data op_name = cd['strategy_op'] threshold = cd['strategy_threshold'] func_name = cd['strategy_func'] var_name = cd['strategy_var'] supported_ops = BuiltInFuncs.name_supported_ops[func_name] required_args = BuiltInFuncs.get_required_args(func_name) if self.is_exists(cd): self.errors['strategy_name'] = [ _("This record already exists, do not add it twice") ] if var_name not in required_args: self.errors['strategy_var'] = [ _('The built-in variables supported by the function are'). format(func_name, self._get_display_names(required_args)) ] if op_name not in supported_ops: self.errors['strategy_op'] = [ _('This ActionCode is not supported by the function').format( func_name) ] if op_name in ('is', 'is_not') and threshold: self.errors['strategy_op'] = [ _('[{}]The ActionCode does not accept the threshold').format( op_name) ] if op_name in {_('lt'), _('le'), _('eq'), _('ne'), _('ge'), _('gt')}: if not threshold: self.errors['strategy_threshold'] = [ _('ActionCode{}Thresholds must be included').format( op_name) ] return cd