Exemple #1
0
    def event_files_changed(self):
        for f in self.getFiles():
            if f.type in ["thumb", "presentation"]:
                self.removeFile(f)

        nodefiles = self.getFiles()
        if len(nodefiles) == 1 and nodefiles[0].mimetype == "video/quicktime":
            if nodefiles[0].retrieveFile().endswith('.mov'):  # handle mov -> flv
                flvname = "%sflv" % nodefiles[0].retrieveFile()[:-3]
                ret = os.system("ffmpeg -loglevel quiet -i %s -ar 44100 -ab 128 -f flv %s" % (nodefiles[0].retrieveFile(), flvname))
                if ret & 0xff00:
                    return
                self.addFile(FileNode(name=flvname, type="video", mimetype="video/x-flv"))

        #fetch tags to be omitted
        unwanted_attrs = self.unwanted_attributes()

        for f in self.getFiles():
            if f.type in["original", "video"]:
                if f.mimetype == "video/x-flv":
                    meta = FLVReader(f.retrieveFile())
                    for key in meta:
                        if any(tag in key for tag in unwanted_attrs):
                                continue
                        try:
                            self.set(key, int(meta[key]))
                        except:
                            self.set(key, meta[key])

                    self.set("vid-width", self.get("width"))
                    self.set("vid-height", self.get("height"))

                    tempname = os.path.join(config.get("paths.tempdir"), "tmp.gif")
                    try:
                        os.unlink(tempname)
                    except:
                        pass

                    try:
                        if self.get("system.thumbframe") != "":
                            cmd = "ffmpeg -loglevel quiet  -ss %s -i %s -vframes 1 -pix_fmt rgb24 %s" % (
                                self.get("system.thumbframe"), f.retrieveFile(), tempname)
                        else:
                            cmd = "ffmpeg -loglevel quiet -i %s -vframes 1 -pix_fmt rgb24 %s" % (f.retrieveFile(), tempname)
                        ret = os.system(cmd)
                        if ret & 0xff00:
                            return
                    except:
                        return
                    path, ext = splitfilename(f.retrieveFile())
                    thumbname = path + ".thumb"
                    thumbname2 = path + ".thumb2"
                    makeThumbNail(tempname, thumbname)
                    makePresentationFormat(tempname, thumbname2)
                    self.addFile(FileNode(name=thumbname, type="thumb", mimetype="image/jpeg"))
                    self.addFile(FileNode(name=thumbname2, type="presentation", mimetype="image/jpeg"))
Exemple #2
0
    def event_files_changed(self):
        for f in self.getFiles():
            if f.type in ["thumb", "presentation"]:
                self.removeFile(f)

        for f in self.getFiles():
            if f.mimetype == "video/mp4":
                for f in self.getFiles():
                    if f.type in ["thumb", "presentation"]:
                        self.removeFile(f)

                if len([f for f in self.getFiles() if f.mimetype == 'video/mp4']) > 0:
                    tempname = os.path.join(config.get("paths.tempdir"), "tmp.gif")

                    if os.path.exists(tempname):
                        os.remove(tempname)

                    mp4_path = f.retrieveFile()
                    mp4_name = os.path.splitext(mp4_path)[0]

                    try:
                        if self.get("system.thumbframe") != "":

                            cmd = "ffmpeg -loglevel quiet -ss {} -i {} -vframes 1 -pix_fmt rgb24 {}".format(self.get("system.thumbframe"), mp4_path, tempname)
                        else:
                            cmd = "ffmpeg -loglevel quiet -i {} -vframes 1 -pix_fmt rgb24 {}".format(mp4_path, tempname)
                        ret = os.system(cmd)
                        if ret & 0xff00:
                            return
                    except:
                        return
                    thumbname = "{}.thumb".format(mp4_name)
                    thumbname2 = "{}.thumb2".format(mp4_name)
                    makeThumbNail(tempname, thumbname)
                    makePresentationFormat(tempname, thumbname2)
                    self.addFile(FileNode(name=thumbname, type="thumb", mimetype="image/jpeg"))
                    self.addFile(FileNode(name=thumbname2, type="presentation", mimetype="image/jpeg"))
