def __call__(self): obj = IContentListingObject(self.context) summary = json_compatible({ '@id': obj.getURL(), '@type': obj.PortalType(), 'title': obj.Title(), 'description': obj.Description() }) return summary
def make_item(item, next_prev=True): """Make an item for REST API as expected by the frontend client. """ ws = getattr(item, WORKSPACE_ATTRIBUTE, None) or None # at least not Missing.Value # noqa if next_prev: ob = item.getObject() parent = aq_parent(ob) data_previous = None if (parent.portal_type in NODE_TYPES and getattr(aq_base(parent), WORKSPACE_ATTRIBUTE, ws) != ws): # If the parent's ws != current ws it's OK to not reach this branch because: # 1) not a Contribution or Case. # 2) or hasn't set it's ``workspace`` attribute and not a different ws for sure. _prev = uuidToCatalogBrain(IUUID(parent)) if parent else None data_previous = make_item(_prev, next_prev=False) if _prev else None data_next = [] for child in ob.contentValues(): if getattr(aq_base(child), WORKSPACE_ATTRIBUTE, ws) != ws: # If child hasn't set it's ws attribute its not a different WS for sure. _next = uuidToCatalogBrain(IUUID(child)) data_next.append(make_item(_next, next_prev=False)) item = IContentListingObject(item) ret = { "@id": item.getURL(), "@type": item.PortalType(), "UID": item.uuid(), "title": item.Title(), "review_state": item.review_state(), "workspace": ws, "is_workspace_root": item.workspace_root, "created": item.CreationDate(), "modified": item.ModificationDate() } if next_prev: ret["previous_workspace"] = data_previous ret["next_workspaces"] = data_next return ret
def make_item_overview(item, next_prev=True): """Make an item for REST API as expected by the frontend client. This one is used for overviews, where we do not want the direct next/previous workspace but the next/previous down/up the tree. """ if next_prev: ob = item.getObject() _prev = get_root_of_workspace(aq_parent(ob)) _prev = uuidToCatalogBrain(IUUID(_prev)) if _prev else None data_previous = make_item_overview( _prev, next_prev=False) if _prev else None # noqa _next = get_next_workspaces(ob, context_aware=True) or [] data_next = [make_item_overview(it, next_prev=False) for it in _next] item = IContentListingObject(item) ret = { "@id": item.getURL(), "@type": item.PortalType(), "UID": item.uuid(), "title": item.Title(), "review_state": item.review_state(), "workspace": getattr(item, WORKSPACE_ATTRIBUTE, None) or None, # at least not Missing.Value # noqa "is_workspace_root": item.workspace_root, "created": item.CreationDate(), "modified": item.ModificationDate() } if next_prev: ret["previous_workspace"] = data_previous ret["next_workspaces"] = data_next return ret