def import_new(req): reload(bibtex) user = users.getUserFromRequest(req) importdir= users.getImportDir(user) del req.params["upload"] if "file" in req.params and req.params["doi"]: req.request["Location"] = req.makeLink("content", {"id":importdir.id, "error":"doi_and_bibtex_given"}) req.params["error"] = "doi_and_bibtex_given" msg_t = (user.getName(), importdir.id, importdir.name, importdir.type, req.params["error"]) msg = "%s using import module for node %r (%r, %r): Error: %r" % msg_t logg.info(msg) elif "file" in req.params.keys(): file = req.params["file"] del req.params["file"] if hasattr(file,"filesize") and file.filesize>0: try: bibtex.importBibTeX(file.tempname, importdir, req) req.request["Location"] = req.makeLink("content", {"id":importdir.id}) except ValueError, e: req.request["Location"] = req.makeLink("content", {"id":importdir.id, "error":str(e)}) req.params["error"] = str(e) except bibtex.MissingMapping,e: req.request["Location"] = req.makeLink("content", {"id":importdir.id, "error":str(e)}) req.params["error"] = str(e) except:
def content(req): user = users.getUserFromRequest(req) access = AccessData(req) language = lang(req) if not access.user.isEditor(): return req.writeTAL("web/edit/edit.html", {}, macro="error") if "id" in req.params and len(req.params) == 1: nid = req.params.get("id") try: node = tree.getNode(nid) except: node = None if node: cmd = "cd (%s %r, %r)" % (nid, node.name, node.type) logger.info("%s: %s" % (user.getName(), cmd)) # logging.getLogger("usertracing").info("%s: in editor %s" % (user.getName(), cmd)) else: cmd = "ERROR-cd to non-existing id=%r" % nid logger.error("%s: %s") % (user.getName(), cmd) if "action" in req.params and req.params["action"] == "upload": pass content = {"script": "", "body": ""} v = {"dircontent": "", "notdirectory": 0, "operations": ""} try: v["nodeiconpath"] = getEditorIconPath(node) except: v["nodeiconpath"] = "webtree/directory.gif" path = req.path[1:].split("/") if len(path) >= 4: req.params["style"] = "popup" req.params["id"] = path[1] req.params["tab"] = path[2] req.params["option"] = path[3] getEditModules() if not access.user.isEditor(): return req.writeTAL("web/edit/edit.html", {}, macro="error") # remove all caches for the frontend area- we might make changes there for sessionkey in ["contentarea", "navframe"]: try: del req.session[sessionkey] except: pass ids = getIDs(req) if req.params.get("type", "") == "help" and req.params.get("tab", "") == "upload": return upload_help(req) if len(ids) > 0: node = tree.getNode(ids[0]) tabs = "content" if node.type == "root": tabs = "content" elif node.id == users.getUploadDir(access.getUser()).id: tabs = "upload" elif node.id == users.getImportDir(access.getUser()).id: tabs = "imports" elif hasattr(node, "getDefaultEditTab"): tabs = node.getDefaultEditTab() v["notdirectory"] = 0 current = req.params.get("tab", tabs) logger.debug("... %s inside %s.%s: -> !!! current = %r !!!" % (get_user_id(req), __name__, funcname(), current)) msg = "%s selected editor module is %r" % (user.getName(), current) jsfunc = req.params.get("func", "") if jsfunc: msg = msg + (", js-function: %r" % jsfunc) logger.info(msg) # some tabs operate on only one file # if current in ["files", "view", "upload"]: if current in ["files", "upload"]: ids = ids[0:1] # display current images if not tree.getNode(ids[0]).isContainer(): v["notdirectory"] = 1 items = [] if current != "view": for id in ids: node = tree.getNode(id) if hasattr(node, "show_node_image"): if not isDirectory(node) and not node.isContainer(): items.append((id, node.show_node_image())) else: items.append(("", node.show_node_image())) v["items"] = items logger.debug( "... %s inside %s.%s: -> display current images: items: %r" % (get_user_id(req), __name__, funcname(), [_t[0] for _t in items]) ) try: n = tree.getNode(req.params.get("src", req.params.get("id"))) if current == "metadata" and "save" in req.params: pass s = [] while n: try: s = [ '<a onClick="activateEditorTreeNode(%r); return false;" href="/edit/edit_content?id=%s">%s</a>' % (n.id, n.id, n.getLabel(lang=language)) ] + s except: s = [ '<a onClick="activateEditorTreeNode(%r); return false;" href="/edit/edit_content?id=%s">%s</a>' % (n.id, n.id, n.name) ] + s p = n.getParents() if p: n = p[0] else: n = None v["dircontent"] = " <b>»</b> ".join(s[1:]) except: logger.exception("ERROR displaying current images") else: # or current directory n = tree.getNode(ids[0]) s = [] while n: if len(s) == 0: try: s = ["%s" % (n.getLabel(lang=language))] except: s = ["%s" % (n.name)] else: try: s = [ '<a onClick="activateEditorTreeNode(%r); return false;" href="/edit/edit_content?id=%s">%s</a>' % (n.id, n.id, n.getLabel(lang=language)) ] + s except: s = [ '<a onClick="activateEditorTreeNode(%r); return false;" href="/edit/edit_content?id=%s">%s</a>' % (n.id, n.id, n.name) ] + s p = n.getParents() if p: n = p[0] else: n = None v["dircontent"] = " <b>»</b> ".join(s[1:]) if current == "globals": basedir = config.get("paths.datadir") file_to_edit = None if "file_to_edit" in req.params: file_to_edit = req.params["file_to_edit"] if not file_to_edit: d = node.getStartpageDict() if d and lang(req) in d: file_to_edit = d[lang(req)] found = False for f in node.getFiles(): if f.mimetype == "text/html": filepath = f.retrieveFile().replace(basedir, "") if file_to_edit == filepath: found = True result = edit_editor(req, node, f) if result == "error": logger.error("error editing %r" % f.retrieveFile()) break if not found: edit_editor(req, node, None) elif current == "tab_metadata": edit_metadata(req, ids) # undefined elif current == "tab_upload": edit_upload(req, ids) # undefined elif current == "tab_import": edit_import(req, ids) # undefined elif current == "tab_globals": req.write("") elif current == "tab_lza": edit_lza(req, ids) # undefined elif current == "tab_logo": edit_logo(req, ids) # undefined else: t = current.split("_")[-1] if t in editModules.keys(): c = editModules[t].getContent(req, ids) if c: content["body"] += c # use standard method of module else: logger.debug("empty content") return else: req.setStatus(httpstatus.HTTP_INTERNAL_SERVER_ERROR) content["body"] += req.getTAL("web/edit/edit.html", {"module": current}, macro="module_error") if req.params.get("style", "") != "popup": # normal page with header v["tabs"] = handletabs(req, ids, tabs) v["script"] = content["script"] v["body"] = content["body"] v["paging"] = showPaging(req, current, ids) v["node"] = node v["ids"] = req.params.get("ids", "").split(",") if req.params.get("ids", "") == "": v["ids"] = req.params.get("id", "").split(",") v["tab"] = current v["operations"] = req.getTAL( "web/edit/edit_common.html", {"iscontainer": node.isContainer()}, macro="show_operations" ) user = users.getUserFromRequest(req) v["user"] = user v["language"] = lang(req) v["t"] = translation_t v["spc"] = [Menu("sub_header_frontend", "../", target="_parent")] if user.isAdmin(): v["spc"].append(Menu("sub_header_administration", "../admin", target="_parent")) if user.isWorkflowEditor(): v["spc"].append(Menu("sub_header_workflow", "../publish", target="_parent")) v["spc"].append(Menu("sub_header_logout", "../logout", target="_parent")) # add icons to breadcrumbs ipath = "webtree/directory.gif" if node and node.isContainer(): if node.name == "home" or "Arbeitsverzeichnis" in node.name: ipath = "webtree/homeicon.gif" elif node.name == "Uploads": ipath = "webtree/uploadicon.gif" elif node.name == "Importe": ipath = "webtree/importicon.gif" elif node.name == "Inkonsistente Daten": ipath = "webtree/faultyicon.gif" elif node.name == "Papierkorb": ipath = "webtree/trashicon.gif" else: ipath = getEditorIconPath(node) v["dircontent"] += ' <img src="' + "/img/" + ipath + '" />' return req.writeTAL("web/edit/edit.html", v, macro="frame_content")
def action(req): global editModules access = AccessData(req) language = lang(req) user = users.getUserFromRequest(req) trashdir = users.getTrashDir(user) uploaddir = users.getUploadDir(user) faultydir = users.getFaultyDir(user) importdir = users.getImportDir(user) trashdir_parents = trashdir.getParents() action = req.params.get("action", "") changednodes = {} if not access.user.isEditor(): req.write("""permission denied""") req.setStatus(httpstatus.HTTP_FORBIDDEN) return if "tab" in req.params: tab = req.params.get("tab").split("_")[-1] return editModules[tab].getContent(req, [req.params.get("id")]) if action == "getlabels": nids = req.params.get("ids", []) nids = [nid.strip() for nid in nids.split(",") if nid.strip()] for nid in set(nids + [_n.id for _n in [trashdir, uploaddir, importdir, faultydir]]): try: changednodes[nid] = getTreeLabel(tree.getNode(nid), lang=language) except: msg = "could not make fancytree label for node %r" % nid logger.error(msg) res_dict = {"changednodes": changednodes} req.write(json.dumps(res_dict, indent=4)) return else: # all 'action's except 'getlabels' require a base dir (src) srcid = req.params.get("src") try: src = tree.getNode(srcid) except: req.writeTAL("web/edit/edit.html", {"edit_action_error": srcid}, macro="edit_action_error") return if req.params.get("action") == "addcontainer": node = tree.getNode(srcid) if not access.hasWriteAccess(node): # deliver errorlabel req.writeTALstr('<tal:block i18n:translate="edit_nopermission"/>', {}) return # create new container newnode_type = req.params.get("type") if newnode_type in ["bare_collection", "bare_directory"]: newnode_type = newnode_type.replace("bare_", "") translated_label = t(lang(req), "edit_add_" + newnode_type) if translated_label.startswith("edit_add_"): translated_label = t(lang(req), "edit_add_container_default") + newnode_type newnode = node.addChild(tree.Node(name=translated_label, type=newnode_type)) newnode.set("creator", user.getName()) newnode.set("creationtime", str(time.strftime("%Y-%m-%dT%H:%M:%S", time.localtime(time.time())))) clearFromCache(node) req.params["dest"] = newnode.id # try: # label = newnode.getLabel() # except: # label = newnode.getName() # # c = len(newnode.getContentChildren()) # if c>0: # label += ' <small>(%s)</small>' %(c) label = getTreeLabel(newnode, lang=language) fancytree_nodedata = { "title": label, "key": newnode.id, "isLazy": False, "isFolder": True, "icon": getEditorIconPath(newnode), "readonly": 0, "tooltip": "%s (%s)" % (label, newnode.id), "children": [], } req.write(json.dumps(fancytree_nodedata)) msg = "%s adding new container %r (%r) to %r (%r, %r)" % ( access.user.name, newnode.id, newnode.type, node.id, node.name, node.type, ) logging.getLogger("usertracing").info(msg) logger.info(msg) return try: destid = req.params.get("dest", None) dest = tree.getNode(destid) folderid = destid except: destid = None dest = None folderid = srcid idlist = getIDs(req) mysrc = None errorobj = None # try: if action == "clear_trash": for n in trashdir.getChildren(): # if trashdir is it's sole parent, remove file from disk # attn: this will not touch files from children of deleted # containers if len(n.getParents()) == 1: logger.info( "%s going to remove files from disk for node %r (%r, %r)" % (user.getName(), n.id, n.name, n.type) ) for f in n.getFiles(): # dangerous ??? check this f_path = f.retrieveFile() if os.path.exists(f_path): logger.info("%s going to remove file %r from disk" % (user.getName(), f_path)) os.remove(f_path) trashdir.removeChild(n) dest = trashdir clearFromCache(trashdir) changednodes[trashdir.id] = 1 _parent_descr = [(p.name, p.id, p.type) for p in trashdir_parents] msg = "%s cleared trash folder with id %s, child of %r" % (user.getName(), trashdir.id, _parent_descr) logger.info(msg) logging.getLogger("usertracing").info(msg) # return else: for id in idlist: obj = tree.getNode(id) mysrc = src if isDirectory(obj): mysrc = obj.getParents()[0] if action == "delete": if access.hasWriteAccess(mysrc) and access.hasWriteAccess(obj): if mysrc.id != trashdir.id: mysrc.removeChild(obj) changednodes[mysrc.id] = 1 trashdir.addChild(obj) changednodes[trashdir.id] = 1 clearFromCache(mysrc) logger.info( "%s moved to trash bin %s (%r, %r) from %s (%r, %r)" % (user.getName(), obj.id, obj.name, obj.type, mysrc.id, mysrc.name, mysrc.type) ) logging.getLogger("usertracing").info( "%s removed %s (%r, %r) from %s (%r, %r)" % (user.getName(), obj.id, obj.name, obj.type, mysrc.id, mysrc.name, mysrc.type) ) dest = mysrc else: logger.info("%s has no write access for node %s" % (user.getName(), mysrc.id)) req.writeTALstr('<tal:block i18n:translate="edit_nopermission"/>', {}) dest = mysrc elif action in ["move", "copy"]: if ( dest != mysrc and access.hasWriteAccess(mysrc) and access.hasWriteAccess(dest) and access.hasWriteAccess(obj) and isDirectory(dest) ): if not nodeIsChildOfNode(dest, obj): if action == "move": mysrc.removeChild(obj) changednodes[mysrc.id] = 1 # getLabel(mysrc) dest.addChild(obj) changednodes[dest.id] = 1 # getLabel(dest) clearFromCache(dest) _what = "%s %s %r (%r, %r) " % (access.user.name, action, obj.id, obj.name, obj.type) _from = "from %r (%r, %r) " % (mysrc.id, mysrc.name, mysrc.type) _to = "to %r (%r, %r)" % (dest.id, dest.name, dest.type) msg = _what + _from + _to logging.getLogger("usertracing").info(msg) logger.info(msg) else: logger.error( "%s could not %s %s from %s to %s" % (user.getName(), action, obj.id, mysrc.id, dest.id) ) else: return mysrc = None if not mysrc: mysrc = src if action in ["move", "copy", "delete", "clear_trash"]: for nid in changednodes: try: changednodes[nid] = getTreeLabel(tree.getNode(nid), lang=language) except: msg = "could not make fancytree label for node %r" % nid logger.error(msg) res_dict = {"changednodes": changednodes} req.write(json.dumps(res_dict, indent=4)) else: try: req.write(dest.id) except: req.write("no-node-id-specified (web.edit.edit.action)") logger.warning("no-node-id-specified (web.edit.edit.action)") return
def content(req): user = users.getUserFromRequest(req) access = AccessData(req) language = lang(req) if not access.user.isEditor(): return req.writeTAL("web/edit/edit.html", {}, macro="error") if 'id' in req.params and len(req.params) == 1: nid = req.params.get('id') try: node = tree.getNode(nid) except: node = None if node: cmd = "cd (%s %r, %r)" % (nid, node.name, node.type) logger.info("%s: %s" % (user.getName(), cmd)) #logging.getLogger("usertracing").info("%s: in editor %s" % (user.getName(), cmd)) else: cmd = "ERROR-cd to non-existing id=%r" % nid logger.error("%s: %s") % (user.getName(), cmd) if 'action' in req.params and req.params['action'] == 'upload': pass content = {'script': '', 'body': ''} v = {'dircontent': '', 'notdirectory': 0, 'operations': ''} try: v['nodeiconpath'] = getEditorIconPath(node) except: v['nodeiconpath'] = "webtree/directory.gif" path = req.path[1:].split("/") if len(path) >= 4: req.params["style"] = "popup" req.params["id"] = path[1] req.params["tab"] = path[2] req.params["option"] = path[3] getEditModules() if not access.user.isEditor(): return req.writeTAL("web/edit/edit.html", {}, macro="error") # remove all caches for the frontend area- we might make changes there for sessionkey in ["contentarea", "navframe"]: try: del req.session[sessionkey] except: pass ids = getIDs(req) if req.params.get("type", "") == "help" and req.params.get("tab", "") == "upload": return upload_help(req) if len(ids) > 0: node = tree.getNode(ids[0]) tabs = "content" if node.type == "root": tabs = "content" elif node.id == users.getUploadDir(access.getUser()).id: tabs = "upload" elif node.id == users.getImportDir(access.getUser()).id: tabs = "imports" elif hasattr(node, "getDefaultEditTab"): tabs = node.getDefaultEditTab() v["notdirectory"] = 0 current = req.params.get("tab", tabs) logger.debug("... %s inside %s.%s: -> !!! current = %r !!!" % (get_user_id(req), __name__, funcname(), current)) msg = "%s selected editor module is %r" % (user.getName(), current) jsfunc = req.params.get("func", "") if jsfunc: msg = msg + (', js-function: %r' % jsfunc) logger.info(msg) # some tabs operate on only one file # if current in ["files", "view", "upload"]: if current in ["files", "upload"]: ids = ids[0:1] # display current images if not tree.getNode(ids[0]).isContainer(): v["notdirectory"] = 1 items = [] if current != "view": for id in ids: node = tree.getNode(id) if hasattr(node, "show_node_image"): if not isDirectory(node) and not node.isContainer(): items.append((id, node.show_node_image())) else: items.append(("", node.show_node_image())) v["items"] = items logger.debug("... %s inside %s.%s: -> display current images: items: %r" % (get_user_id(req), __name__, funcname(), [_t[0] for _t in items])) try: n = tree.getNode(req.params.get('src', req.params.get('id'))) if current == 'metadata' and 'save' in req.params: pass s = [] while n: try: s = ['<a onClick="activateEditorTreeNode(%r); return false;" href="/edit/edit_content?id=%s">%s</a>' % (n.id, n.id, n.getLabel(lang=language))] + s except: s = ['<a onClick="activateEditorTreeNode(%r); return false;" href="/edit/edit_content?id=%s">%s</a>' % (n.id, n.id, n.name)] + s p = n.getParents() if p: n = p[0] else: n = None v["dircontent"] = ' <b>»</b> '.join(s[1:]) except: logger.exception('ERROR displaying current images') else: # or current directory n = tree.getNode(ids[0]) s = [] while n: if len(s) == 0: try: s = ['%s' % (n.getLabel(lang=language))] except: s = ['%s' % (n.name)] else: try: s = ['<a onClick="activateEditorTreeNode(%r); return false;" href="/edit/edit_content?id=%s">%s</a>' % (n.id, n.id, n.getLabel(lang=language))] + s except: s = ['<a onClick="activateEditorTreeNode(%r); return false;" href="/edit/edit_content?id=%s">%s</a>' % (n.id, n.id, n.name)] + s p = n.getParents() if p: n = p[0] else: n = None v["dircontent"] = ' <b>»</b> '.join(s[1:]) if current == "globals": basedir = config.get("paths.datadir") file_to_edit = None if "file_to_edit" in req.params: file_to_edit = req.params["file_to_edit"] if not file_to_edit: d = node.getStartpageDict() if d and lang(req) in d: file_to_edit = d[lang(req)] found = False for f in node.getFiles(): if f.mimetype == 'text/html': filepath = f.retrieveFile().replace(basedir, '') if file_to_edit == filepath: found = True result = edit_editor(req, node, f) if result == "error": logger.error("error editing %r" % f.retrieveFile()) break if not found: edit_editor(req, node, None) elif current == "tab_metadata": edit_metadata(req, ids) # undefined elif current == "tab_upload": edit_upload(req, ids) # undefined elif current == "tab_import": edit_import(req, ids) # undefined elif current == "tab_globals": req.write("") elif current == "tab_lza": edit_lza(req, ids) # undefined elif current == "tab_logo": edit_logo(req, ids) # undefined else: t = current.split("_")[-1] if t in editModules.keys(): c = editModules[t].getContent(req, ids) if c: content["body"] += c # use standard method of module else: logger.debug('empty content') return else: req.setStatus(httpstatus.HTTP_INTERNAL_SERVER_ERROR) content["body"] += req.getTAL("web/edit/edit.html", {"module": current}, macro="module_error") if req.params.get("style", "") != "popup": # normal page with header v["tabs"] = handletabs(req, ids, tabs) v["script"] = content["script"] v["body"] = content["body"] v["paging"] = showPaging(req, current, ids) v["node"] = node v["ids"] = req.params.get("ids", "").split(",") if req.params.get("ids", "") == "": v["ids"] = req.params.get("id", "").split(",") v["tab"] = current v["operations"] = req.getTAL("web/edit/edit_common.html", {'iscontainer': node.isContainer()}, macro="show_operations") user = users.getUserFromRequest(req) v['user'] = user v['language'] = lang(req) v['t'] = translation_t v['spc'] = [Menu("sub_header_frontend", "../", target="_parent")] if user.isAdmin(): v['spc'].append(Menu("sub_header_administration", "../admin", target="_parent")) if user.isWorkflowEditor(): v['spc'].append(Menu("sub_header_workflow", "../publish", target="_parent")) v['spc'].append(Menu("sub_header_logout", "../logout", target="_parent")) # add icons to breadcrumbs ipath = 'webtree/directory.gif' if node and node.isContainer(): if node.name == 'home' or 'Arbeitsverzeichnis' in node.name: ipath = 'webtree/homeicon.gif' elif node.name == 'Uploads': ipath = 'webtree/uploadicon.gif' elif node.name == 'Importe': ipath = 'webtree/importicon.gif' elif node.name == 'Inkonsistente Daten': ipath = 'webtree/faultyicon.gif' elif node.name == 'Papierkorb': ipath = 'webtree/trashicon.gif' else: ipath = getEditorIconPath(node) v["dircontent"] += ' <img src="' + '/img/' + ipath + '" />' return req.writeTAL("web/edit/edit.html", v, macro="frame_content")
def action(req): global editModules access = AccessData(req) language = lang(req) user = users.getUserFromRequest(req) trashdir = users.getTrashDir(user) uploaddir = users.getUploadDir(user) faultydir = users.getFaultyDir(user) importdir = users.getImportDir(user) trashdir_parents = trashdir.getParents() action = req.params.get("action", "") changednodes = {} if not access.user.isEditor(): req.write("""permission denied""") req.setStatus(httpstatus.HTTP_FORBIDDEN) return if "tab" in req.params: tab = req.params.get("tab").split("_")[-1] return editModules[tab].getContent(req, [req.params.get("id")]) if action == "getlabels": nids = req.params.get('ids', []) nids = [nid.strip() for nid in nids.split(',') if nid.strip()] for nid in set(nids + [_n.id for _n in [trashdir, uploaddir, importdir, faultydir]]): try: changednodes[nid] = getTreeLabel( tree.getNode(nid), lang=language) except: msg = "could not make fancytree label for node %r" % nid logger.error(msg) res_dict = {'changednodes': changednodes} req.write(json.dumps(res_dict, indent=4)) return else: # all 'action's except 'getlabels' require a base dir (src) srcid = req.params.get("src") try: src = tree.getNode(srcid) except: req.writeTAL( "web/edit/edit.html", {"edit_action_error": srcid}, macro="edit_action_error") return if req.params.get('action') == 'addcontainer': node = tree.getNode(srcid) if not access.hasWriteAccess(node): # deliver errorlabel req.writeTALstr( '<tal:block i18n:translate="edit_nopermission"/>', {}) return # create new container newnode_type = req.params.get('type') if newnode_type in ['bare_collection', 'bare_directory']: newnode_type = newnode_type.replace('bare_', '') translated_label = t(lang(req), 'edit_add_' + newnode_type) if translated_label.startswith('edit_add_'): translated_label = t( lang(req), 'edit_add_container_default') + newnode_type newnode = node.addChild( tree.Node(name=translated_label, type=newnode_type)) newnode.set("creator", user.getName()) newnode.set("creationtime", str( time.strftime('%Y-%m-%dT%H:%M:%S', time.localtime(time.time())))) clearFromCache(node) req.params["dest"] = newnode.id # try: # label = newnode.getLabel() # except: # label = newnode.getName() # # c = len(newnode.getContentChildren()) # if c>0: # label += ' <small>(%s)</small>' %(c) label = getTreeLabel(newnode, lang=language) fancytree_nodedata = { 'title': label, 'key': newnode.id, 'isLazy': False, 'isFolder': True, 'icon': getEditorIconPath(newnode), 'readonly': 0, 'tooltip': '%s (%s)' % (label, newnode.id), 'children': [], } req.write(json.dumps(fancytree_nodedata)) msg = "%s adding new container %r (%r) to %r (%r, %r)" % ( access.user.name, newnode.id, newnode.type, node.id, node.name, node.type) logging.getLogger('usertracing').info(msg) logger.info(msg) return try: destid = req.params.get("dest", None) dest = tree.getNode(destid) folderid = destid except: destid = None dest = None folderid = srcid idlist = getIDs(req) mysrc = None errorobj = None # try: if action == "clear_trash": for n in trashdir.getChildren(): # if trashdir is it's sole parent, remove file from disk # attn: this will not touch files from children of deleted # containers if len(n.getParents()) == 1: logger.info("%s going to remove files from disk for node %r (%r, %r)" % ( user.getName(), n.id, n.name, n.type)) for f in n.getFiles(): # dangerous ??? check this f_path = f.retrieveFile() if os.path.exists(f_path): logger.info( "%s going to remove file %r from disk" % (user.getName(), f_path)) os.remove(f_path) trashdir.removeChild(n) dest = trashdir clearFromCache(trashdir) changednodes[trashdir.id] = 1 _parent_descr = [(p.name, p.id, p.type) for p in trashdir_parents] msg = "%s cleared trash folder with id %s, child of %r" % ( user.getName(), trashdir.id, _parent_descr) logger.info(msg) logging.getLogger('usertracing').info(msg) # return else: for id in idlist: obj = tree.getNode(id) mysrc = src if isDirectory(obj): mysrc = obj.getParents()[0] if action == "delete": if access.hasWriteAccess(mysrc) and access.hasWriteAccess(obj): if mysrc.id != trashdir.id: mysrc.removeChild(obj) changednodes[mysrc.id] = 1 trashdir.addChild(obj) changednodes[trashdir.id] = 1 clearFromCache(mysrc) logger.info("%s moved to trash bin %s (%r, %r) from %s (%r, %r)" % ( user.getName(), obj.id, obj.name, obj.type, mysrc.id, mysrc.name, mysrc.type)) logging.getLogger('usertracing').info("%s removed %s (%r, %r) from %s (%r, %r)" % ( user.getName(), obj.id, obj.name, obj.type, mysrc.id, mysrc.name, mysrc.type)) dest = mysrc else: logger.info( "%s has no write access for node %s" % (user.getName(), mysrc.id)) req.writeTALstr( '<tal:block i18n:translate="edit_nopermission"/>', {}) dest = mysrc elif action in ["move", "copy"]: if dest != mysrc and \ access.hasWriteAccess(mysrc) and \ access.hasWriteAccess(dest) and \ access.hasWriteAccess(obj) and \ isDirectory(dest): if not nodeIsChildOfNode(dest, obj): if action == "move": mysrc.removeChild(obj) changednodes[mysrc.id] = 1 # getLabel(mysrc) dest.addChild(obj) changednodes[dest.id] = 1 # getLabel(dest) clearFromCache(dest) _what = "%s %s %r (%r, %r) " % ( access.user.name, action, obj.id, obj.name, obj.type) _from = "from %r (%r, %r) " % ( mysrc.id, mysrc.name, mysrc.type) _to = "to %r (%r, %r)" % ( dest.id, dest.name, dest.type) msg = _what + _from + _to logging.getLogger('usertracing').info(msg) logger.info(msg) else: logger.error("%s could not %s %s from %s to %s" % ( user.getName(), action, obj.id, mysrc.id, dest.id)) else: return mysrc = None if not mysrc: mysrc = src if action in ["move", "copy", "delete", "clear_trash"]: for nid in changednodes: try: changednodes[nid] = getTreeLabel( tree.getNode(nid), lang=language) except: msg = "could not make fancytree label for node %r" % nid logger.error(msg) res_dict = {'changednodes': changednodes} req.write(json.dumps(res_dict, indent=4)) else: try: req.write(dest.id) except: req.write('no-node-id-specified (web.edit.edit.action)') logger.warning('no-node-id-specified (web.edit.edit.action)') return