Exemple #3
0
def getContent(req, ids):
    ret = ""
    user = users.getUserFromRequest(req)
    node = tree.getNode(ids[0])
    update_error = False
    access = acl.AccessData(req)

    msg = "%s|web.edit.modules.files.getContend|req.fullpath=%r|req.path=%r|req.params=%r|ids=%r" % (get_user_id(req), req.fullpath, req.path, req.params, ids)
    log.debug(msg)

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

    if 'data' in req.params:
        if req.params.get('data') == 'children':  # get formated list of childnodes of selected directory
            excludeid = req.params.get('excludeid', None)
            if excludeid:
                grandchildren = []
                for child in node.getChildren():
                    for grandchild in child.getChildren():
                        if not grandchild.isContainer():
                            grandchildren.append(grandchild)
                req.writeTAL("web/edit/modules/files.html", {'children': [c for c in node.getChildren() if str(c.id) != excludeid],
                                                             'grandchildren': grandchildren}, macro="edit_files_popup_children")
            else:
                grandchildren = []
                for child in node.getChildren():
                    for grandchild in child.getChildren():
                        if not grandchild.isContainer():
                            grandchildren.append(grandchild)
                req.writeTAL("web/edit/modules/files.html", {'children': [c for c in node.getChildren() if str(c.id) != excludeid],
                                                             'grandchildren': grandchildren}, macro="edit_files_popup_children")
        elif req.params.get('data') =='grandchildren':
            grandchildren = []
            for child in node.getChildren():
                if not child.isContainer():
                    for grandchild in child.getChildren():
                        if not grandchild.isContainer():
                            if not grandchild.isContainer():
                                grandchildren.append(grandchild)

            if len(node.getChildren())==0:
                req.writeTAL("web/edit/modules/files.html", {'grandchildren': []}, macro="edit_files_popup_grandchildren")
            else:
                req.writeTAL("web/edit/modules/files.html", {'grandchildren': grandchildren}, macro="edit_files_popup_grandchildren")

        if req.params.get('data') == 'additems':  # add selected node as children
            for childid in req.params.get('items').split(";"):
                if childid.strip() != "":
                    childnode = tree.getNode(childid.strip())
                    for p in childnode.getParents():
                        if p.isContainer():
                            logging.getLogger('editor').info("Removed childnode: {} from node: {}. - caused by adding".format(childnode.id, node.id))
                            p.removeChild(childnode)
                    node.addChild(childnode)
            req.writeTAL("web/edit/modules/files.html", {'children': node.getChildren(), 'node': node}, macro="edit_files_children_list")

        if req.params.get('data') == 'removeitem':  # remove selected childnode node

            try:
                remnode = tree.getNode(req.params.get('remove'))
                if len(remnode.getParents()) == 1:
                    users.getUploadDir(user).addChild(remnode)
                node.removeChild(remnode)
            except: # node not found
                pass
            req.writeTAL("web/edit/modules/files.html", {'children': node.getChildren(), 'node': node}, macro="edit_files_children_list")

        if req.params.get('data') == 'reorder':
            i = 0
            for id in req.params.get('order').split(","):
                if id != "":
                    n = tree.getNode(id)
                    n.setOrderPos(i)
                    i += 1

        if req.params.get('data') == 'translate':
            req.writeTALstr('<tal:block i18n:translate="" tal:content="msgstr"/>', {'msgstr': req.params.get('msgstr')})
        return ""

    if req.params.get("style") == "popup":
        v = {"basedirs": [tree.getRoot('home'), tree.getRoot('collections')]}
        id = req.params.get("id", tree.getRoot().id)
        v["script"] = "var currentitem = '%s';\nvar currentfolder = '%s';\nvar node = %s;" %(id, req.params.get('parent'), id)
        v["idstr"] = ",".join(ids)
        v["node"] = node

        if node.type != 'directory':
            try:
                if v['current_id'] == None:
                    v['current_id'] = node.id
            except KeyError:
                pass

        req.writeTAL("web/edit/modules/files.html", v, macro="edit_files_popup_selection")
        return ""

    if "operation" in req.params:
        op = req.params.get("operation")
        if op == "delete":
            for key in req.params.keys():  # delete file
                if key.startswith("del|"):
                    filename = key[4:-2].split("|")
                    for file in node.getFiles():
                        if file.getName() == filename[1] and file.type == filename[0]:
                            # remove all files in directory
                            if file.getMimeType() == "inode/directory":
                                for root, dirs, files in os.walk(file.retrieveFile()):
                                    for name in files:
                                        try:
                                            os.remove(root + "/" + name)
                                        except:
                                            pass
                                    os.removedirs(file.retrieveFile()+"/")
                            if len([f for f in node.getFiles() if f.getName()==filename[1] and f.type==filename[0]]) > 1:
                                # remove single file from database if there are duplicates
                                node.removeFile(file, single=True)
                            else:
                                # remove single file
                                node.removeFile(file)
                                try:
                                    os.remove(file.retrieveFile())
                                except:
                                    pass
                            break
                    break
                elif key.startswith("delatt|"):
                    for file in node.getFiles():
                        if file.getMimeType() == "inode/directory":
                            try:
                                os.remove(file.retrieveFile() + "/" + key.split("|")[2][:-2])
                            except:
                                pass
                            break
                    break

        elif op=="change":
            uploadfile = req.params.get("updatefile")

            if uploadfile:
                create_version_error = False
                # Create new version when change file
                if (req.params.get('generate_new_version') and not hasattr(node, "metaFields")):
                    if (req.params.get('version_comment', '').strip()==''
                        or req.params.get('version_comment', '').strip()=='&nbsp;'):
                        create_version_error = True
                        req.setStatus(httpstatus.HTTP_INTERNAL_SERVER_ERROR)
                        ret += req.getTAL("web/edit/modules/files.html", {}, macro="version_error")
                    else:
                        current = node
                        node = node.createNewVersion(user)

                        for attr, value in current.items():
                            if node.get(attr)!="": # do not overwrite attributes
                                pass
                            else:
                                node.set(attr, value)
                        req.setStatus(httpstatus.HTTP_MOVED_TEMPORARILY)
                        ret += req.getTAL("web/edit/modules/metadata.html", {'url':'?id='+node.id+'&tab=files', 'pid':None}, macro="redirect")

                if req.params.get("change_file")=="yes" and not create_version_error: # remove old files
                    if uploadfile.filename:
                        if getMimeType(uploadfile.filename)[0] == 'other':
                            return '<h2 style="width:100%; text-align:center ;color:red">file-format is not supported (upload canceled / use attachment)</h2>'
                    for f in node.getFiles():
                        if f.getType() in node.getSysFiles():
                            node.removeFile(f)
                    node.set("system.version.comment", '('+t(req, "edit_files_new_version_exchanging_comment")+')\n'+req.params.get('version_comment', ''))

                if req.params.get("change_file")=="no" and not create_version_error:
                    node.set("system.version.comment", '('+t(req, "edit_files_new_version_adding_comment")+')\n'+req.params.get('version_comment', ''))

                if req.params.get("change_file") in ["yes", "no"] and not create_version_error:
                    if uploadfile.filename:
                        if getMimeType(uploadfile.filename)[0] == 'other':
                            return '<h2 style="width:100%; text-align:center ;color:red">file-format is not supported (upload canceled / use attachment)</h2>'
                    file = importFile(uploadfile.filename, uploadfile.tempname) # add new file
                    node.addFile(file)
                    logging.getLogger('usertracing').info(user.name+" changed file of node "+node.id+" to "+uploadfile.filename+" ("+uploadfile.tempname+")")

                attpath = ""
                for f in node.getFiles():
                    if f.getMimeType()=="inode/directory":
                        attpath = f.getName()
                        break

                if req.params.get("change_file")=="attdir" and not create_version_error: # add attachmentdir
                    dirname = req.params.get("inputname")

                    if attpath=="": # add attachment directory
                        attpath = req.params.get("inputname")
                        if not os.path.exists(getImportDir() + "/" + attpath):
                            os.mkdir(getImportDir() + "/" + attpath)
                            node.addFile(tree.FileNode(name=getImportDir() + "/" + attpath, mimetype="inode/directory", type="attachment"))

                        file = importFileIntoDir(getImportDir() + "/" + attpath, uploadfile.tempname) # add new file
                    node.set("system.version.comment", '('+t(req, "edit_files_new_version_attachment_directory_comment")+')\n'+req.params.get('version_comment', ''))
                    pass


                if req.params.get("change_file")=="attfile" and not create_version_error: # add file as attachment
                    if attpath=="":
                        # no attachment directory existing
                        file = importFile(uploadfile.filename, uploadfile.tempname) # add new file
                        file.mimetype = "inode/file"
                        file.type = "attachment"
                        node.addFile(file)
                    else:
                        # import attachment file into existing attachment directory
                        file = importFileIntoDir(getImportDir() + "/" + attpath, uploadfile.tempname) # add new file
                    node.set("system.version.comment", '('+t(req, "edit_files_new_version_attachment_comment")+')\n'+req.params.get('version_comment', ''))
                    pass

        elif op == "addthumb":  # create new thumbanil from uploaded file
            uploadfile = req.params.get("updatefile")

            if uploadfile:
                thumbname = os.path.join(getImportDir(), hashlib.md5(str(random.random())).hexdigest()[0:8]) + ".thumb"

                file = importFile(thumbname, uploadfile.tempname)  # add new file
                makeThumbNail(file.retrieveFile(), thumbname)
                makePresentationFormat(file.retrieveFile(), thumbname + "2")

                if os.path.exists(file.retrieveFile()):  # remove uploaded original
                    os.remove(file.retrieveFile())

                for f in node.getFiles():
                    if f.type in ["thumb", "presentation", "presentati"]:
                        if os.path.exists(f.retrieveFile()):
                            os.remove(f.retrieveFile())
                        node.removeFile(f)

                node.addFile(tree.FileNode(name=thumbname, type="thumb", mimetype="image/jpeg"))
                node.addFile(tree.FileNode(name=thumbname + "2", type="presentation", mimetype="image/jpeg"))
                logging.getLogger('usertracing').info(user.name + " changed thumbnail of node " + node.id)

        elif op == "postprocess":
            if hasattr(node, "event_files_changed"):
                try:
                    node.event_files_changed()
                    logging.getLogger('usertracing').info(user.name + " postprocesses node " + node.id)
                except:
                    update_error = True

    v = {"id": req.params.get("id", "0"), "tab": req.params.get("tab", ""), "node": node, "update_error": update_error,
         "user": user, "files": filter(lambda x: x.type != 'statistic', node.getFiles()),
         "statfiles": filter(lambda x: x.type == 'statistic', node.getFiles()),
         "attfiles": filter(lambda x: x.type == 'attachment', node.getFiles()), "att": [], "nodes": [node], "access": access}

    for f in v["attfiles"]:  # collect all files in attachment directory
        if f.getMimeType() == "inode/directory":
            for root, dirs, files in os.walk(f.retrieveFile()):
                for name in files:
                    af = tree.FileNode(root + "/" + name, "attachmentfile", getMimeType(name)[0])
                    v["att"].append(af)

    return req.getTAL("web/edit/modules/files.html", v, macro="edit_files_file")
