def iter_servers(spec=None, fields=None, page=None): limit = None skip = None page_count = settings.app.server_page_count if spec is None: spec = {} if fields: fields = {key: True for key in fields} if page is not None: limit = page_count skip = page * page_count if page else 0 cursor = Server.collection.find(spec, fields).sort('name') if skip is not None: cursor = cursor.skip(page * page_count if page else 0) if limit is not None: cursor = cursor.limit(limit) for doc in cursor: yield Server(doc=doc, fields=fields)
def get_dict(id): return Server(id=id, fields=dict_fields).dict()
def get_by_id(id, fields=None): return Server(id=id, fields=fields)
def new_server(**kwargs): server = Server(**kwargs) server.initialize() return server
def iter_servers(spec=None, fields=None): if fields: fields = {key: True for key in fields} for doc in Server.collection.find(spec or {}, fields).sort('name'): yield Server(doc=doc, fields=fields)
def iter_servers_dict(): fields = {key: True for key in dict_fields} for doc in Server.collection.find({}, fields).sort('name'): yield Server(doc=doc, fields=fields).dict()