def page_view_page(context, request): # Embedding of items has to happen here as we don't know which of their subobjects # need embedding as we don't know the type and may need their full page view. properties = item_view_page(context, request) blocks = properties.get('layout', {}).get('blocks', []) for block in blocks: if 'item' in block and block['item']: block['item'] = request.embed(block['item'], '@@page', as_user=True) return properties
def antibody_approval_page_view(context, request): if "antibodies" in request.traversed: obj = request.embed(request.resource_path(context), "@@object") qs = request.query_string location = obj["antibody"] + ("?" if qs else "") + qs raise HTTPMovedPermanently(location=location) if request.has_permission("view"): return item_view_page(context, request) raise HTTPForbidden()
def antibody_approval_page_view(context, request): if 'antibodies' in request.traversed: obj = request.embed(request.resource_path(context), '@@object') qs = request.query_string location = obj['antibody'] + ('?' if qs else '') + qs raise HTTPMovedPermanently(location=location) if request.has_permission('view'): return item_view_page(context, request) raise HTTPForbidden()
def user_page_view(context, request): """smth.""" properties = item_view_page(context, request) if not request.has_permission('view_details'): filtered = {} for key in ['@id', '@type', 'uuid', 'lab', 'title', 'link_id', 'display_title']: try: filtered[key] = properties[key] except KeyError: pass return filtered return properties
def user_page_view(context, request): """smth.""" properties = item_view_page(context, request) if not request.has_permission('view_details'): filtered = {} for key in [ '@id', '@type', 'uuid', 'institution', 'project', 'title', 'display_title' ]: try: filtered[key] = properties[key] except KeyError: pass return filtered return properties
def static_page(request): ''' basically get the page in a standard way (item_view_page) which will do permissions checking. Then format the return result to be something the front-end expects ''' def remove_relations_in_tree(node, keep="children"): '''Returns (deep-)copy''' filtered_node = {"name": node['name']} if keep == 'children' and node.get('children') is not None: filtered_node['children'] = [ remove_relations_in_tree(c, keep) for c in node['children'] ] if keep == 'parent' and node.get('parent'): filtered_node['parent'] = remove_relations_in_tree( node['parent'], keep) for field in node.keys(): if field not in ['next', 'previous', 'children', 'parent' ] and node.get(field) is not None: filtered_node[field] = node[field] return filtered_node path_parts = [path_part for path_part in request.subpath if path_part] page_name = "/".join(path_parts) tree = request._static_page_tree if tree is not None: tree = add_sibling_parent_relations_to_tree(tree) curr_node = tree page_in_tree = True for path_idx, part in enumerate(path_parts): for child in curr_node.get('children', []): split_child_name = child['name'].split('/') if len(split_child_name ) > path_idx and split_child_name[path_idx] == part: curr_node = child break if path_idx == len(path_parts) - 1 and curr_node.get( 'uuid') is None: page_in_tree = False break else: page_in_tree = False context = Page(request.registry, request._static_page_model) if context.properties.get('redirect') and context.properties[ 'redirect'].get('enabled'): # We have a redirect defined. parsed_redirect_uri = urlparse(context.properties['redirect'].get( 'target', '/')) uri_to_use = (parsed_redirect_uri.scheme and (parsed_redirect_uri.scheme + ':') or '') + '//' if parsed_redirect_uri.netloc else '' uri_to_use += parsed_redirect_uri.path uri_to_use += '?' + urlencode({ 'redirected_from': '/' + context.properties.get('name', str(context.uuid)) }) + ((parsed_redirect_uri.query and ('&' + parsed_redirect_uri.query)) or '') # Fallback to 307 as is 'safest' (response isn't cached by browsers) return get_pyramid_http_exception_for_redirect_code( context.properties['redirect'].get('code', 307))( location=uri_to_use, detail="Redirected from " + page_name) item = item_view_page(context, request) cleanup_page_tree(item) item['toc'] = item.get('table-of-contents') item['@context'] = item['@id'] if page_in_tree: if curr_node.get('next'): item['next'] = remove_relations_in_tree(curr_node['next']) if curr_node.get('previous'): item['previous'] = remove_relations_in_tree(curr_node['previous']) if curr_node.get('parent'): item['parent'] = remove_relations_in_tree(curr_node['parent'], keep="parent") if curr_node.get('sibling_length') is not None: item['sibling_length'] = curr_node['sibling_length'] item['sibling_position'] = curr_node['sibling_position'] return item
def static_page(request): ''' basically get the page in a standard way (item_view_page) which will do permissions checking. Then format the return result to be something the front-end expects ''' def remove_relations_in_tree(node, keep="children"): '''Returns (deep-)copy''' filtered_node = { "name" : node['name'] } if keep == 'children' and node.get('children') is not None: filtered_node['children'] = [ remove_relations_in_tree(c, keep) for c in node['children'] ] if keep == 'parent' and node.get('parent'): filtered_node['parent'] = remove_relations_in_tree(node['parent'], keep) for field in node.keys(): if field not in ['next', 'previous', 'children', 'parent'] and node.get(field) is not None: filtered_node[field] = node[field] return filtered_node path_parts = [ path_part for path_part in request.subpath if path_part ] page_name = "/".join(path_parts) tree = request._static_page_tree if tree is not None: tree = add_sibling_parent_relations_to_tree(tree) curr_node = tree page_in_tree = True for path_idx, part in enumerate(path_parts): for child in curr_node.get('children',[]): split_child_name = child['name'].split('/') if len(split_child_name) > path_idx and split_child_name[path_idx] == part: curr_node = child break if path_idx == len(path_parts) - 1 and curr_node.get('uuid') is None: page_in_tree = False break else: page_in_tree = False context = Page(request.registry, request._static_page_model) if context.properties.get('redirect') and context.properties['redirect'].get('enabled'): # We have a redirect defined. parsed_redirect_uri = urlparse(context.properties['redirect'].get('target', '/')) uri_to_use = (parsed_redirect_uri.scheme and (parsed_redirect_uri.scheme + ':') or '') + '//' if parsed_redirect_uri.netloc else '' uri_to_use += parsed_redirect_uri.path uri_to_use += '?' + urlencode({ 'redirected_from' : '/' + context.properties.get('name', str(context.uuid)) }) + ((parsed_redirect_uri.query and ('&' + parsed_redirect_uri.query)) or '') # Fallback to 307 as is 'safest' (response isn't cached by browsers) return get_pyramid_http_exception_for_redirect_code(context.properties['redirect'].get('code', 307))(location=uri_to_use, detail="Redirected from " + page_name) item = item_view_page(context, request) cleanup_page_tree(item) item['toc'] = item.get('table-of-contents') item['@context'] = item['@id'] if page_in_tree: if curr_node.get('next'): item['next'] = remove_relations_in_tree(curr_node['next']) if curr_node.get('previous'): item['previous'] = remove_relations_in_tree(curr_node['previous']) if curr_node.get('parent'): item['parent'] = remove_relations_in_tree(curr_node['parent'], keep="parent") if curr_node.get('sibling_length') is not None: item['sibling_length'] = curr_node['sibling_length'] item['sibling_position'] = curr_node['sibling_position'] return item