Ejemplo n.º 1
0
    def insert(cls, *args, **kwargs):
        """
        Override collection insert method to allow saved defaults.

        Takes same arguments as :meth:`pymongo.collection.Collection.insert`.

        If `manipulate` is ``False`` then the saved defaults will not be
        inserted.

        :param manipulate: If ``True`` manipulate the documents before \
                inserting (optional)
        :type manipulate: bool

        """
        _version._clean(kwargs)
        if args and kwargs.get('manipulate', True):
            # Insert can take an iterable of documents or a single doc
            doc_or_docs = args[0]
            if isinstance(doc_or_docs, dict):
                cls._ensure_saved_defaults(doc_or_docs)
            else:
                for doc in doc_or_docs:
                    cls._ensure_saved_defaults(doc)

        return cls.collection.insert(*args, **kwargs)
Ejemplo n.º 2
0
    def _wrap_update(cls, *args, **kwargs):
        """
        Override collection update method to handle multiple Pymongo
        versions.

        """
        _version._clean(kwargs)
        return cls.collection.update(*args, **kwargs)
Ejemplo n.º 3
0
    def save(cls, *args, **kwargs):
        """
        Override collection save method to allow saved defaults.

        Takes same arguments as :meth:`pymongo.collection.Collection.save`.

        If `manipulate` is ``False`` then the saved defaults will not be
        inserted.

        :param manipulate: If ``True`` manipulate the documents before saving \
                (optional)
        :type manipulate: bool

        """
        _version._clean(kwargs)
        if args and kwargs.get('manipulate', True):
            cls._ensure_saved_defaults(args[0])

        return cls.collection.save(*args, **kwargs)