# Path: cms/dbutil.py
# def get_mongodb(request):
# def get_collection(request, name):
# def get_gridfs(request, collection='fs'):
# def encode_keys(d):
# def get_es_conn(request):
# def get_es_index_name(request):
# def serve_gridfs_file(file):
# def serve_gridfs_file_for_id(request, id, collection='fs'):
# 
# Path: cms/exceptions.py
# class Veto(Exception):
#     """ May be raised when an attempt is made to do something that the CMS doesn't allow,
#     such as adding an object to a folder with a name that's already in use.
#     Higher level code (such as views) may want to catch these Veto exceptions
#     and present them to end users in a friendly manner.
#     """
#     def __init__(self, msg):
#         Exception.__init__(self, msg)


from cms import dbutil
from cms.exceptions import Veto
import string
        """
        collection_name - name of the MongoDB collection
        child_class - the class used to construct children of this collection
        """
        self.request = request
        self._collection_name = collection_name
        self._child_class = child_class

    def _get_collection(self):
        return dbutil.get_collection(self.request, self._collection_name)

    def _get_child_class(self, doc):
        """ doc is a mongodb document from this collection.
        Not used by the base Collection class, but subclasses could
        use it if they store in their documents the class of each child.
        """
        return self._child_class

    def _morph_spec(self, spec):
        """ Can be used to apply a filter to all mongo queries made by this collection.
        """
        # no-op for base Collection class
        return spec

    def has_child(self, name):
        spec = self._morph_spec({'__name__': name})
        doc = self._get_collection().find_one(spec)
        return doc is not None

    def _construct_child_from_mongo_document(self, doc):

# Path: cms/dbutil.py
# def get_mongodb(request):
# def get_collection(request, name):
# def get_gridfs(request, collection='fs'):
# def encode_keys(d):
# def get_es_conn(request):
# def get_es_index_name(request):
# def serve_gridfs_file(file):
# def serve_gridfs_file_for_id(request, id, collection='fs'):
# 
# Path: cms/exceptions.py
# class Veto(Exception):
#     """ May be raised when an attempt is made to do something that the CMS doesn't allow,
#     such as adding an object to a folder with a name that's already in use.
#     Higher level code (such as views) may want to catch these Veto exceptions
#     and present them to end users in a friendly manner.
#     """
#     def __init__(self, msg):
#         Exception.__init__(self, msg)


# Path: cms/resources/collection.py
from cms import dbutil
from cms.exceptions import Veto
import string

        """
        collection_name - name of the MongoDB collection
        child_class - the class used to construct children of this collection
        """
        self.request = request
        self._collection_name = collection_name
        self._child_class = child_class

    def _get_collection(self):
        return dbutil.get_collection(self.request, self._collection_name)

    def _get_child_class(self, doc):
        """ doc is a mongodb document from this collection.
        Not used by the base Collection class, but subclasses could
        use it if they store in their documents the class of each child.
        """
        return self._child_class

    def _morph_spec(self, spec):
        """ Can be used to apply a filter to all mongo queries made by this collection.
        """
        # no-op for base Collection class
        return spec

    def has_child(self, name):
        spec = self._morph_spec({'__name__': name})
        doc = self._get_collection().find_one(spec)
        return doc is not None

    def _construct_child_from_mongo_document(self, doc):

        obj = self._get_child_class(doc)(self.request, **(dbutil.encode_keys(doc)))