def getEditModuleHierarchy(typename): _menu = {} menus = {} types = [] for type in loadAllDatatypes(): if type.name == typename: types = [type] break for dtype in types: # get menu for type _items = {} if dtype.name != "root": n = tree.Node("", type=dtype.name) menu_str = getEditMenuString(dtype.name) if menu_str != "": menus[n.type] = parseMenuString(menu_str) _menu = {} _menu[-1] = [] editModules = getEditModules() # modules installed in system for module in editModules: if module.startswith("menu"): active = -1 for m in menus[n.type]: if m.getName().endswith(module): active = menus[n.type].index(m) break if active not in _menu.keys(): _menu[active] = [] _menu[active].append(module) else: active = -1 for m in menus[n.type]: items = m.getItemList() for item in items: if item == module: active = menus[n.type].index(m) if active not in _items.keys(): _items[active] = [] _items[active].append( (module, items.index(item))) break if active == -1: if active not in _items.keys(): _items[active] = [] _items[active].append((module, 0)) for key in _menu.keys(): if key in _items.keys(): items = _items[key] items.sort(lambda x, y: cmp(x[1], y[1])) for item in items: _menu[key].append(item[0]) return _menu
def getEditModuleHierarchy(typename): _menu = {} menus = {} types = [] for type in loadAllDatatypes(): if type.name == typename: types = [type] break for dtype in types: # get menu for type _items = {} if dtype.name != "root": n = tree.Node("", type=dtype.name) menu_str = getEditMenuString(dtype.name) if menu_str != "": menus[n.type] = parseMenuString(menu_str) _menu = {} _menu[-1] = [] editModules = getEditModules() # modules installed in system for module in editModules: if module.startswith("menu"): active = -1 for m in menus[n.type]: if m.getName().endswith(module): active = menus[n.type].index(m) break if active not in _menu.keys(): _menu[active] = [] _menu[active].append(module) else: active = -1 for m in menus[n.type]: items = m.getItemList() for item in items: if item == module: active = menus[n.type].index(m) if active not in _items.keys(): _items[active] = [] _items[active].append((module, items.index(item))) break if active == -1: if active not in _items.keys(): _items[active] = [] _items[active].append((module, 0)) for key in _menu.keys(): if key in _items.keys(): items = _items[key] items.sort(lambda x, y: cmp(x[1], y[1])) for item in items: _menu[key].append(item[0]) return _menu
def view(req): page = req.params.get("page", "") gotopage = req.params.get("gotopage", "") if gotopage == "adminmodules" and req.params.get("changes") == "adminmodules": adminModuleActions(req) elif gotopage == "editmodules" and req.params.get("changes") == "editmodules": editModuleActions(req) v = {} v["gotopage"] = req.params.get("gotopage", "") v["subitem"] = req.params.get("editsubitem", "") if page == "adminmodules": v['mods'] = getAdminModuleHierarchy() v['modinfo'] = getAdminModuleInformation v['required'] = ItemIsRequired return req.getTAL("web/admin/modules/settingsmenu.html", v, macro="view_adminmodules") elif page == "editmodules": if "subitem" not in v or v["subitem"] == "": v["subitem"] = req.params.get("subitem", "") v['mods'] = getEditModuleHierarchy(req.params.get("subitem", "")) v['datatypes'] = [] v["typelongname"] = "" for dtype in loadAllDatatypes(): if dtype.name != "root": n = tree.Node("", type=dtype.name) if hasattr(n, "getEditMenuTabs"): v['datatypes'].append(dtype) if dtype.name == v["subitem"]: v["typelongname"] = dtype.getLongName() modinfo = {} for mod in editModules: if hasattr(editModules[mod], "getInformation"): modinfo[mod] = editModules[mod].getInformation() def getVersion(modname): if modname in modinfo: if "version" in modinfo[modname]: return modinfo[modname]["version"] return "" def isSystem(modname): if modname in modinfo: if "system" in modinfo[modname] and modinfo[modname]["system"] == 1: return 1 return 0 v["getVersion"] = getVersion v["isSystem"] = isSystem return req.getTAL("web/admin/modules/settingsmenu.html", v, macro="view_editmodules") else: return req.getTAL("web/admin/modules/settingsmenu.html", v, macro="view")
def getEditMenuString(ntype, default=0): menu_str = "" for dtype in loadAllDatatypes(): # all known datatypes if dtype.name == ntype: n = tree.Node("", type=dtype.name) menu_str = getRoot().get("edit.menu." + dtype.name) if (menu_str == "" or default == 1) and hasattr(n, "getEditMenuTabs"): menu_str = n.getEditMenuTabs() break return menu_str
def getDatatypes(req, schemes): dtypes = [] datatypes = loadAllDatatypes() for scheme in schemes: for dtype in scheme.getDatatypes(): if dtype not in dtypes: for t in datatypes: if t.getName() == dtype and not elemInList(dtypes, t.getName()): dtypes.append(t) dtypes.sort(lambda x, y: cmp(translate(x.getLongName(), request=req).lower( ), translate(y.getLongName(), request=req).lower())) return dtypes
def getContainerTreeTypes_orig(req): def getDatatypes(req): dtypes = [] for scheme in AccessData(req).filter(loadTypesFromDB()): dtypes += scheme.getDatatypes() return set(dtypes) if len(containertypes) == 0: dtypes = getDatatypes(req) for dtype in loadAllDatatypes(): if dtype.name in dtypes: n = tree.Node("", type=dtype.name) if hasattr(n, "isContainer") and hasattr(n, "isSystemType"): if n.isContainer() and not n.isSystemType(): containertypes.append(dtype) return containertypes
def getContainerTreeTypes(req): """ function only called to fill context menues for editor tree """ global containertypes containertypes = [] def getDatatypes(req): dtypes = [] for scheme in AccessData(req).filter(loadTypesFromDB()): dtypes += scheme.getDatatypes() return set(dtypes) if 1: # len(containertypes)==0: dtypes = getDatatypes(req) for dtype in loadAllDatatypes(): if dtype.name in dtypes: n = tree.Node("", type=dtype.name) if hasattr(n, "isContainer") and hasattr(n, "isSystemType"): if n.isContainer() and not n.isSystemType(): if dtype not in containertypes: containertypes.append(dtype) ct_names = [ct.name for ct in containertypes] # Datatype(key, key, cls.__name__, cls.__module__+'.'+cls.__name__) for key in ["collection", "directory"]: prefix = "bare_" # user should be able to create collection and directory containers to # have a functinal system. in a completly empty mediatum there will be no # metadatatypes (schemata) for those. they are inserted here on-the-fly # as bare_collection, bare_directory if key not in ct_names: containertypes.append( Datatype( prefix + key, prefix + key, "no_class", "generated on-the-fly for editor to provide name for context_menue", ) ) return containertypes
def getContainerTreeTypes(req): ''' function only called to fill context menues for editor tree ''' global containertypes containertypes = [] def getDatatypes(req): dtypes = [] for scheme in AccessData(req).filter(loadTypesFromDB()): dtypes += scheme.getDatatypes() return set(dtypes) if 1: # len(containertypes)==0: dtypes = getDatatypes(req) for dtype in loadAllDatatypes(): if dtype.name in dtypes: n = tree.Node("", type=dtype.name) if hasattr(n, "isContainer") and hasattr(n, "isSystemType"): if n.isContainer() and not n.isSystemType(): if dtype not in containertypes: containertypes.append(dtype) ct_names = [ct.name for ct in containertypes] # Datatype(key, key, cls.__name__, cls.__module__+'.'+cls.__name__) for key in ['collection', 'directory']: prefix = 'bare_' # user should be able to create collection and directory containers to # have a functinal system. in a completly empty mediatum there will be no # metadatatypes (schemata) for those. they are inserted here on-the-fly # as bare_collection, bare_directory if key not in ct_names: containertypes.append(Datatype(prefix + key, prefix + key, 'no_class', 'generated on-the-fly for editor to provide name for context_menue')) return containertypes
def getContent(req, ids): user = users.getUserFromRequest(req) node = tree.getNode(ids[0]) access = acl.AccessData(req) if not access.hasWriteAccess( node) or "changeschema" in users.getHideMenusForUser(user): req.setStatus(httpstatus.HTTP_FORBIDDEN) return req.getTAL("web/edit/edit.html", {}, macro="access_error") error = req.params.get("error") currentContentType = node.getContentType() try: currentSchema = node.type.split('/')[1] # string except: currentSchema = '' currentCategoryName = node.getCategoryName() currentTypeAlias = node.getTypeAlias() schemes = AccessData(req).filter(loadTypesFromDB()) _schemes = [] for scheme in schemes: if scheme.isActive(): _schemes.append(scheme) schemes = _schemes schemeNames2LongNames = {'': ''} for s in schemes: schemeNames2LongNames[s.getName()] = s.getLongName() try: currentSchemaLongName = schemeNames2LongNames[currentSchema] except KeyError: currentSchemaLongName = '' # find out which schema allows which datatype, and hence, # which overall data types we should display dtypes = [] datatypes = loadAllDatatypes() for scheme in schemes: for dtype in scheme.getDatatypes(): if dtype not in dtypes: for t in datatypes: if t.getName() == dtype and not elemInList( dtypes, t.getName()): dtypes.append(t) dtypes.sort(lambda x, y: cmp( translate(x.getLongName(), request=req).lower(), translate(y.getLongName(), request=req).lower())) admissible_objtypes = getTypes(datatypes) admissible_datatypes = [ n for n in admissible_objtypes if tree.Node('', n.name).getCategoryName() in ['document', 'image', 'video', 'audio'] ] admissible_containers = [ n for n in admissible_objtypes if tree.Node('', n.name).getCategoryName() in ['container'] ] admissible_objtypes.sort(lambda x, y: cmp( translate(x.getLongName(), request=req).lower(), translate(y.getLongName(), request=req).lower())) admissible_datatypes.sort(lambda x, y: cmp( translate(x.getLongName(), request=req).lower(), translate(y.getLongName(), request=req).lower())) admissible_containers.sort(lambda x, y: cmp( translate(x.getLongName(), request=req).lower(), translate(y.getLongName(), request=req).lower())) available_schemes = [ s for s in schemes if currentContentType in s.getDatatypes() ] # filter schemes for special datatypes if req.params.get("objtype", "") != "": _schemes = [] for scheme in schemes: if req.params.get("objtype", "") in scheme.getDatatypes(): _schemes.append(scheme) schemes = _schemes schemes.sort(lambda x, y: cmp( translate(x.getLongName(), request=req).lower(), translate(y.getLongName(), request=req).lower())) newObjectType = req.params.get("objtype") newSchema = req.params.get("schema") if not newSchema: newSchema = '' newType = newObjectType if newSchema: newType += '/' + newSchema oldType = currentContentType if currentSchema: oldType = oldType + '/' + currentSchema if newType != oldType: node.setTypeName(newType) msg = "%s changed node schema for node %s '%s' from '%s' to '%s'" % ( user.name, node.id, node.name, oldType, newType) logger.info(msg) logging.getLogger('usertracing').info(msg) node.setDirty() # cache clean / reload because object type changed tree.remove_from_nodecaches(node) node = tree.getNode(node.id) currentContentType = node.getContentType() currentSchema = newSchema currentSchemaLongName = schemeNames2LongNames[currentSchema] currentCategoryName = node.getCategoryName() currentTypeAlias = node.getTypeAlias() available_schemes = [ s for s in schemes if newObjectType in s.getDatatypes() ] isContainer = False if hasattr(node, "isContainer"): isContainer = node.isContainer() if "action" in req.params.keys(): if req.params.get("action").startswith("get_schemes_for_"): newObjectType = req.params.get("action").replace( "get_schemes_for_", "") available_schemes = [ s for s in schemes if newObjectType in s.getDatatypes() ] req.writeTAL("web/edit/modules/changeschema.html", { 'schemes': available_schemes, 'currentSchema': currentSchema }, macro="changeschema_selectscheme") return "" containers = getContainers(datatypes) d = {"id": req.params.get("id"), "error": error, "node": node} d['currentContentType'] = currentContentType d['currentSchema'] = currentSchema d['currentSchemaLongName'] = currentSchemaLongName d['currentCategoryName'] = currentCategoryName d['currentTypeAlias'] = currentTypeAlias d['isContainer'] = int(isContainer) d['nodes'] = [node] if currentContentType in [dtype.name for dtype in containers]: d['schemes'] = [] d['datatypes'] = admissible_containers # containers else: d['schemes'] = available_schemes d['datatypes'] = admissible_datatypes # dtypes return req.getTAL("web/edit/modules/changeschema.html", d, macro="changeschema_popup")
def getContent(req, ids): user = users.getUserFromRequest(req) node = tree.getNode(ids[0]) access = acl.AccessData(req) if not access.hasWriteAccess(node) or "changeschema" in users.getHideMenusForUser(user): req.setStatus(httpstatus.HTTP_FORBIDDEN) return req.getTAL("web/edit/edit.html", {}, macro="access_error") error = req.params.get("error") currentContentType = node.getContentType() try: currentSchema = node.type.split("/")[1] # string except: currentSchema = "" currentCategoryName = node.getCategoryName() currentTypeAlias = node.getTypeAlias() schemes = AccessData(req).filter(loadTypesFromDB()) _schemes = [] for scheme in schemes: if scheme.isActive(): _schemes.append(scheme) schemes = _schemes schemeNames2LongNames = {"": ""} for s in schemes: schemeNames2LongNames[s.getName()] = s.getLongName() try: currentSchemaLongName = schemeNames2LongNames[currentSchema] except KeyError: currentSchemaLongName = "" # find out which schema allows which datatype, and hence, # which overall data types we should display dtypes = [] datatypes = loadAllDatatypes() for scheme in schemes: for dtype in scheme.getDatatypes(): if dtype not in dtypes: for t in datatypes: if t.getName() == dtype and not elemInList(dtypes, t.getName()): dtypes.append(t) dtypes.sort( lambda x, y: cmp( translate(x.getLongName(), request=req).lower(), translate(y.getLongName(), request=req).lower() ) ) admissible_objtypes = getTypes(datatypes) admissible_datatypes = [ n for n in admissible_objtypes if tree.Node("", n.name).getCategoryName() in ["document", "image", "video", "audio"] ] admissible_containers = [n for n in admissible_objtypes if tree.Node("", n.name).getCategoryName() in ["container"]] admissible_objtypes.sort( lambda x, y: cmp( translate(x.getLongName(), request=req).lower(), translate(y.getLongName(), request=req).lower() ) ) admissible_datatypes.sort( lambda x, y: cmp( translate(x.getLongName(), request=req).lower(), translate(y.getLongName(), request=req).lower() ) ) admissible_containers.sort( lambda x, y: cmp( translate(x.getLongName(), request=req).lower(), translate(y.getLongName(), request=req).lower() ) ) available_schemes = [s for s in schemes if currentContentType in s.getDatatypes()] # filter schemes for special datatypes if req.params.get("objtype", "") != "": _schemes = [] for scheme in schemes: if req.params.get("objtype", "") in scheme.getDatatypes(): _schemes.append(scheme) schemes = _schemes schemes.sort( lambda x, y: cmp( translate(x.getLongName(), request=req).lower(), translate(y.getLongName(), request=req).lower() ) ) newObjectType = req.params.get("objtype") newSchema = req.params.get("schema") if not newSchema: newSchema = "" newType = newObjectType if newSchema: newType += "/" + newSchema oldType = currentContentType if currentSchema: oldType = oldType + "/" + currentSchema if newType != oldType: node.setTypeName(newType) msg = "%s changed node schema for node %s '%s' from '%s' to '%s'" % ( user.name, node.id, node.name, oldType, newType, ) logger.info(msg) logging.getLogger("usertracing").info(msg) node.setDirty() # cache clean / reload because object type changed tree.remove_from_nodecaches(node) node = tree.getNode(node.id) currentContentType = node.getContentType() currentSchema = newSchema currentSchemaLongName = schemeNames2LongNames[currentSchema] currentCategoryName = node.getCategoryName() currentTypeAlias = node.getTypeAlias() available_schemes = [s for s in schemes if newObjectType in s.getDatatypes()] isContainer = False if hasattr(node, "isContainer"): isContainer = node.isContainer() if "action" in req.params.keys(): if req.params.get("action").startswith("get_schemes_for_"): newObjectType = req.params.get("action").replace("get_schemes_for_", "") available_schemes = [s for s in schemes if newObjectType in s.getDatatypes()] req.writeTAL( "web/edit/modules/changeschema.html", {"schemes": available_schemes, "currentSchema": currentSchema}, macro="changeschema_selectscheme", ) return "" containers = getContainers(datatypes) d = {"id": req.params.get("id"), "error": error, "node": node} d["currentContentType"] = currentContentType d["currentSchema"] = currentSchema d["currentSchemaLongName"] = currentSchemaLongName d["currentCategoryName"] = currentCategoryName d["currentTypeAlias"] = currentTypeAlias d["isContainer"] = int(isContainer) d["nodes"] = [node] if currentContentType in [dtype.name for dtype in containers]: d["schemes"] = [] d["datatypes"] = admissible_containers # containers else: d["schemes"] = available_schemes d["datatypes"] = admissible_datatypes # dtypes return req.getTAL("web/edit/modules/changeschema.html", d, macro="changeschema_popup")
def view(req): page = req.params.get("page", "") gotopage = req.params.get("gotopage", "") if gotopage == "adminmodules" and req.params.get( "changes") == "adminmodules": adminModuleActions(req) elif gotopage == "editmodules" and req.params.get( "changes") == "editmodules": editModuleActions(req) v = {} v["gotopage"] = req.params.get("gotopage", "") v["subitem"] = req.params.get("editsubitem", "") if page == "adminmodules": v['mods'] = getAdminModuleHierarchy() v['modinfo'] = getAdminModuleInformation v['required'] = ItemIsRequired return req.getTAL("web/admin/modules/settingsmenu.html", v, macro="view_adminmodules") elif page == "editmodules": if "subitem" not in v or v["subitem"] == "": v["subitem"] = req.params.get("subitem", "") v['mods'] = getEditModuleHierarchy(req.params.get("subitem", "")) v['datatypes'] = [] v["typelongname"] = "" for dtype in loadAllDatatypes(): if dtype.name != "root": n = tree.Node("", type=dtype.name) if hasattr(n, "getEditMenuTabs"): v['datatypes'].append(dtype) if dtype.name == v["subitem"]: v["typelongname"] = dtype.getLongName() modinfo = {} for mod in editModules: if hasattr(editModules[mod], "getInformation"): modinfo[mod] = editModules[mod].getInformation() def getVersion(modname): if modname in modinfo: if "version" in modinfo[modname]: return modinfo[modname]["version"] return "" def isSystem(modname): if modname in modinfo: if "system" in modinfo[modname] and modinfo[modname][ "system"] == 1: return 1 return 0 v["getVersion"] = getVersion v["isSystem"] = isSystem return req.getTAL("web/admin/modules/settingsmenu.html", v, macro="view_editmodules") else: return req.getTAL("web/admin/modules/settingsmenu.html", v, macro="view")
def createView(dbname, viewname, viewsql): if str(dbname) in ["", "None"]: # sqlite try: db.runQuery("DROP VIEW %s;" % viewname) except: pass sql = 'CREATE VIEW `%s` AS %s' % (viewname, viewsql) else: sql = 'CREATE OR REPLACE VIEW `%s`.`%s` AS %s' % (dbname, viewname, viewsql) db.runQuery(sql) print "view '%s' created" % viewname for dtype in loadAllDatatypes(): if dtype.getName() not in ["root", "navitem", "home"]: n = tree.Node("", type=dtype.name) if hasattr(n, "isSystemType") and n.isSystemType() == 0: if hasattr(n, "isContainer") and n.isContainer() == 1: container.append(dtype.name) else: content.append(dtype.name) types = ["'" + "', '".join(container) + "'", "'" + "', '".join(content) + "'"] t = "" for x in content: t += "node.type like '" + x + "%' or " for i in range(0, 2):
def view(req): mtypes = loadTypesFromDB() actfilter = getFilter(req) # filter if actfilter != "": if actfilter in ("all", "*", t(lang(req), "admin_filter_all")): None # all users elif actfilter == "0-9": num = re.compile(r'([0-9])') if req.params.get("filtertype", "") == "id": mtypes = filter(lambda x: num.match(x.getName()), mtypes) else: mtypes = filter(lambda x: num.match(x.getLongName()), mtypes) elif actfilter == "else" or actfilter == t(lang(req), "admin_filter_else"): all = re.compile(r'([a-z]|[A-Z]|[0-9]|\.)') if req.params.get("filtertype", "") == "id": mtypes = filter(lambda x: not all.match(x.getName()), mtypes) else: mtypes = filter(lambda x: not all.match(x.getLongName()), mtypes) else: if req.params.get("filtertype", "") == "id": mtypes = filter(lambda x: x.getName().lower().startswith(actfilter), mtypes) else: mtypes = filter(lambda x: x.getLongName().lower().startswith(actfilter), mtypes) pages = Overview(req, mtypes) order = getSortCol(req) # sorting if order != "": if int(order[0:1]) == 0: mtypes.sort(lambda x, y: cmp(x.getName().lower(), y.getName().lower())) elif int(order[0:1]) == 1: mtypes.sort(lambda x, y: cmp(x.getLongName().lower(), y.getLongName().lower())) elif int(order[0:1]) == 2: mtypes.sort(lambda x, y: cmp(x.getDescription().lower(), y.getDescription().lower())) elif int(order[0:1]) == 3: mtypes.sort(lambda x, y: cmp(x.getActive(), y.getActive())) elif int(order[0:1]) == 4: mtypes.sort(lambda x, y: cmp(x.getDatatypeString().lower(), y.getDatatypeString().lower())) elif int(order[0:1]) == 5: mtypes.sort(lambda x, y: cmp(x.metadatatype.getAccess("read"), y.metadatatype.getAccess("read"))) elif int(order[0:1]) == 6: mtypes.sort(lambda x, y: cmp(x.searchIndexCorrupt(), y.searchIndexCorrupt())) elif int(order[0:1]) == 7: mtypes.sort(lambda x, y: cmp(len(x.getAllItems()), len(y.getAllItems()))) if int(order[1:]) == 1: mtypes.reverse() else: mtypes.sort(lambda x, y: cmp(x.getName().lower(), y.getName().lower())) v = getAdminStdVars(req) v["sortcol"] = pages.OrderColHeader( [ t( lang(req), "admin_meta_col_1"), t( lang(req), "admin_meta_col_2"), t( lang(req), "admin_meta_col_3"), t( lang(req), "admin_meta_col_4"), t( lang(req), "admin_meta_col_5"), t( lang(req), "admin_meta_col_6")]) v["metadatatypes"] = mtypes v["datatypes"] = loadAllDatatypes() v["datatypes"].sort(lambda x, y: cmp(t(lang(req), x.getLongName()), t(lang(req), y.getLongName()))) v["pages"] = pages v["actfilter"] = actfilter v["filterattrs"] = [("id", "admin_metatype_filter_id"), ("name", "admin_metatype_filter_name")] v["filterarg"] = req.params.get("filtertype", "id") return req.getTAL("web/admin/modules/metatype.html", v, macro="view_type")