コード例 #1
0
ファイル: content.py プロジェクト: hibozzy/mediatum
def mkContentNode(req):
    access = AccessData(req)
    id = req.params.get("id", tree.getRoot("collections").id)
    try:
        node = tree.getNode(id)
    except tree.NoSuchNodeError:
        return ContentError("No such node", 404)
    if not access.hasReadAccess(node):
        return ContentError("Permission denied", 403)

    if node.type in ["directory", "collection"]:
        if "files" not in req.params and len(
                filter(None,
                       node.getStartpageDict().values())) > 0:
            for f in node.getFiles():
                if f.type == "content" and f.mimetype == "text/html" and os.path.isfile(
                        f.retrieveFile()) and fileIsNotEmpty(f.retrieveFile()):
                    return ContentNode(node)

        ids = access.filter(
            list(set(tree.getAllContainerChildrenAbs(node, []))))
        node.ccount = len(ids)
        #ids = access.filter(node.getAllChildren())
        c = ContentList(tree.NodeList(ids), getCollection(node))
        c.feedback(req)
        c.node = node
        return c
    else:
        return ContentNode(node)
コード例 #2
0
ファイル: content.py プロジェクト: agromsl/mediatum
def mkContentNode(req):
    access = AccessData(req)
    id = req.params.get("id", tree.getRoot("collections").id)
    try:
        node = tree.getNode(id)
    except tree.NoSuchNodeError:
        return ContentError("No such node", 404)
    if not access.hasReadAccess(node):
        return ContentError("Permission denied", 403)

    if node.type in ["directory", "collection"]:
        if "files" not in req.params and len(filter(None, node.getStartpageDict().values())) > 0:
            for f in node.getFiles():
                if f.type == "content" and f.mimetype == "text/html" and os.path.isfile(
                        f.retrieveFile()) and fileIsNotEmpty(f.retrieveFile()):
                    return ContentNode(node)

        ids = access.filter(list(set(tree.getAllContainerChildrenAbs(node, []))))
        node.ccount = len(ids)
        #ids = access.filter(node.getAllChildren())
        c = ContentList(tree.NodeList(ids), getCollection(node))
        c.feedback(req)
        c.node = node
        return c
    else:
        return ContentNode(node)
コード例 #3
0
def getContent(req, ids):
    user = users.getUserFromRequest(req)
    access = AccessData(req)
    node = tree.getNode(ids[0])

    if "sortfiles" in users.getHideMenusForUser(user) or not access.hasWriteAccess(node):
        req.setStatus(httpstatus.HTTP_FORBIDDEN)
        return req.getTAL("web/edit/edit.html", {}, macro="access_error")

    c = getCollection(node)

    if "globalsort" in req.params:
        c.set("sortfield", req.params["globalsort"])
    collection_sortfield = c.get("sortfield")

    class SortChoice:

        def __init__(self, label, value):
            self.label = label
            self.value = value

    sortfields = [SortChoice(t(req, "off"), "")]
    for ntype, num in c.getAllOccurences(AccessData(req)).items():
        if ntype.getSortFields():
            for sortfield in ntype.getSortFields():
                sortfields += [SortChoice(sortfield.getLabel(), sortfield.getName())]
                sortfields += [SortChoice(sortfield.getLabel() + t(req, "descending"), "-" + sortfield.getName())]
            break

    return req.getTAL("web/edit/modules/sortfiles.html", {"node": node, "collection_sortfield": collection_sortfield,
                                                          "sortchoices": sortfields, "name": c.getName()}, macro="edit_sortfiles")
コード例 #4
0
ファイル: content.py プロジェクト: hibozzy/mediatum
 def __init__(self, node, nr=0, num=0, words=None, collection=None):
     self.node = node
     self.id = node.id
     self.paths = []
     self.nr = nr
     self.num = num
     self.words = words
     if collection:
         self.collection = collection
     else:
         self.collection = getCollection(node)
     collections = {}
コード例 #5
0
ファイル: content.py プロジェクト: agromsl/mediatum
 def __init__(self, node, nr=0, num=0, words=None, collection=None):
     self.node = node
     self.id = node.id
     self.paths = []
     self.nr = nr
     self.num = num
     self.words = words
     if collection:
         self.collection = collection
     else:
         self.collection = getCollection(node)
     collections = {}
