def get_format_validators(include=None, dic=False):
    """Get all FormatValidators.

    :param include: List of FormatValidators to include
    :param dic: Should return a dict
    :return: List of FormatValidator-objects if dic False otherwise dict
    """

    format_validator_classes = [
        import_string(cls) for cls in settings.FORMAT_VALIDATOR_CLASSES
    ] + base_format_validators
    if include is not None:
        format_validator_classes = [
            fvc for fvc in format_validator_classes if fvc.slug in include
        ]
    if dic:
        return {ds.slug: ds for ds in format_validator_classes}
    return [
        FormatValidator(
            slug=ds.slug,
            name=translate_value(ds.name),
            regex=ds.regex,
            error_msg=translate_value(ds.error_msg),
        )
        for ds in format_validator_classes
    ]
Esempio n. 2
0
    def load(self):
        if is_iterable_and_no_string(self.data):
            if not 0 < len(self.data) < 3:
                raise DataSourceException(
                    f"Failed to parse data:\n{self.data}")
            elif len(self.data) == 1:
                return str(self.data[0]), str(self.data[0])
            elif isinstance(self.data[1], dict):
                return (
                    str(self.data[0]),
                    str(translate_value(self.data[1]) or self.data[0]),
                )
            return str(self.data[0]), str(self.data[1])

        return str(self.data), str(self.data)
Esempio n. 3
0
def get_data_sources(dic=False):
    """Get all configured DataSources.

    :param dic: Should return a dict
    :return: List of DataSource-objects if dic False otherwise dict
    """

    data_source_classes = [
        import_string(cls) for cls in settings.DATA_SOURCE_CLASSES
    ]
    if dic:
        return {ds.__name__: ds for ds in data_source_classes}
    return [
        DataSource(name=ds.__name__, info=translate_value(ds.info))
        for ds in data_source_classes
    ]
 def validate(self, value, document):
     if not re.match(self.regex, value):
         raise ValidationError(translate_value(self.error_msg))