def validates_watch(obj, target, lang): checker = Checker() check = True _ = obj._ checker.errors = [] if target not in WATCH_PLUGINS.values(): check = False checker.add_error(_('"%s" is not watch target.') %_(target)) if lang not in DEFAULT_LANGS: check = False checker.add_error(_('"%s" is not supported language.') %_(lang)) obj.view.alert = checker.errors return check
def validates_watch(obj, target, lang): checker = Checker() check = True _ = obj._ checker.errors = [] if target not in WATCH_PLUGINS.values(): check = False checker.add_error(_('"%s" is not watch target.') % _(target)) if lang not in DEFAULT_LANGS: check = False checker.add_error(_('"%s" is not supported language.') % _(lang)) obj.view.alert = checker.errors return check
def validates_watch(obj): checker = Checker() check = True _ = obj._ checker.errors = [] if is_param(obj.input, 'watch_name'): check = checker.check_string(_('Name'), obj.input.watch_name, CHECK_EMPTY | CHECK_ONLYSPACE, None, ) and check else: check = False checker.add_error(_('"%s" is required.') %_('Name')) if is_param(obj.input, 'watch_target'): check = checker.check_string(_('Watch Target'), obj.input.watch_target, CHECK_EMPTY | CHECK_ONLYSPACE, None, ) and check if obj.input.watch_target not in WATCH_PLUGINS.values(): check = False # TRANSLATORS: # %sは監視対象ではありません。 checker.add_error(_('"%s" is not watch target.') %_(obj.input.watch_target)) else: check = False checker.add_error(_('"%s" is required.') %_('Watch Target')) if is_param(obj.input, 'continuation_count'): check = checker.check_number(_('Alert Trigger Count'), obj.input.continuation_count, CHECK_EMPTY | CHECK_VALID | CHECK_MIN | CHECK_MAX, CONTINUATION_COUNT_MIN, CONTINUATION_COUNT_MAX, ) and check else: check = False checker.add_error(_('"%s" is required.') %_('Alert Trigger Count')) if is_param(obj.input, 'prohibition_period'): check = checker.check_number(_('Silent Period'), obj.input.prohibition_period, CHECK_EMPTY | CHECK_VALID | CHECK_MIN | CHECK_MAX, PROHIBITION_PERIOD_MIN, PROHIBITION_PERIOD_MAX, ) and check else: check = False checker.add_error(_('"%s" is required.') %_('Silent Period')) if is_param(obj.input, 'threshold_fraction'): fraction = int(obj.input.threshold_fraction) else: fraction = 0 if is_param(obj.input, 'threshold_val1'): if fraction == 0: check = checker.check_number(_('Threshold Value'), obj.input.threshold_val1, CHECK_EMPTY | CHECK_VALID | CHECK_MIN, THRESHOLD_VAL_MIN, None, ) and check else: check = checker.check_fraction(_('Threshold Value'), obj.input.threshold_val1, CHECK_EMPTY | CHECK_VALID | CHECK_MIN, THRESHOLD_VAL_MIN, None, fraction, ) and check else: check = False checker.add_error(_('"%s" is required.') %_('Threshold Value')) if is_param(obj.input, 'threshold_val2'): if fraction == 0: check = checker.check_number(_('Threshold Value'), obj.input.threshold_val2, CHECK_EMPTY | CHECK_VALID | CHECK_MIN, THRESHOLD_VAL_MIN, None, ) and check else: check = checker.check_fraction(_('Threshold Value'), obj.input.threshold_val2, CHECK_EMPTY | CHECK_VALID | CHECK_MIN, THRESHOLD_VAL_MIN, None, fraction, ) and check else: check = False checker.add_error(_('"%s" is required.') %_('Threshold Value')) if not is_param(obj.input, 'threshold_type'): check = False checker.add_error(_('"%s" is required.') %_('Threshold Type')) if is_param(obj.input, 'notify_mail_to'): if obj.input.notify_mail_to != "": check = checker.check_mailaddress(_('Mail To'), obj.input.notify_mail_to, CHECK_LENGTH | CHECK_VALID, EMAIL_MIN_LENGTH, EMAIL_MAX_LENGTH, ) and check if is_param(obj.input, 'notify_mail_from'): if obj.input.notify_mail_from != "": check = checker.check_mailaddress(_('Mail From'), obj.input.notify_mail_from, CHECK_LENGTH | CHECK_VALID, EMAIL_MIN_LENGTH, EMAIL_MAX_LENGTH, ) and check obj.view.alert = checker.errors return check
def validates_watch(obj): checker = Checker() check = True _ = obj._ checker.errors = [] if is_param(obj.input, 'watch_name'): check = checker.check_string( _('Name'), obj.input.watch_name, CHECK_EMPTY | CHECK_ONLYSPACE, None, ) and check else: check = False checker.add_error(_('"%s" is required.') % _('Name')) if is_param(obj.input, 'watch_target'): check = checker.check_string( _('Watch Target'), obj.input.watch_target, CHECK_EMPTY | CHECK_ONLYSPACE, None, ) and check if obj.input.watch_target not in WATCH_PLUGINS.values(): check = False # TRANSLATORS: # %sは監視対象ではありません。 checker.add_error( _('"%s" is not watch target.') % _(obj.input.watch_target)) else: check = False checker.add_error(_('"%s" is required.') % _('Watch Target')) if is_param(obj.input, 'continuation_count'): check = checker.check_number( _('Alert Trigger Count'), obj.input.continuation_count, CHECK_EMPTY | CHECK_VALID | CHECK_MIN | CHECK_MAX, CONTINUATION_COUNT_MIN, CONTINUATION_COUNT_MAX, ) and check else: check = False checker.add_error(_('"%s" is required.') % _('Alert Trigger Count')) if is_param(obj.input, 'prohibition_period'): check = checker.check_number( _('Silent Period'), obj.input.prohibition_period, CHECK_EMPTY | CHECK_VALID | CHECK_MIN | CHECK_MAX, PROHIBITION_PERIOD_MIN, PROHIBITION_PERIOD_MAX, ) and check else: check = False checker.add_error(_('"%s" is required.') % _('Silent Period')) if is_param(obj.input, 'threshold_fraction'): fraction = int(obj.input.threshold_fraction) else: fraction = 0 if is_param(obj.input, 'threshold_val1'): if fraction == 0: check = checker.check_number( _('Threshold Value'), obj.input.threshold_val1, CHECK_EMPTY | CHECK_VALID | CHECK_MIN, THRESHOLD_VAL_MIN, None, ) and check else: check = checker.check_fraction( _('Threshold Value'), obj.input.threshold_val1, CHECK_EMPTY | CHECK_VALID | CHECK_MIN, THRESHOLD_VAL_MIN, None, fraction, ) and check else: check = False checker.add_error(_('"%s" is required.') % _('Threshold Value')) if is_param(obj.input, 'threshold_val2'): if fraction == 0: check = checker.check_number( _('Threshold Value'), obj.input.threshold_val2, CHECK_EMPTY | CHECK_VALID | CHECK_MIN, THRESHOLD_VAL_MIN, None, ) and check else: check = checker.check_fraction( _('Threshold Value'), obj.input.threshold_val2, CHECK_EMPTY | CHECK_VALID | CHECK_MIN, THRESHOLD_VAL_MIN, None, fraction, ) and check else: check = False checker.add_error(_('"%s" is required.') % _('Threshold Value')) if not is_param(obj.input, 'threshold_type'): check = False checker.add_error(_('"%s" is required.') % _('Threshold Type')) if is_param(obj.input, 'notify_mail_to'): if obj.input.notify_mail_to != "": check = checker.check_mailaddress( _('Mail To'), obj.input.notify_mail_to, CHECK_LENGTH | CHECK_VALID, EMAIL_MIN_LENGTH, EMAIL_MAX_LENGTH, ) and check if is_param(obj.input, 'notify_mail_from'): if obj.input.notify_mail_from != "": check = checker.check_mailaddress( _('Mail From'), obj.input.notify_mail_from, CHECK_LENGTH | CHECK_VALID, EMAIL_MIN_LENGTH, EMAIL_MAX_LENGTH, ) and check obj.view.alert = checker.errors return check