How to use fireo - 10 common examples

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 / datetime_field.py View on Github external
def db_value(self, val):
        if isinstance(val, (DatetimeWithNanoseconds, datetime, Sentinel, type(None))):
            return val
        raise errors.InvalidFieldType(f'Invalid field type. Field "{self.name}" expected {datetime}, '
                                      f'got {type(val)}')
github octabytes / FireO / src / fireo / fields / number_field.py View on Github external
def attr_range(self, attr_val, field_val):
        """Method for attribute range"""
        try:
            start, stop = attr_val
        except TypeError:
            start = attr_val
            stop = None

        if start and field_val < start:
            raise errors.NumberRangeError(f'Field "{self.name}" expect number must be grater or equal '
                                          f'than {start}, given {field_val}')
        if stop and field_val > stop:
            raise errors.NumberRangeError(f'Field "{self.name}" expect number must be less than or equal '
                                          f'to {stop}, given {field_val}')

        return field_val
github octabytes / FireO / src / fireo / fields / fields.py View on Github external
def __init__(self, model, *args, **kwargs):
        super().__init__(*args, **kwargs)
        # Check nested model class is subclass for Model
        from fireo.models import Model
        if not issubclass(model, Model):
            raise errors.NestedModelTypeError(f'Nested model {model.__name__} must be inherit from Model class')
        self.nested_model = model
github octabytes / FireO / src / fireo / fields / number_field.py View on Github external
def db_value(self, val):
        if type(val) in [int, float, Increment] or val is None:
            return val
        raise errors.InvalidFieldType(f'Invalid field type. Field "{self.name}" expected {int} or {float}, '
                                      f'got {type(val)}')
github octabytes / FireO / src / fireo / fields / reference_field.py View on Github external
def db_value(self, model):
        # if no model is provided then return None
        if model is None:
            return None
        # check reference model and passing model is same
        if not issubclass(model.__class__, self.model_ref):
            raise errors.ReferenceTypeError(f'Invalid reference type. Field "{self.name}" required value type '
                                            f'"{self.model_ref.__name__}", but got "{model.__class__.__name__}"')
        # Get document reference from firestore
        return firestore.DocumentReference(*utils.ref_path(model.key), client=db.conn)
github octabytes / FireO / src / fireo / fields / map_field.py View on Github external
def db_value(self, val):
        if type(val) is dict or val is None:
            # check if user defined to set the value as lower case
            if self.model_cls._meta.to_lowercase:
                return {k: v.lower() if type(v) is str else v for k,v in val.items()}
            return val
        raise errors.InvalidFieldType(f'Invalid field type. Field "{self.name}" expected {dict}, '
                                      f'got {type(val)}')
github octabytes / FireO / src / fireo / fields / fields.py View on Github external
def db_value(self, model):
        # check reference model and passing model is same
        if not issubclass(model.__class__, self.model_ref):
            raise errors.ReferenceTypeError(f'Invalid reference type. Field "{self.name}" required value type '
                                            f'{self.model_ref.__name__}, but got {model.__class__.__name__}')
        # Get document reference from firestore
        return firestore.DocumentReference(*utils.ref_path(model.key), client=db.conn)
github octabytes / FireO / src / fireo / fields / nested_model.py View on Github external
def __init__(self, model, *args, **kwargs):
        super().__init__(*args, **kwargs)
        # Check nested model class is subclass for Model
        from fireo.models import Model
        if not issubclass(model, Model):
            raise errors.NestedModelTypeError(f'Nested model "{model.__name__}" must be inherit from Model class')
        self.nested_model = model
github octabytes / FireO / src / fireo / fields / boolean_field.py View on Github external
def db_value(self, val):
        if type(val) is bool or val is None:
            return val
        raise errors.InvalidFieldType(f'Invalid field type. Field "{self.name}" expected {bool}, '
                                      f'got {type(val)}')
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