コード例 #6
0
def getContent(req, ids):
    user = current_user
    node = q(Node).get(ids[0])

    if "sortfiles" in user.hidden_edit_functions or not node.has_write_access(
    ):
        req.setStatus(httpstatus.HTTP_FORBIDDEN)
        return req.getTAL("web/edit/edit.html", {}, macro="access_error")

    c = getCollection(node)

    if "globalsort" in req.params:
        c.set("sortfield", req.params["globalsort"])
    collection_sortfield = c.get("sortfield")
    db.session.commit()

    class SortChoice:
        def __init__(self, label, value):
            self.label = label
            self.value = value

    sortfields = [SortChoice(t(req, "off"), "")]
    schemas = (t[0] for t in c.all_children_by_query(
        q(Node.schema).filter_by(subnode=False).group_by(Node.schema).order_by(
            func.count(Node.schema).desc())))

    for schema in schemas:
        metadatatype = q(Metadatatype).filter_by(name=schema).one()
        if metadatatype:
            sort_fields = metadatatype.metafields.filter(
                Node.a.opts.like(u"%o%")).all()
            if sort_fields:
                for sortfield in sort_fields:
                    sortfields += [
                        SortChoice(sortfield.getLabel(), sortfield.name)
                    ]
                    sortfields += [
                        SortChoice(sortfield.getLabel() + t(req, "descending"),
                                   "-" + sortfield.name)
                    ]
                break

    return req.getTAL("web/edit/modules/sortfiles.html", {
        "node": node,
        "collection_sortfield": collection_sortfield,
        "sortchoices": sortfields,
        "name": c.name
    },
                      macro="edit_sortfiles")
コード例 #7
0
ファイル: sortfiles.py プロジェクト: mediatum/mediatum
def getContent(req, ids):
    user = current_user
    node = q(Node).get(ids[0])

    if "sortfiles" in user.hidden_edit_functions or not node.has_write_access():
        req.setStatus(httpstatus.HTTP_FORBIDDEN)
        return req.getTAL("web/edit/edit.html", {}, macro="access_error")

    c = getCollection(node)

    if "globalsort" in req.params:
        c.set("sortfield", req.params["globalsort"])
    collection_sortfield = c.get("sortfield")
    db.session.commit()

    class SortChoice:

        def __init__(self, label, value):
            self.label = label
            self.value = value

    sortfields = [SortChoice(t(req, "off"), "")]
    schemas = (t[0] for t in c.all_children_by_query(q(Node.schema)
                                                  .filter_by(subnode=False)
                                                  .group_by(Node.schema)
                                                  .order_by(func.count(Node.schema).desc())))

    for schema in schemas:
        metadatatype = q(Metadatatype).filter_by(name=schema).one()
        if metadatatype:
            sort_fields = metadatatype.metafields.filter(Node.a.opts.like(u"%o%")).all()
            if sort_fields:
                for sortfield in sort_fields:
                    sortfields += [SortChoice(sortfield.getLabel(), sortfield.name)]
                    sortfields += [SortChoice(sortfield.getLabel() + t(req, "descending"), "-" + sortfield.name)]
                break


    return req.getTAL("web/edit/modules/sortfiles.html", {"node": node,
                                                          "collection_sortfield": collection_sortfield,
                                                          "sortchoices": sortfields,
                                                          "name": c.name},
                      macro="edit_sortfiles")
コード例 #8
0
def show_printview(req):
    """ create a pdf preview of given node (id in path e.g. /print/[id].pdf)"""
    match = RE_PRINT_URL.match(req.path)
    nodeid = int(match.group(1))

    node = q(Node).get(nodeid)
    if node.system_attrs.get("print") == "0" or not node.has_read_access():
        return 404

    style = int(req.params.get("style", 2))

    # nodetype
    mtype = node.metadatatype

    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']]

    # XXX: use scalar() after duplicate cleanup
    presentation_file = node.files.filter_by(filetype=u"presentation").first()
    imagepath = presentation_file.abspath if presentation_file is not None else None

    # children
    children = []
    if isinstance(node, Container):
        ret = []
        getPrintChildren(req, node, ret)

        for c in ret:
            if not isinstance(c, Container):
                # items
                c_mtype = c.metadatatype
                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)
                p = []
                for item in items[0]:
                    p.append(item.getName())
                p.append(c.getName())
                children.append([(c.id, " > ".join(p[1:]), c.getName(),
                                  "header")])

        if len(children) > 1:
            col = []
            order = []
            try:
                sort = getCollection(node).get("sortfield")
            except:
                logg.exception(
                    "exception in show_printview, getting sortfield failed, setting sort = \"\""
                )
                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" + unicode(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.reply_headers[
        'Content-Disposition'] = u'inline; filename="{}_printview.pdf"'.format(
            node.id)
    req.write(
        printview.getPrintView(lang(req), imagepath, metadata, getPaths(node),
                               style, children, getCollection(node)))
