def getIDPaths(nid, sep="/", containers_only=True): ''' return list of sep-separated id lists for paths to node with id nid ''' try: node = q(Node).get(nid) if not node.has_read_access(): return [] except: return [] from web.frontend.content import getPaths paths = getPaths(node) res = [] for path in paths: if containers_only: pids = [("%s" % p.id) for p in path if isinstance(p, Container)] else: pids = [("%s" % p.id) for p in path] if pids: res.append(sep.join(pids)) return res
def getIDPaths(nid, access, sep="/", containers_only=True): """ return list of sep-separated id lists for paths to node with id nid """ try: node = tree.getNode(nid) if not access.hasReadAccess(node): return [] except: return [] from web.frontend.content import getPaths paths = getPaths(node, access) res = [] for path in paths: if containers_only: pids = [("%s" % p.id) for p in path if hasattr(p, "isContainer") and p.isContainer()] else: pids = [("%s" % p.id) for p in path] if pids: res.append(sep.join(pids)) return res
def getIDPaths(nid, access, sep="/", containers_only=True): ''' return list of sep-separated id lists for paths to node with id nid ''' try: node = tree.getNode(nid) if not access.hasReadAccess(node): return [] except: return [] from web.frontend.content import getPaths paths = getPaths(node, access) res = [] for path in paths: if containers_only: pids = [("%s" % p.id) for p in path if hasattr(p, 'isContainer') and p.isContainer()] else: pids = [("%s" % p.id) for p in path] if pids: res.append(sep.join(pids)) return res
def getPathTo(req): # returns path(s) to selected node, 'x' separated, with selected nodes in () # parameters: pathTo=selected Node access = AccessData(req) collectionsid = tree.getRoot('collections').id id = req.params.get("pathTo", collectionsid).split(",")[0] node = tree.getNode(id) items = [] checked = [] for path in getPaths(node, access): if node.id not in path and node.isContainer(): # add node if container path.append(node) checked.append(path[-1].id) # last item of path is checked if path[0].getParents()[0].id == collectionsid and collectionsid not in items: items.append(collectionsid) for item in path: if item.id not in items: items.append(item.id) items.append("x") # set devider for next path if req.params.get("multiselect", "false") == "false": # if not multiselect use only first path break if len(items) == 0 or collectionsid in tree.getNode(items[0]).getParents()[0].id: items = [collectionsid] + items items = (",").join(items) for check in checked: # set marked items items = items.replace(check, "(%s)" % (check)) req.write(items) return
def show_printview(req): """ create a pdf preview of given node (id in path e.g. /print/[id]/[area])""" p = req.path[1:].split("/") try: nodeid = int(p[1]) except ValueError: raise ValueError("Invalid Printview URL: " + req.path) if len(p) == 3: if p[2] == "edit": req.reply_headers['Content-Type'] = "application/pdf" editprint = printmethod(req) if editprint: req.write(editprint) else: req.write("") return # use objects from session if str(nodeid) == "0": children = [] if "contentarea" in req.session: try: nodes = req.session["contentarea"].content.files except: c = req.session["contentarea"].content nodes = c.resultlist[c.active].files for n in nodes: c_mtype = getMetaType(n.getSchema()) c_mask = c_mtype.getMask("printlist") if not c_mask: c_mask = c_mtype.getMask("nodesmall") _c = c_mask.getViewHTML([n], VIEW_DATA_ONLY + VIEW_HIDE_EMPTY) if len(_c) > 0: children.append(_c) req.reply_headers['Content-Type'] = "application/pdf" req.write( printview.getPrintView(lang(req), None, [["", "", t(lang(req), "")]], [], 3, children)) else: node = getNode(nodeid) if node.get("system.print") == "0": return 404 access = AccessData(req) if not access.hasAccess(node, "read"): req.write(t(req, "permission_denied")) return style = int(req.params.get("style", 2)) # nodetype mtype = getMetaType(node.getSchema()) mask = None metadata = None if mtype: for m in mtype.getMasks(): if m.getMasktype() == "fullview": mask = m if m.getMasktype() == "printview": mask = m break if not mask: mask = mtype.getMask("nodebig") if mask: metadata = mask.getViewHTML([node], VIEW_DATA_ONLY + VIEW_HIDE_EMPTY) if not metadata: metadata = [['nodename', node.getName(), 'Name', 'text']] files = node.getFiles() imagepath = None for file in files: if file.getType().startswith("presentati"): imagepath = file.retrieveFile() # children children = [] if node.isContainer(): ret = [] getPrintChildren(req, node, ret) for c in ret: if not c.isContainer(): # items c_mtype = getMetaType(c.getSchema()) c_mask = c_mtype.getMask("printlist") if not c_mask: c_mask = c_mtype.getMask("nodesmall") _c = c_mask.getViewHTML([c], VIEW_DATA_ONLY) if len(_c) > 0: children.append(_c) else: # header items = getPaths(c, AccessData(req)) p = [] for item in items[0]: p.append(u(item.getName())) p.append(u(c.getName())) children.append([(c.id, " > ".join(p[1:]), u(c.getName()), "header")]) if len(children) > 1: col = [] order = [] try: sort = getCollection(node).get("sortfield") except: sort = "" for i in range(0, 2): col.append((0, "")) order.append(1) if req.params.get("sortfield" + str(i)) != "": sort = req.params.get("sortfield" + str(i), sort) if sort != "": if sort.startswith("-"): sort = sort[1:] order[i] = -1 _i = 0 for c in children[0]: if c[0] == sort: col[i] = (_i, sort) _i += 1 if col[i][1] == "": col[i] = (0, children[0][0][0]) # sort method for items def myCmp(x, y, col, order): cx = "" cy = "" for item in x: if item[0] == col[0][1]: cx = item[1] break for item in y: if item[0] == col[0][1]: cy = item[1] break if cx.lower() > cy.lower(): return 1 * order[0] return -1 * order[0] sorted_children = [] tmp = [] for item in children: if item[0][3] == "header": if len(tmp) > 0: tmp.sort(lambda x, y: myCmp(x, y, col, order)) sorted_children.extend(tmp) tmp = [] sorted_children.append(item) else: tmp.append(item) tmp.sort(lambda x, y: myCmp(x, y, col, order)) sorted_children.extend(tmp) children = sorted_children req.reply_headers['Content-Type'] = "application/pdf" req.write( printview.getPrintView(lang(req), imagepath, metadata, getPaths(node, AccessData(req)), style, children, getCollection(node)))
def isParent__(basenode, node, access): return 1 for ls in getPaths(node, access): if str(basenode.id) in tree.NodeList(ls).getIDs(): return 1 return 0
def isChildOf(access, node, basenodeid): for ls in getPaths(node, access): if str(basenodeid) in tree.NodeList(ls).getIDs(): return 1 return 0
def show_printview(req): """ create a pdf preview of given node (id in path e.g. /print/[id]/[area])""" p = req.path[1:].split("/") try: nodeid = int(p[1]) except ValueError: raise ValueError("Invalid Printview URL: " + req.path) if len(p) == 3: if p[2] == "edit": req.reply_headers['Content-Type'] = "application/pdf" editprint = printmethod(req) if editprint: req.write(editprint) else: req.write("") return # use objects from session if str(nodeid) == "0": children = [] if "contentarea" in req.session: try: nodes = req.session["contentarea"].content.files except: c = req.session["contentarea"].content nodes = c.resultlist[c.active].files for n in nodes: c_mtype = getMetaType(n.getSchema()) c_mask = c_mtype.getMask("printlist") if not c_mask: c_mask = c_mtype.getMask("nodesmall") _c = c_mask.getViewHTML([n], VIEW_DATA_ONLY + VIEW_HIDE_EMPTY) if len(_c) > 0: children.append(_c) req.reply_headers['Content-Type'] = "application/pdf" req.write(printview.getPrintView(lang(req), None, [["", "", t(lang(req), "")]], [], 3, children)) else: node = getNode(nodeid) if node.get("system.print") == "0": return 404 access = AccessData(req) if not access.hasAccess(node, "read"): req.write(t(req, "permission_denied")) return style = int(req.params.get("style", 2)) # nodetype mtype = getMetaType(node.getSchema()) mask = None metadata = None if mtype: for m in mtype.getMasks(): if m.getMasktype() == "fullview": mask = m if m.getMasktype() == "printview": mask = m break if not mask: mask = mtype.getMask("nodebig") if mask: metadata = mask.getViewHTML([node], VIEW_DATA_ONLY + VIEW_HIDE_EMPTY) if not metadata: metadata = [['nodename', node.getName(), 'Name', 'text']] files = node.getFiles() imagepath = None for file in files: if file.getType().startswith("presentati"): imagepath = file.retrieveFile() # children children = [] if node.isContainer(): ret = [] getPrintChildren(req, node, ret) for c in ret: if not c.isContainer(): # items c_mtype = getMetaType(c.getSchema()) c_mask = c_mtype.getMask("printlist") if not c_mask: c_mask = c_mtype.getMask("nodesmall") _c = c_mask.getViewHTML([c], VIEW_DATA_ONLY) if len(_c) > 0: children.append(_c) else: # header items = getPaths(c, AccessData(req)) p = [] for item in items[0]: p.append(u(item.getName())) p.append(u(c.getName())) children.append([(c.id, " > ".join(p[1:]), u(c.getName()), "header")]) if len(children) > 1: col = [] order = [] try: sort = getCollection(node).get("sortfield") except: sort = "" for i in range(0, 2): col.append((0, "")) order.append(1) if req.params.get("sortfield" + str(i)) != "": sort = req.params.get("sortfield" + str(i), sort) if sort != "": if sort.startswith("-"): sort = sort[1:] order[i] = -1 _i = 0 for c in children[0]: if c[0] == sort: col[i] = (_i, sort) _i += 1 if col[i][1] == "": col[i] = (0, children[0][0][0]) # sort method for items def myCmp(x, y, col, order): cx = "" cy = "" for item in x: if item[0] == col[0][1]: cx = item[1] break for item in y: if item[0] == col[0][1]: cy = item[1] break if cx.lower() > cy.lower(): return 1 * order[0] return -1 * order[0] sorted_children = [] tmp = [] for item in children: if item[0][3] == "header": if len(tmp) > 0: tmp.sort(lambda x, y: myCmp(x, y, col, order)) sorted_children.extend(tmp) tmp = [] sorted_children.append(item) else: tmp.append(item) tmp.sort(lambda x, y: myCmp(x, y, col, order)) sorted_children.extend(tmp) children = sorted_children req.reply_headers['Content-Type'] = "application/pdf" req.write(printview.getPrintView(lang(req), imagepath, metadata, getPaths( node, AccessData(req)), style, children, getCollection(node)))