Exemple #4
0
    def event_files_changed(self):
        for f in self.getFiles():
            if f.type in ["thumb", "presentation"]:
                self.removeFile(f)

        nodefiles = self.getFiles()
        if len(nodefiles) == 1 and nodefiles[0].mimetype == "video/quicktime":
            if nodefiles[0].retrieveFile().endswith(
                    '.mov'):  # handle mov -> flv
                flvname = "%sflv" % nodefiles[0].retrieveFile()[:-3]
                ret = os.system(
                    "ffmpeg -loglevel quiet -i %s -ar 44100 -ab 128 -f flv %s"
                    % (nodefiles[0].retrieveFile(), flvname))
                if ret & 0xff00:
                    return
                self.addFile(
                    FileNode(name=flvname,
                             type="video",
                             mimetype="video/x-flv"))

        #fetch tags to be omitted
        unwanted_attrs = self.unwanted_attributes()

        for f in self.getFiles():
            if f.type in ["original", "video"]:
                if f.mimetype == "video/x-flv":
                    meta = FLVReader(f.retrieveFile())
                    for key in meta:
                        if any(tag in key for tag in unwanted_attrs):
                            continue
                        try:
                            self.set(key, int(meta[key]))
                        except:
                            self.set(key, meta[key])

                    self.set("vid-width", self.get("width"))
                    self.set("vid-height", self.get("height"))

                    tempname = os.path.join(config.get("paths.tempdir"),
                                            "tmp.gif")
                    try:
                        os.unlink(tempname)
                    except:
                        pass

                    try:
                        if self.get("system.thumbframe") != "":
                            cmd = "ffmpeg -loglevel quiet  -ss %s -i %s -vframes 1 -pix_fmt rgb24 %s" % (
                                self.get("system.thumbframe"),
                                f.retrieveFile(), tempname)
                        else:
                            cmd = "ffmpeg -loglevel quiet -i %s -vframes 1 -pix_fmt rgb24 %s" % (
                                f.retrieveFile(), tempname)
                        ret = os.system(cmd)
                        if ret & 0xff00:
                            return
                    except:
                        return
                    path, ext = splitfilename(f.retrieveFile())
                    thumbname = path + ".thumb"
                    thumbname2 = path + ".thumb2"
                    makeThumbNail(tempname, thumbname)
                    makePresentationFormat(tempname, thumbname2)
                    self.addFile(
                        FileNode(name=thumbname,
                                 type="thumb",
                                 mimetype="image/jpeg"))
                    self.addFile(
                        FileNode(name=thumbname2,
                                 type="presentation",
                                 mimetype="image/jpeg"))