コード例 #9
0
    def feedback(self, req):
        Portlet.feedback(self, req)
        self.lang = lang(req)
        if "dir" in req.params or "id" in req.params:
            id = req.params.get("id", req.params.get("dir"))
            try:
                node = tree.getNode(id)
                if isCollection(node):
                    self.collection = node
                    self.directory = node
                else:
                    if isDirectory(node):
                        self.directory = node
                    else:
                        if not isDirectory(self.directory) or not isParentOf(node, self.directory):
                            self.directory = getDirectory(node)
                    if self.collection.type == "collections" or not isParentOf(node, self.collection):
                        self.collection = getCollection(node)
            except tree.NoSuchNodeError:
                pass
        try:
            self.hide_empty = self.collection.get("style_hide_empty") == "1"
        except:
            self.hide_empty = False
        access = AccessData(req)
        # open all parents, so we see that node
        opened = {}
        parents = [self.directory]
        counter = 0
        while parents:
            counter += 1
            if counter > 50:
                raise RecursionException
            p = parents.pop()
            opened[p.id] = 1
            parents += p.getParents()

        m = {}

        def f(m, node, indent, hide_empty):
            if indent > 15:
                raise RecursionException
            if not access.hasReadAccess(node):
                return

            count = -1
            m[node.id] = e = NavTreeEntry(self, node, indent, node.type == "directory", hide_empty=hide_empty, lang=self.lang)
            if node.id in opened or e.defaultopen:
                m[node.id].folded = 0
                for c in node.getContainerChildren():
                    if c.get("style_hide_empty") == "1":
                        hide_empty = 1
                    f(m, c, indent + 1, hide_empty)

        f(m, tree.getRoot("collections"), 0, self.hide_empty)

        if "cunfold" in req.params:
            id = req.params["cunfold"]
            if id in m:
                m[id].folded = 0

        if self.directory.id in m:
            m[self.directory.id].folded = 0
            m[self.directory.id].active = 1

        if self.collection.id in m:
            m[self.collection.id].active = 1

        col_data = []

        def f(col_data, node, indent):
            if indent > 15:
                raise RecursionException
            if node.id not in m:
                return

            data = m[node.id]
            col_data += [data]
            if not data.folded or data.defaultopen:
                for c in node.getContainerChildren().sort_by_orderpos():
                    f(col_data, c, indent + 1)

        f(col_data, tree.getRoot("collections"), 0)
        self.col_data = col_data
コード例 #10
0
ファイル: popups.py プロジェクト: hibozzy/mediatum
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)))
コード例 #11
0
ファイル: popups.py プロジェクト: mediatum/mediatum
def show_printview(req):
    """ create a pdf preview of given node (id in path e.g. /print/[id].pdf)"""
    match = RE_PRINT_URL.match(req.path)
    nodeid = int(match.group(1))

    node = q(Node).get(nodeid)
    if node.system_attrs.get("print") == "0" or not node.has_read_access():
        return 404

    style = int(req.params.get("style", 2))

    # nodetype
    mtype = node.metadatatype

    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']]

    # XXX: use scalar() after duplicate cleanup
    presentation_file = node.files.filter_by(filetype=u"presentation").first()
    imagepath = presentation_file.abspath if presentation_file is not None else None

    # children
    children = []
    if isinstance(node, Container):
        ret = []
        getPrintChildren(req, node, ret)
        logg.debug("getPrintChildren done")

        maskcache = {}

        for c in ret:
            if not isinstance(c, Container):
                # items
                if c.schema in maskcache:
                    c_mask = maskcache[c.schema]
                else:
                    c_mtype = c.metadatatype
                    c_mask = c_mtype.getMask("printlist")
                    if not c_mask:
                        c_mask = c_mtype.getMask("nodesmall")
                    maskcache[c.schema] = c_mask
                _c = c_mask.getViewHTML([c], VIEW_DATA_ONLY)
                if len(_c) > 0:
                    children.append(_c)
            else:
                # header
                items = getPaths(c)
                if not items:
                    continue
                p = []
                for item in items[0]:
                    p.append(item.getName())
                p.append(c.getName())
                children.append([(c.id, " > ".join(p[1:]), c.getName(), "header")])

        if len(children) > 1:
            col = []
            order = []
            try:
                sort = getCollection(node).get("sortfield")
            except:
                logg.exception("exception in show_printview, getting sortfield failed, setting sort = \"\"")
                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" + unicode(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

    print_dir = []
    printfile = printview.getPrintView(lang(req), imagepath, metadata, getPaths(node), style, children, getCollection(node),
                                       return_file=True, print_dir = print_dir)
    req.sendFile(printfile, "application/pdf", nginx_x_accel_redirect_enabled=False)
    if print_dir:
        shutil.rmtree(print_dir[0], ignore_errors=True)
コード例 #12
0
ファイル: popups.py プロジェクト: agromsl/mediatum
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)))