Esempio n. 1
0
def get(context, request, username=None):
    """Plone users route
    """
    # Don't allow anonymous users to query a user other than themselves
    if api.is_anonymous():
        username = "******"

    # query all users if no username was given
    if username is None:
        users = api.get_users()
    elif username == "current":
        users = [api.get_current_user()]
    else:
        users = [api.get_user(username)]

    # Prepare batch
    size = req.get_batch_size()
    start = req.get_batch_start()
    batch = api.make_batch(users, size, start)

    # get the user info for the user ids in the current batch
    users = map(get_user_info, batch.get_batch())

    return {
        "pagesize": batch.get_pagesize(),
        "next": batch.make_next_url(),
        "previous": batch.make_prev_url(),
        "page": batch.get_pagenumber(),
        "pages": batch.get_numpages(),
        "count": batch.get_sequence_length(),
        "items": users,
    }
Esempio n. 2
0
def get(context, request, username=None):
    """Plone users route
    """
    # Don't allow anonymous users to query a user other than themselves
    if api.is_anonymous():
        username = "******"

    # query all users if no username was given
    if username is None:
        users = api.get_users()
    elif username == "current":
        users = [api.get_current_user()]
    else:
        users = [api.get_user(username)]

    # Prepare batch
    size = req.get_batch_size()
    start = req.get_batch_start()
    batch = api.make_batch(users, size, start)

    # get the user info for the user ids in the current batch
    users = map(get_user_info, batch.get_batch())

    return {
        "pagesize": batch.get_pagesize(),
        "next": batch.make_next_url(),
        "previous": batch.make_prev_url(),
        "page": batch.get_pagenumber(),
        "pages": batch.get_numpages(),
        "count": batch.get_sequence_length(),
        "items": users,
    }
Esempio n. 3
0
def get_batched(portal_type=None, request=None, uid=None, endpoint=None):
    """ returns a batched result record (dictionary)
    """

    # fetch the catalog results
    results = get_search_results(portal_type=portal_type, uid=uid)

    # fetch the batch params from the request
    size = req.get_batch_size()
    start = req.get_batch_start()

    complete = req.get_complete()
    if not complete:
        # if the uid is given, get the complete information set
        complete = uid and True or False

    # return a batched record
    return get_batch(results, size, start, endpoint=endpoint, complete=complete)
Esempio n. 4
0
def get_batched(portal_type=None, request=None, uid=None, endpoint=None):
    """ returns a batched result record (dictionary)
    """

    # fetch the catalog results
    results = get_search_results(portal_type=portal_type, uid=uid)

    # fetch the batch params from the request
    size = req.get_batch_size()
    start = req.get_batch_start()

    complete = req.get_complete()
    if not complete:
        # if the uid is given, get the complete information set
        complete = uid and True or False

    # return a batched record
    return get_batch(results,
                     size,
                     start,
                     endpoint=endpoint,
                     complete=complete)
Esempio n. 5
0
def get_batched(portal_type=None, uid=None, endpoint=None, **kw):
    """ returns a batched result record (dictionary)
    """

    # fetch the catalog results
    results = get_search_results(portal_type=portal_type, uid=uid, **kw)

    # fetch the batch params from the request
    size = req.get_batch_size()
    start = req.get_batch_start()

    # check for existing complete flag
    complete = req.get_complete(default=_marker)
    if complete is _marker:
        # if the uid is given, get the complete information set
        complete = uid and True or False

    # return a batched record
    return get_batch(results,
                     size,
                     start,
                     endpoint=endpoint,
                     complete=complete)
 def test_batch_start_parameter(self):
     self.assertEqual(req.get_batch_start(), 0)
     request = req.get_request()
     request.form["b_start"] = 1
     self.assertEqual(req.get_batch_start(), 1)
Esempio n. 7
0
 def test_batch_start_parameter(self):
     self.assertEqual(req.get_batch_start(), 0)
     request = req.get_request()
     request.form["b_start"] = 1
     self.assertEqual(req.get_batch_start(), 1)