Exemple #5
0
def getContent(req, ids):
    ret = ""
    user = users.getUserFromRequest(req)
    node = tree.getNode(ids[0])
    update_error = False
    access = acl.AccessData(req)

    msg = "%s|web.edit.modules.files.getContend|req.fullpath=%r|req.path=%r|req.params=%r|ids=%r" % (
        get_user_id(req), req.fullpath, req.path, req.params, ids)
    log.debug(msg)

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

    if 'data' in req.params:
        if req.params.get(
                'data'
        ) == 'children':  # get formated list of childnodes of selected directory
            req.writeTAL("web/edit/modules/files.html",
                         {'children': node.getChildren()},
                         macro="edit_files_popup_children")

        if req.params.get(
                'data') == 'additems':  # add selected node as children
            for childid in req.params.get('items').split(";"):
                if childid.strip() != "":
                    childnode = tree.getNode(childid.strip())
                    for p in childnode.getParents():
                        p.removeChild(childnode)
                    node.addChild(childnode)
            req.writeTAL("web/edit/modules/files.html", {
                'children': node.getChildren(),
                'node': node
            },
                         macro="edit_files_children_list")

        if req.params.get(
                'data') == 'removeitem':  # remove selected childnode node
            try:
                remnode = tree.getNode(req.params.get('remove'))
                if len(remnode.getParents()) == 1:
                    users.getUploadDir(user).addChild(remnode)
                node.removeChild(remnode)
            except:  # node not found
                pass
            req.writeTAL("web/edit/modules/files.html", {
                'children': node.getChildren(),
                'node': node
            },
                         macro="edit_files_children_list")

        if req.params.get('data') == 'reorder':
            i = 0
            for id in req.params.get('order').split(","):
                if id != "":
                    n = tree.getNode(id)
                    n.setOrderPos(i)
                    i += 1

        if req.params.get('data') == 'translate':
            req.writeTALstr(
                '<tal:block i18n:translate="" tal:content="msgstr"/>',
                {'msgstr': req.params.get('msgstr')})
        return ""

    if req.params.get("style") == "popup":
        v = {"basedirs": [tree.getRoot('home'), tree.getRoot('collections')]}
        id = req.params.get("id", tree.getRoot().id)
        v["script"] = "var currentitem = '%s';\nvar currentfolder = '%s';\nvar node = %s;" % (
            id, req.params.get('parent'), id)
        v["idstr"] = ",".join(ids)
        v["node"] = node
        req.writeTAL("web/edit/modules/files.html",
                     v,
                     macro="edit_files_popup_selection")
        return ""

    if "operation" in req.params:
        op = req.params.get("operation")
        if op == "delete":
            for key in req.params.keys():  # delete file
                if key.startswith("del|"):
                    filename = key[4:-2].split("|")
                    for file in node.getFiles():
                        if file.getName(
                        ) == filename[1] and file.type == filename[0]:
                            # remove all files in directory
                            if file.getMimeType() == "inode/directory":
                                for root, dirs, files in os.walk(
                                        file.retrieveFile()):
                                    for name in files:
                                        try:
                                            os.remove(root + "/" + name)
                                        except:
                                            pass
                                    os.removedirs(file.retrieveFile() + "/")
                            if len([
                                    f for f in node.getFiles() if f.getName()
                                    == filename[1] and f.type == filename[0]
                            ]) > 1:
                                # remove single file from database if there are duplicates
                                node.removeFile(file, single=True)
                            else:
                                # remove single file
                                node.removeFile(file)
                                try:
                                    os.remove(file.retrieveFile())
                                except:
                                    pass
                            break
                    break
                elif key.startswith("delatt|"):
                    for file in node.getFiles():
                        if file.getMimeType() == "inode/directory":
                            try:
                                os.remove(file.retrieveFile() + "/" +
                                          key.split("|")[2][:-2])
                            except:
                                pass
                            break
                    break

        elif op == "change":
            uploadfile = req.params.get("updatefile")

            if uploadfile:
                create_version_error = False
                # Create new version when change file
                if (req.params.get('generate_new_version')
                        and not hasattr(node, "metaFields")):
                    if (req.params.get('version_comment', '').strip() == ''
                            or req.params.get('version_comment',
                                              '').strip() == '&nbsp;'):
                        create_version_error = True
                        req.setStatus(httpstatus.HTTP_INTERNAL_SERVER_ERROR)
                        ret += req.getTAL("web/edit/modules/files.html", {},
                                          macro="version_error")
                    else:
                        current = node
                        node = node.createNewVersion(user)

                        for attr, value in current.items():
                            if node.get(
                                    attr) != "":  # do not overwrite attributes
                                pass
                            else:
                                node.set(attr, value)
                        req.setStatus(httpstatus.HTTP_MOVED_TEMPORARILY)
                        ret += req.getTAL("web/edit/modules/metadata.html", {
                            'url': '?id=' + node.id + '&tab=files',
                            'pid': None
                        },
                                          macro="redirect")

                if req.params.get(
                        "change_file"
                ) == "yes" and not create_version_error:  # remove old files
                    for f in node.getFiles():
                        if f.getType() in node.getSysFiles():
                            node.removeFile(f)
                    node.set(
                        "system.version.comment", '(' +
                        t(req, "edit_files_new_version_exchanging_comment") +
                        ')\n' + req.params.get('version_comment', ''))

                if req.params.get(
                        "change_file") == "no" and not create_version_error:
                    node.set(
                        "system.version.comment",
                        '(' + t(req, "edit_files_new_version_adding_comment") +
                        ')\n' + req.params.get('version_comment', ''))

                if req.params.get("change_file") in [
                        "yes", "no"
                ] and not create_version_error:
                    file = importFile(uploadfile.filename,
                                      uploadfile.tempname)  # add new file
                    node.addFile(file)
                    logging.getLogger('usertracing').info(
                        user.name + " changed file of node " + node.id +
                        " to " + uploadfile.filename + " (" +
                        uploadfile.tempname + ")")

                attpath = ""
                for f in node.getFiles():
                    if f.getMimeType() == "inode/directory":
                        attpath = f.getName()
                        break

                if req.params.get(
                        "change_file"
                ) == "attdir" and not create_version_error:  # add attachmentdir
                    dirname = req.params.get("inputname")

                    if attpath == "":  # add attachment directory
                        attpath = req.params.get("inputname")
                        if not os.path.exists(getImportDir() + "/" + attpath):
                            os.mkdir(getImportDir() + "/" + attpath)
                            node.addFile(
                                tree.FileNode(name=getImportDir() + "/" +
                                              attpath,
                                              mimetype="inode/directory",
                                              type="attachment"))

                        file = importFileIntoDir(
                            getImportDir() + "/" + attpath,
                            uploadfile.tempname)  # add new file
                    node.set(
                        "system.version.comment", '(' + t(
                            req,
                            "edit_files_new_version_attachment_directory_comment"
                        ) + ')\n' + req.params.get('version_comment', ''))
                    pass

                if req.params.get(
                        "change_file"
                ) == "attfile" and not create_version_error:  # add file as attachment
                    if attpath == "":
                        # no attachment directory existing
                        file = importFile(uploadfile.filename,
                                          uploadfile.tempname)  # add new file
                        file.mimetype = "inode/file"
                        file.type = "attachment"
                        node.addFile(file)
                    else:
                        # import attachment file into existing attachment directory
                        file = importFileIntoDir(
                            getImportDir() + "/" + attpath,
                            uploadfile.tempname)  # add new file
                    node.set(
                        "system.version.comment", '(' +
                        t(req, "edit_files_new_version_attachment_comment") +
                        ')\n' + req.params.get('version_comment', ''))
                    pass

        elif op == "addthumb":  # create new thumbanil from uploaded file
            uploadfile = req.params.get("updatefile")

            if uploadfile:
                thumbname = os.path.join(
                    getImportDir(),
                    hashlib.md5(str(
                        random.random())).hexdigest()[0:8]) + ".thumb"

                file = importFile(thumbname,
                                  uploadfile.tempname)  # add new file
                makeThumbNail(file.retrieveFile(), thumbname)
                makePresentationFormat(file.retrieveFile(), thumbname + "2")

                if os.path.exists(
                        file.retrieveFile()):  # remove uploaded original
                    os.remove(file.retrieveFile())

                for f in node.getFiles():
                    if f.type in ["thumb", "presentation", "presentati"]:
                        if os.path.exists(f.retrieveFile()):
                            os.remove(f.retrieveFile())
                        node.removeFile(f)

                node.addFile(
                    tree.FileNode(name=thumbname,
                                  type="thumb",
                                  mimetype="image/jpeg"))
                node.addFile(
                    tree.FileNode(name=thumbname + "2",
                                  type="presentation",
                                  mimetype="image/jpeg"))
                logging.getLogger('usertracing').info(
                    user.name + " changed thumbnail of node " + node.id)

        elif op == "postprocess":
            if hasattr(node, "event_files_changed"):
                try:
                    node.event_files_changed()
                    logging.getLogger('usertracing').info(
                        user.name + " postprocesses node " + node.id)
                except:
                    update_error = True

    v = {
        "id": req.params.get("id", "0"),
        "tab": req.params.get("tab", ""),
        "node": node,
        "update_error": update_error,
        "user": user,
        "files": filter(lambda x: x.type != 'statistic', node.getFiles()),
        "statfiles": filter(lambda x: x.type == 'statistic', node.getFiles()),
        "attfiles": filter(lambda x: x.type == 'attachment', node.getFiles()),
        "att": [],
        "nodes": [node],
        "access": access
    }

    for f in v["attfiles"]:  # collect all files in attachment directory
        if f.getMimeType() == "inode/directory":
            for root, dirs, files in os.walk(f.retrieveFile()):
                for name in files:
                    af = tree.FileNode(root + "/" + name, "attachmentfile",
                                       getMimeType(name)[0])
                    v["att"].append(af)

    return req.getTAL("web/edit/modules/files.html",
                      v,
                      macro="edit_files_file")