def get(context, request, username=None): """Plone users route """ user_ids = [] # 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: user_ids = api.get_member_ids() elif username == "current": current_user = api.get_current_user() user_ids = [current_user.getId()] else: user_ids = [username] # Prepare batch size = req.get_batch_size() start = req.get_batch_start() batch = api.make_batch(user_ids, 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, }
def get(context, request, catalog_id=None): """Returns all registered catalogs if key is None, otherwise try to fetch the information about the catalog name passed in """ archetype_tool = api.get_tool("archetype_tool") def get_data(catalog): portal_types = catalog.getPortalTypes() # Bail out portal types not present in this catalog pt_catalogs = map(archetype_tool.getCatalogsByType, portal_types) pt_catalogs = map(lambda pts: catalog in pts, pt_catalogs) pt_catalogs = zip(pt_catalogs, portal_types) portal_types = filter(lambda it: it[0], pt_catalogs) return { "id": catalog.id, "indexes": sorted(catalog.indexes()), "schema": sorted(catalog.schema()), "portal_types": sorted(map(lambda it: it[1], portal_types)), } if catalog_id: # Return the catalog directly catalog = api.get_tool(catalog_id) # If a catalog name was passed in, return the catalog info directly return get_data(catalog) # Look for all catalogs if not archetype_tool: # Default catalog catalogs = [api.get_tool("portal_catalog")], else: catalogs = archetype_tool.getCatalogsInSite() catalogs = map(api.get_tool, catalogs) # Exclude some catalogs skip = ["reference_catalog", "uid_catalog"] catalogs = filter(lambda cat: cat.id not in skip, catalogs) # Generate the metadata info for catalogs records = map(get_data, catalogs) # Prepare batch size = req.get_batch_size() start = req.get_batch_start() batch = api.make_batch(records, size, start) 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": records, "url": api.url_for("senaite.jsonapi.v1.catalogs", key=catalog_id), }
def get(context, request, key=None): """Return settings by keyword. If key is None, return all settings. """ settings = api.get_settings_by_keyword(key) # Prepare batch size = req.get_batch_size() start = req.get_batch_start() batch = api.make_batch(settings, size, start) 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": settings, "url": api.url_for("senaite.jsonapi.v1.settings", key=key), }
def get(context, request, key=None): """Return all registry items if key is None, otherwise try to fetch the registry key """ registry_records = api.get_registry_records_by_keyword(key) # Prepare batch size = req.get_batch_size() start = req.get_batch_start() batch = api.make_batch(registry_records, size, start) 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": [registry_records], "url": api.url_for("senaite.jsonapi.v1.registry", key=key), }
def get_batched(portal_type=None, uid=None, endpoint=None, **kw): """Get batched results """ # 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)