def validate_required(self, value): """ Validates input value against required status. Raises an `InputError` if no value has been provided. """ if self.status == STATUS.active and self.required and (value is None): raise InputError('The field %s is required.' % self.name)
def create(cls, service: str, options: dict[str, str]) -> Plugin: try: module = import_module(f'plugins.{service}') except ModuleNotFoundError: raise InputError(f'Invalid service {service} defined') plugin_cls: Type[Plugin] = module.PluginImpl return plugin_cls(options)
def validate_required(self, value): """ Validate teh given value agaist required status. Checks if value is not None and has at least one character. """ if self.status == STATUS.active and self.required and ( value is None or len(str(value)) == 0): raise InputError('The field %s is required.' % self.name)
def validate_input(self, value): """ Validates if the given value is a valid input for the NumerField. Checks if a value of type number has been provided or if a value of type String has been provided that can be successfully converted to a Float value. Then checks if the value is between bounds of minval and maxval. Returns `True` or `False`. """ if isinstance(value, (str, unicode)) and len(value) == 0: value = None self.validate_required(value) if value is not None: if isinstance(value, (str, unicode)): try: value = float(value) if '.' in value else int(value) except ValueError: raise InputError( 'The value provided for field %s is not a number.' % self.name) if isinstance(value, (int, long, float, complex)): if self.minval and self.maxval and (not (value >= self.minval) and (value <= self.maxval)): raise InputError('The value provided for field %s must be ' ' greater than %s and lower than %s.' % (self.name, self.minval, self.maxval)) else: if self.minval and (not (value >= self.minval)): raise InputError('The value provided for field %s must' ' be greater than %s.' % (self.name, self.minval)) if self.maxval and (not (value <= self.maxval)): raise InputError('The value provided for field %s must' ' be lower than %s.' % (self.name, self.maxval)) else: raise InputError('The value provided for field %s is not a ' 'number.' % self.name)
def validate_input(self, value): """ Checks if the provided value is a valid and ISO8601 compliant date string. """ self.validate_required(value) if value is not None: try: parse_date(value) except ParseError: raise InputError('The value for DateTimeField %s is not a ' 'valid date.' % self.name)
def validate_input(self, provided_vals): self.validate_required(provided_vals) valid = True if provided_vals is not None: if isinstance(provided_vals, (str, unicode)): provided_vals = json.loads(provided_vals) accepted_values = [value.id for value in self.lookupvalues.all()] intersection = [ val for val in provided_vals if val in accepted_values ] valid = len(intersection) == len(provided_vals) if not valid: raise InputError('One or more values for the multiple select ' 'field %s is not an accepted value for the ' 'field.' % self.name)
def validate_input(self, value): """ Checks if the provided value is in the list of `LookupValue`'s. Returns `True` or `False`. """ self.validate_required(value) valid = False if value is not None: try: value = int(value) except ValueError: pass for lookupvalue in self.lookupvalues.all(): if lookupvalue.id == value: valid = True else: valid = True if not valid: raise InputError('The value for lookup field %s is not an ' 'accepted value for the field.' % self.name)
def validate_required(self, value): if self.required and (value is None or len(value) == 0): raise InputError('The field %s is required.' % self.name)