How to use the fireo.fields.errors.AttributeTypeError function in fireo

To help you get started, we’ve selected a few fireo examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github octabytes / FireO / src / fireo / fields / text_field.py View on Github external
# just return back the None value
        if val is None:
            return val

        self.field_attribute.parse(val, run_only=['format'])
        if self.format_type:
            if self.format_type in self.supported_types:
                if self.format_type == 'title':
                    return self._titlecase(val)
                if self.format_type == 'upper':
                    return val.upper()
                if self.format_type == 'lower':
                    return val.lower()
                if self.format_type == 'capitalize':
                    return val.capitalize()
            raise errors.AttributeTypeError(
                f'Invalid attribute type. Inside Field "{self.name}", '
                f'"format" type must be one of them "{self.supported_types}".')
        return val
github octabytes / FireO / src / fireo / fields / reference_field.py View on Github external
def attr_auto_load(self, attr_val, field_val):
        """Attribute method for auto load

        Allow users to load reference documents automatically or just return the reference
        and user itself call the `get()` method to load the document.
        """
        if type(attr_val) is not bool:
            raise errors.AttributeTypeError(f'Attribute auto_load only accept bool type, got {type(attr_val)} in '
                                            f'model "{self.model_cls.__name__}" field "{self.name}"')
        self.auto_load = attr_val
        return field_val
github octabytes / FireO / src / fireo / fields / fields.py View on Github external
def attr_on_load(self, method_name, field_val):
        """Attribute method for on load

        Call user specify method when reference document is loaded
        """
        try:
            m = getattr(self.model_cls, method_name)
            if not callable(m):
                raise errors.AttributeTypeError(f'Attribute {m} is not callable in model {self.model_cls.__name__} '
                                                f'field {self.name}')
            self.on_load = method_name
        except AttributeError as e:
            raise errors.AttributeMethodNotDefined(f'Method {method_name} is not defined for attribute on_load in '
                                                   f'model {self.model_cls.__name__} field {self.name}') from e

        return field_val
github octabytes / FireO / src / fireo / fields / reference_field.py View on Github external
def attr_on_load(self, method_name, field_val):
        """Attribute method for on load

        Call user specify method when reference document is loaded
        """
        try:
            m = getattr(self.model_cls, method_name)
            if not callable(m):
                raise errors.AttributeTypeError(f'Attribute {m} is not callable in model "{self.model_cls.__name__}" '
                                                f'field "{self.name}"')
            self.on_load = method_name
        except AttributeError as e:
            raise errors.AttributeMethodNotDefined(f'Method "{method_name}" is not defined for attribute on_load in '
                                                   f'model "{self.model_cls.__name__}" field "{self.name}"') from e

        return field_val
github octabytes / FireO / src / fireo / fields / fields.py View on Github external
def attr_auto_load(self, attr_val, field_val):
        """Attribute method for auto load

        Allow users to load reference documents automatically or just return the reference
        and user itself call the `get()` method to load the document.
        """
        if type(attr_val) is not bool:
            raise errors.AttributeTypeError(f'Attribute auto_load only accept bool type, got {type(attr_val)} in '
                                            f'model {self.model_cls.__name__} field {self.name}')
        self.auto_load = attr_val
        return field_val