Example #1
0
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)
Example #2
0
def new_server(**kwargs):
    server = Server(**kwargs)
    server.initialize()
    return server
Example #3
0
def get_dict(id):
    return Server(id=id, fields=dict_fields).dict()
Example #4
0
def get_by_id(id, fields=None):
    return Server(id=id, fields=fields)
Example #5
0
def new_server(**kwargs):
    server = Server(**kwargs)
    server.initialize()
    return server
Example #6
0
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)
Example #7
0
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()