How to use the mixer.main.SKIP_VALUE function in mixer

To help you get started, we’ve selected a few mixer 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 klen / mixer / mixer / backend / mongoengine.py View on Github external
def get_default(field):
        """ Get default value from field.

        :return value: A default value or NO_VALUE

        """
        if not field.scheme.default:
            return SKIP_VALUE

        if callable(field.scheme.default):
            return field.scheme.default()

        return field.scheme.default
github klen / mixer / mixer / backend / sqlalchemy.py View on Github external
def get_default(field):
        """ Get default value from field.

        :return value: A default value or NO_VALUE

        """
        column = field.scheme

        if isinstance(column, RelationshipProperty):
            column = column.local_remote_pairs[0][0]

        if not column.default:
            return SKIP_VALUE

        if column.default.is_callable:
            return column.default.arg(None)

        return getattr(column.default, 'arg', SKIP_VALUE)
github klen / mixer / mixer / backend / django.py View on Github external
def _get_value(self, name, value, field=None):

        if isinstance(value, GeneratorType):
            return self._get_value(name, next(value), field)

        if not isinstance(value, t.Mix) and value is not SKIP_VALUE:

            if callable(value):
                return self._get_value(name, value(), field)

            if field and not isinstance(field.scheme, models.ForeignKey):
                value = field.scheme.to_python(value)

        return name, value
github klen / mixer / mixer / backend / sqlalchemy.py View on Github external
def gen_select(self, field_name, select):
        """ Select exists value from database.

        :param field_name: Name of field for generation.

        :return : None or (name, value) for later use

        """
        if not self.__mixer or not self.__mixer.params.get('session'):
            return field_name, SKIP_VALUE

        relation = self.mapper.get_property(field_name)
        session = self.__mixer.params.get('session')
        value = session.query(
            relation.mapper.class_
        ).filter(*select.choices).order_by(func.random()).first()
        return self.get_value(field_name, value)
github klen / mixer / mixer / backend / marshmallow.py View on Github external
def get_default(field):
        """ Get default value from field.

        :return value:

        """
        return field.scheme.default is missing and SKIP_VALUE or field.scheme.default # noqa
github klen / mixer / mixer / backend / pony.py View on Github external
def get_default(field):
        """ Get default value from field.

        :return value:

        """
        return field.scheme.default is None and SKIP_VALUE or field.scheme.default # noqa
github klen / mixer / mixer / backend / yadm.py View on Github external
def get_default(field):
        """ Get default value from field.

        :return value: A default value or NO_VALUE

        """
        if field.scheme.default is NoDefault:
            return SKIP_VALUE

        if callable(field.scheme.default):
            return field.scheme.default()

        return field.scheme.default
github klen / mixer / mixer / backend / peewee.py View on Github external
def gen_select(self, field_name, select):
        """ Select exists value from database.

        :param field_name: Name of field for generation.

        :return : None or (name, value) for later use

        """
        field = self.__fields[field_name]
        if not isinstance(field.scheme, ForeignKeyField):
            return field_name, SKIP_VALUE

        model = field.scheme.rel_model
        value = model.select().order_by(fn.Random()).get()
        return self.get_value(field_name, value)