def get_collection(cls):
"""Return a reference to the database collection for the class"""
# By default the collection returned will be the published collection,
# however if the `draft` flag has been set against the global context
# (e.g `g`) then the collection returned will contain draft documents.
if g.get('draft'):
return getattr(
cls.get_db(),
'{collection}_draft'.format(collection=cls._collection)
)
return getattr(cls.get_db(), cls._collection)
# Contexts
评论列表
文章目录