コード例 #1
0
ファイル: edit.py プロジェクト: hibozzy/mediatum
def getEditModules(force=0):
    if len(editModules) == 0:

        for modpath in core.editmodulepaths:  # paths with edit modules
            path = os.walk(os.path.join(config.basedir, modpath[1]))
            for root, dirs, files in path:
                for name in [f for f in files if f.endswith(".py") and f != "__init__.py"]:
                    try:
                        path, module = splitpath(modpath[1])
                        if modpath[0] == '':
                            m = __import__("web.edit.modules." + name[:-3])
                            m = eval("m.edit.modules." + name[:-3])
                        else:
                            sys.path += [path]
                            m = __import__(
                                module.replace("/", ".") + "." + name[:-3])
                            m = eval("m." + name[:-3])
                        editModules[name[:-3]] = m
                    except ImportError as e:
                        print e
                        logger.error("import error in module " + name[:-3])
                    except SyntaxError:
                        logger.error("syntax error in module " + name[:-3])
                        print sys.exc_info()

    return editModules
コード例 #2
0
ファイル: edit.py プロジェクト: hibozzy/mediatum
def getEditModules(force=0):
    if len(editModules) == 0:

        for modpath in core.editmodulepaths:  # paths with edit modules
            path = os.walk(os.path.join(config.basedir, modpath[1]))
            for root, dirs, files in path:
                for name in [f for f in files if f.endswith(".py") and f != "__init__.py"]:
                    try:
                        path, module = splitpath(modpath[1])
                        if modpath[0] == "":
                            m = __import__("web.edit.modules." + name[:-3])
                            m = eval("m.edit.modules." + name[:-3])
                        else:
                            sys.path += [path]
                            m = __import__(module.replace("/", ".") + "." + name[:-3])
                            m = eval("m." + name[:-3])
                        editModules[name[:-3]] = m
                    except ImportError as e:
                        print e
                        logger.error("import error in module " + name[:-3])
                    except SyntaxError:
                        logger.error("syntax error in module " + name[:-3])
                        print sys.exc_info()

    return editModules
コード例 #3
0
def getAdminModules(path):
    mods = {}
    for root, dirs, files in path:
        if os.path.basename(root) not in ("test", "__pycache__"):
            for name in [
                    f for f in files
                    if f.endswith(".py") and f != "__init__.py"
            ]:
                m = __import__("web.admin.modules." + name[:-3])
                m = eval("m.admin.modules." + name[:-3])
                mods[name[:-3]] = m

    # test for external modules by plugin
    for k, v in config.getsubset("plugins").items():
        path, module = splitpath(v)
        try:
            sys.path += [path + ".adminmodules"]

            for root, dirs, files in os.walk(
                    os.path.join(config.basedir, v + "/adminmodules")):
                for name in [
                        f for f in files
                        if f.endswith(".py") and f != "__init__.py"
                ]:
                    m = __import__(module + ".adminmodules." + name[:-3])
                    m = eval("m.adminmodules." + name[:-3])
                    mods[name[:-3]] = m
        except ImportError:
            pass  # no admin modules in plugin
    return mods
コード例 #4
0
def getEditModuleNames():
    ret = []
    path = os.walk(os.path.join(config.basedir, 'web/edit/modules'))
    for root, dirs, files in path:
        for name in [
                f for f in files if f.endswith(".py") and f != "__init__.py"
        ]:
            ret.append(name[:-3])

    # test for external modules by plugin
    for k, v in config.getsubset("plugins").items():
        path, module = splitpath(v)
        try:
            sys.path += [path + ".editmodules"]

            for root, dirs, files in os.walk(
                    os.path.join(config.basedir, v + "/editmodules")):
                for name in [
                        f for f in files
                        if f.endswith(".py") and f != "__init__.py"
                ]:
                    ret.append(name[:-3])
        except ImportError:
            pass  # no edit modules in plugin
    return ret
コード例 #5
0
ファイル: edit.py プロジェクト: mediatum/mediatum
def getEditModules(force=0):
    if len(editModules) == 0:
        for modpath in core.editmodulepaths:  # paths with edit modules
            if os.path.isabs(modpath[1]):
                mod_dirpath = modpath[1]
            else:
                mod_dirpath = os.path.join(config.basedir, modpath[1])

            walk = os.walk(mod_dirpath)
            for dirpath, subdirs, files in walk:
                if os.path.basename(dirpath) not in ("test", "__pycache__"):
                    for name in [f for f in files if f.endswith(".py") and f != "__init__.py"]:
                        basename = name[:-3]
                        try:
                            path, module = splitpath(mod_dirpath)
                            if not modpath[0]:
                                m = __import__("web.edit.modules." + basename)
                                m = eval("m.edit.modules." + basename)
                            else:
                                sys.path += [path]
                                m = __import__(
                                    module.replace("/", ".") + "." + basename)
                                m = eval("m." + name[:-3])
                            editModules[name[:-3]] = m
                        except ImportError as e:
                            print e
                            logg.exception("import error in module %s", basename)
                        except SyntaxError:
                            logg.exception("syntax error in module %s", basename)

    return editModules
コード例 #6
0
    def __init__(self):
        self.manager = {}
        if config.get("archive.activate", "").lower() == "true":
            print "Initializing archive manager:",
            for paths in config.get("archive.class").split(";"):
                path, manager = splitpath(paths)
                self.manager[manager] = paths

        print "archivemanager init done", len(self.manager)
コード例 #7
0
    def getManager(self, name=""):
        if name == "":
            return self.manager

        if name in self.manager.keys():
            path, manager = splitpath(self.manager[name])
            if path and path not in sys.path:
                sys.path += [path]
            return __import__(manager).__dict__[manager]()
        return None
コード例 #8
0
def getContentStyles(type, name="", contenttype=""):
    name = name.split(";")[0]
    global contentstyles

    if len(contentstyles) == 0:
        styles = {}
        # load standard themes
        for root, dirs, files in os.walk(
                os.path.join(config.basedir, 'web/frontend/styles')):
            for n in [f for f in files if f.endswith(".cfg")]:
                c = readStyleConfig(root + "/" + n)
                styles[c.getID()] = c

        # test for external styles by plugin (default for user types) and theme styles of plugin styles
        for k, v in config.getsubset("plugins").items():
            path, module = splitpath(v)

            if os.path.exists(os.path.join(config.basedir, v)):
                for root, dirs, files in os.walk(
                        os.path.join(config.basedir, v)):
                    for n in [f for f in files if f.endswith(".cfg")]:
                        c = readStyleConfig(root + "/" + n)
                        styles[c.getID()] = c
                    break

            if os.path.exists(
                    os.path.join(config.basedir,
                                 v + "themes/" + theme.getName() + "/styles")):
                for root, dirs, files in os.walk(
                        os.path.join(
                            config.basedir,
                            v + "themes/" + theme.getName() + "/styles")):
                    for n in [f for f in files if f.endswith(".cfg")]:
                        c = readStyleConfig(root + "/" + n)
                        styles[c.getID()] = c

        contentstyles = styles

    if contenttype != "":
        ret = filter(lambda x: x.getContentType() == contenttype,
                     contentstyles.values())
        if len(ret) > 0:
            if name != "":
                return filter(lambda x: x.getName() == name, ret)
            else:
                return ret
        else:
            return []

    if name != "":
        if name in contentstyles.keys():
            return contentstyles[name]
        else:
            return contentstyles.values()[0]
    return filter(lambda x: x.getType() == type, contentstyles.values())
コード例 #9
0
 def open_for_write(self, path, mode):
     path, filename = utils.splitpath(path)
     olddir = self.dir
     oldnode = self.node
     if not self.cwd(path):
         raise IOError("no such directory: " + path)
     filename = config.get("paths.tempdir") + filename
     r = FileWriter(self.node, filename)
     self.dir = olddir
     self.node = oldnode
     return r
コード例 #10
0
 def mkdir(self, path):
     path, filename = utils.splitpath(path)
     olddir = self.dir
     oldnode = self.node
     if not self.cwd(path):
         raise IOError("no such directory: " + path)
     node = self.node
     self.dir = olddir
     self.node = oldnode
     node.addChild(tree.Node(utf8_decode_escape(filename),
                             type="directory"))
コード例 #11
0
ファイル: ftp.py プロジェクト: agromsl/mediatum
 def open_for_write(self, path, mode):
     path, filename = utils.splitpath(path)
     olddir = self.dir
     oldnode = self.node
     if not self.cwd(path):
         raise IOError("no such directory: " + path)
     filename = config.get("paths.tempdir") + filename
     r = FileWriter(self.node, filename)
     self.dir = olddir
     self.node = oldnode
     return r
コード例 #12
0
ファイル: ftp.py プロジェクト: agromsl/mediatum
 def mkdir(self, path):
     path, filename = utils.splitpath(path)
     olddir = self.dir
     oldnode = self.node
     if not self.cwd(path):
         raise IOError("no such directory: " + path)
     node = self.node
     self.dir = olddir
     self.node = oldnode
     node.addChild(tree.Node(utf8_decode_escape(filename),
                             type="directory"))
コード例 #13
0
 def rmdir(self, path):
     path, filename = utils.splitpath(path)
     olddir = self.dir
     oldnode = self.node
     if not self.cwd(path):
         raise IOError("no such directory: " + path)
     try:
         for subdir in self.node.getChildren():
             if subdir.getName() == filename:
                 self.node.removeChild(subdir)
     finally:
         self.dir = olddir
         self.node = oldnode
コード例 #14
0
ファイル: styles.py プロジェクト: agromsl/mediatum
def readStyleConfig(filename):
    path, file = splitpath(filename)
    attrs = {"type": "", "contenttype": "", "name": "", "label": "", "icon": "",
             "template": path.replace(config.basedir, "") + "/", "description": "", "default": ""}
    fi = open(filename, "rb")
    for line in fi:
        if line.find("#") < 0:
            line = line.split("=")
            if line[0].strip() in attrs.keys():
                attrs[line[0].strip()] += line[1].replace("\r", "").replace("\n", "").strip()
    fi.close()
    return ContentStyle(attrs["type"], attrs["contenttype"], attrs["name"], attrs["label"],
                        attrs["icon"], attrs["template"], attrs["default"], attrs["description"])
コード例 #15
0
ファイル: ftp.py プロジェクト: agromsl/mediatum
 def rmdir(self, path):
     path, filename = utils.splitpath(path)
     olddir = self.dir
     oldnode = self.node
     if not self.cwd(path):
         raise IOError("no such directory: " + path)
     try:
         for subdir in self.node.getChildren():
             if subdir.getName() == filename:
                 self.node.removeChild(subdir)
     finally:
         self.dir = olddir
         self.node = oldnode
コード例 #16
0
ファイル: ftp.py プロジェクト: agromsl/mediatum
 def isfile(self, path):
     path, filename = utils.splitpath(path)
     olddir = self.dir
     oldnode = self.node
     result = self.cwd(path)
     if result:
         result = None
         for f in self.node.getFiles():
             if filename == f.getName():
                 result = self.node, f
         for node in self.node.getChildren():
             if filename.replace('(%s) ' % node.id, '') == node.getName():
                 result = self.node, node
     self.dir = olddir
     self.node = oldnode
     return result
コード例 #17
0
 def isfile(self, path):
     path, filename = utils.splitpath(path)
     olddir = self.dir
     oldnode = self.node
     result = self.cwd(path)
     if result:
         result = None
         for f in self.node.getFiles():
             if filename == f.getName():
                 result = self.node, f
         for node in self.node.getChildren():
             if filename.replace('(%s) ' % node.id, '') == node.getName():
                 result = self.node, node
     self.dir = olddir
     self.node = oldnode
     return result
コード例 #18
0
ファイル: styles.py プロジェクト: agromsl/mediatum
def getContentStyles(type, name="", contenttype=""):
    name = name.split(";")[0]
    global contentstyles

    if len(contentstyles) == 0:
        styles = {}
        # load standard themes
        for root, dirs, files in os.walk(os.path.join(config.basedir, 'web/frontend/styles')):
            for n in [f for f in files if f.endswith(".cfg")]:
                c = readStyleConfig(root + "/" + n)
                styles[c.getID()] = c

        # test for external styles by plugin (default for user types) and theme styles of plugin styles
        for k, v in config.getsubset("plugins").items():
            path, module = splitpath(v)

            if os.path.exists(os.path.join(config.basedir, v)):
                for root, dirs, files in os.walk(os.path.join(config.basedir, v)):
                    for n in [f for f in files if f.endswith(".cfg")]:
                        c = readStyleConfig(root + "/" + n)
                        styles[c.getID()] = c
                    break

            if os.path.exists(os.path.join(config.basedir, v + "themes/" + theme.getName() + "/styles")):
                for root, dirs, files in os.walk(os.path.join(config.basedir, v + "themes/" + theme.getName() + "/styles")):
                    for n in [f for f in files if f.endswith(".cfg")]:
                        c = readStyleConfig(root + "/" + n)
                        styles[c.getID()] = c

        contentstyles = styles

    if contenttype != "":
        ret = filter(lambda x: x.getContentType() == contenttype, contentstyles.values())
        if len(ret) > 0:
            if name != "":
                return filter(lambda x: x.getName() == name, ret)
            else:
                return ret
        else:
            return []

    if name != "":
        if name in contentstyles.keys():
            return contentstyles[name]
        else:
            return contentstyles.values()[0]
    return filter(lambda x: x.getType() == type, contentstyles.values())
コード例 #19
0
ファイル: usergroup.py プロジェクト: agromsl/mediatum
def getEditModuleNames():
    ret = []
    path = os.walk(os.path.join(config.basedir, 'web/edit/modules'))
    for root, dirs, files in path:
        for name in [f for f in files if f.endswith(".py") and f != "__init__.py"]:
            ret.append(name[:-3])

    # test for external modules by plugin
    for k, v in config.getsubset("plugins").items():
        path, module = splitpath(v)
        try:
            sys.path += [path + ".editmodules"]

            for root, dirs, files in os.walk(os.path.join(config.basedir, v + "/editmodules")):
                for name in [f for f in files if f.endswith(".py") and f != "__init__.py"]:
                    ret.append(name[:-3])
        except ImportError:
            pass  # no edit modules in plugin
    return ret
コード例 #20
0
ファイル: adminutils.py プロジェクト: mediatum/mediatum
def getAdminModules(path):
    mods = {}
    for root, dirs, files in path:
        if os.path.basename(root) not in ("test", "__pycache__"):
            for name in [f for f in files if f.endswith(".py") and f != "__init__.py"]:
                m = __import__("web.admin.modules." + name[:-3])
                m = eval("m.admin.modules." + name[:-3])
                mods[name[:-3]] = m

    # test for external modules by plugin
    for k, v in config.getsubset("plugins").items():
        path, module = splitpath(v)
        with suppress(ImportError,warn=False): # no admin modules in plugin
            sys.path += [path + ".adminmodules"]
            for root, dirs, files in os.walk(os.path.join(config.basedir, v + "/adminmodules")):
                for name in [f for f in files if f.endswith(".py") and f != "__init__.py"]:
                    m = __import__(module + ".adminmodules." + name[:-3])
                    m = eval("m.adminmodules." + name[:-3])
                    mods[name[:-3]] = m
    return mods
コード例 #21
0
ファイル: adminutils.py プロジェクト: agromsl/mediatum
def getAdminModules(path):
    mods = {}
    for root, dirs, files in path:
        for name in [f for f in files if f.endswith(".py") and f != "__init__.py"]:
            m = __import__("web.admin.modules." + name[:-3])
            m = eval("m.admin.modules." + name[:-3])
            mods[name[:-3]] = m

    # test for external modules by plugin
    for k, v in config.getsubset("plugins").items():
        path, module = splitpath(v)
        try:
            sys.path += [path + ".adminmodules"]

            for root, dirs, files in os.walk(os.path.join(config.basedir, v + "/adminmodules")):
                for name in [f for f in files if f.endswith(".py") and f != "__init__.py"]:
                    m = __import__(module + ".adminmodules." + name[:-3])
                    m = eval("m.adminmodules." + name[:-3])
                    mods[name[:-3]] = m
        except ImportError:
            pass  # no admin modules in plugin
    return mods
コード例 #22
0
def initialize():
    archive_manager = []
    if config.get("archive.activate", "").lower() == "true":
        print "Initializing archive manager:", config.get("archive.activate")
        for paths in config.get("archive.class").split(";"):
            try:
                path, manager = splitpath(paths)
            except:
                pass

            if path and path not in sys.path:
                sys.path += [path]
            m = __import__(manager).__dict__[manager]()
            print str(m.__class__), ",",
            archive_manager.append(m)
        print len(archive_manager), "manager loaded"
    if len(archive_manager) > 0:
        None
        # start archiving thread
        thread_id = thread.start_new_thread(archive_thread, ())
        logg.info("started archiving thread")

        return archive_manager
コード例 #23
0
def readStyleConfig(filename):
    path, file = splitpath(filename)
    attrs = {
        "type": "",
        "contenttype": "",
        "name": "",
        "label": "",
        "icon": "",
        "template": path.replace(config.basedir, "") + "/",
        "description": "",
        "default": ""
    }
    fi = open(filename, "rb")
    for line in fi:
        if line.find("#") < 0:
            line = line.split("=")
            if line[0].strip() in attrs.keys():
                attrs[line[0].strip()] += line[1].replace("\r", "").replace(
                    "\n", "").strip()
    fi.close()
    return ContentStyle(attrs["type"], attrs["contenttype"], attrs["name"],
                        attrs["label"], attrs["icon"], attrs["template"],
                        attrs["default"], attrs["description"])
コード例 #24
0
ファイル: stats.py プロジェクト: hibozzy/mediatum
    def __init__(self, filenode):
        self.items = []
        self.created = None
        self.access = None
        self.currentnodeid = ""

        if filenode:
            self.filenode = filenode
            self.filename = splitpath(filenode.retrieveFile())[1]

            self.period_year = int(self.filename.split("_")[2].split("-")[0])
            self.period_month = int(self.filename.split("_")[2].split("-")[1])
            self.type = self.filename.split("_")[3]

            if os.path.exists(filenode.retrieveFile()):
                fi = open(filenode.retrieveFile(), "r")
                p = xml.parsers.expat.ParserCreate()
                p.StartElementHandler = lambda name, attrs: self.\
                    xml_start_element(name, attrs)
                p.EndElementHandler = lambda name: self.xml_end_element(name)
                p.CharacterDataHandler = lambda d: self.xml_char_data(d)
                p.ParseFile(fi)
                fi.close()
コード例 #25
0
ファイル: stats.py プロジェクト: mediatum/mediatum
    def __init__(self, filenode):
        self.items = []
        self.created = None
        self.access = None
        self.currentnodeid = ""

        if filenode:
            self.filenode = filenode
            self.filename = splitpath(filenode.retrieveFile())[1]

            self.period_year = int(self.filename.split("_")[2].split("-")[0])
            self.period_month = int(self.filename.split("_")[2].split("-")[1])
            self.type = self.filename.split("_")[3]

            if filenode.exists:
                with open(filenode.abspath, "r") as fi:
                    # expat only understands str, so we cannot use codecs here, just plain open()
                    p = xml.parsers.expat.ParserCreate()
                    p.StartElementHandler = lambda name, attrs: self.\
                        xml_start_element(name, attrs)
                    p.EndElementHandler = lambda name: self.xml_end_element(name)
                    p.CharacterDataHandler = lambda d: self.xml_char_data(d)
                    p.ParseFile(fi)
コード例 #26
0
ファイル: stats.py プロジェクト: agromsl/mediatum
    def __init__(self, filenode):
        self.items = []
        self.created = None
        self.access = None
        self.currentnodeid = ""

        if filenode:
            self.filenode = filenode
            self.filename = splitpath(filenode.retrieveFile())[1]

            self.period_year = int(self.filename.split("_")[2].split("-")[0])
            self.period_month = int(self.filename.split("_")[2].split("-")[1])
            self.type = self.filename.split("_")[3]

            if os.path.exists(filenode.retrieveFile()):
                fi = open(filenode.retrieveFile(), "r")
                p = xml.parsers.expat.ParserCreate()
                p.StartElementHandler = lambda name, attrs: self.\
                    xml_start_element(name, attrs)
                p.EndElementHandler = lambda name: self.xml_end_element(name)
                p.CharacterDataHandler = lambda d: self.xml_char_data(d)
                p.ParseFile(fi)
                fi.close()
コード例 #27
0
def getEditModules(force=0):
    if len(editModules) == 0:
        for modpath in core.editmodulepaths:  # paths with edit modules
            if os.path.isabs(modpath[1]):
                mod_dirpath = modpath[1]
            else:
                mod_dirpath = os.path.join(config.basedir, modpath[1])

            walk = os.walk(mod_dirpath)
            for dirpath, subdirs, files in walk:
                if os.path.basename(dirpath) not in ("test", "__pycache__"):
                    for name in [
                            f for f in files
                            if f.endswith(".py") and f != "__init__.py"
                    ]:
                        basename = name[:-3]
                        try:
                            path, module = splitpath(mod_dirpath)
                            if not modpath[0]:
                                m = __import__("web.edit.modules." + basename)
                                m = eval("m.edit.modules." + basename)
                            else:
                                sys.path += [path]
                                m = __import__(
                                    module.replace("/", ".") + "." + basename)
                                m = eval("m." + name[:-3])
                            editModules[name[:-3]] = m
                        except ImportError as e:
                            print e
                            logg.exception("import error in module %s",
                                           basename)
                        except SyntaxError:
                            logg.exception("syntax error in module %s",
                                           basename)

    return editModules
コード例 #28
0
    def __init__(self, filenode):
        self.items = []
        self.created = None
        self.access = None
        self.currentnodeid = ""

        if filenode:
            self.filenode = filenode
            self.filename = splitpath(filenode.retrieveFile())[1]

            self.period_year = int(self.filename.split("_")[2].split("-")[0])
            self.period_month = int(self.filename.split("_")[2].split("-")[1])
            self.type = self.filename.split("_")[3]

            if filenode.exists:
                with open(filenode.abspath, "r") as fi:
                    # expat only understands str, so we cannot use codecs here, just plain open()
                    p = xml.parsers.expat.ParserCreate()
                    p.StartElementHandler = lambda name, attrs: self.\
                        xml_start_element(name, attrs)
                    p.EndElementHandler = lambda name: self.xml_end_element(
                        name)
                    p.CharacterDataHandler = lambda d: self.xml_char_data(d)
                    p.ParseFile(fi)
コード例 #29
0
ファイル: statsaccess.py プロジェクト: agromsl/mediatum
def getPeriod(filename):
    filename = splitpath(filename)[-1]
    period = filename[:-4].split("_")[2]
    type = filename[:-4].split("_")[3]
    return period, type
コード例 #30
0
ファイル: logo.py プロジェクト: mediatum/mediatum
def getContent(req, ids):
    user = current_user
    node = q(Node).get(ids[0])

    if "logo" in current_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")

    # delete logo file
    if "action" in req.params and req.params.get('action') == "delete":
        file = req.params.get('file').split("/")[-1]
        for f in node.files:
            if f.abspath.endswith(file):
                node.files.remove(f)
                db.session.commit()
                req.write('ok')
                return None
        req.write('not found')
        return None

    # add logo file
    if "addfile" in req.params.keys():
        file = req.params.get("updatefile")
        if file:
            mimetype = "application/x-download"
            type = "file"
            mimetype, type = getMimeType(file.filename.lower())

            if mimetype not in ("image/jpeg", "image/gif", "image/png"):
                # wrong file type (jpeg, jpg, gif, png)
                req.setStatus(httpstatus.HTTP_INTERNAL_SERVER_ERROR)
                return req.getTAL("web/edit/modules/logo.html", {}, macro="filetype_error")
            else:
                file = importFile(file.filename, file.tempname)
                node.files.append(file)
                db.session.commit()

    # save logo
    if "logo_save" in req.params.keys():
        # save url
        if req.params.get("logo_link", "") == "":
            if 'url' in node.attrs:
                del node.attrs['url']
        else:
            node.set('url', req.params.get("logo_link"))

        # save filename
        if req.params.get('logo') == "/img/empty.gif":
            # remove logo from current node
            node.set("system.logo", "")
            logg.info("%s cleared logo for node %s (%s, %s)", user.login_name, node.id, node.name, node.type)
        else:
            node.set("system.logo", req.params.get("logo").split("/")[-1])
            logg.info("%s set logo for node %s (%s, %s) to %s", user.login_name, node.id, node.name, node.type, node.get("system.logo"))

        db.session.commit()

    logofiles = []
    for f in node.files:
        if f.filetype == "image":
            logofiles.append(splitpath(f.abspath))
    
    v = {
        "id": req.params.get("id", "0"),
        "tab": req.params.get("tab", ""),
        "node": node,
        "logofiles": logofiles,
        "logo": node.getLogoPath(),
        "language": lang(req),
        "t": translation_t,
        "csrf": req.csrf_token.current_token
    }
         
    return req.getTAL("web/edit/modules/logo.html", v, macro="edit_logo")
コード例 #31
0
ファイル: statsaccess.py プロジェクト: hibozzy/mediatum
def getPeriod(filename):
    filename = splitpath(filename)[-1]
    period = filename[:-4].split("_")[2]
    type = filename[:-4].split("_")[3]
    return period, type
コード例 #32
0
def getContent(req, ids):
    user = current_user
    node = q(Node).get(ids[0])

    if "logo" in current_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")

    # delete logo file
    if "action" in req.params and req.params.get('action') == "delete":
        file = req.params.get('file').split("/")[-1]
        for f in node.files:
            if f.abspath.endswith(file):
                node.files.remove(f)
                db.session.commit()
                req.write('ok')
                return None
        req.write('not found')
        return None

    # add logo file
    if "addfile" in req.params.keys():
        file = req.params.get("updatefile")
        if file:
            mimetype = "application/x-download"
            type = "file"
            mimetype, type = getMimeType(file.filename.lower())

            if mimetype not in ("image/jpeg", "image/gif", "image/png"):
                # wrong file type (jpeg, jpg, gif, png)
                req.setStatus(httpstatus.HTTP_INTERNAL_SERVER_ERROR)
                return req.getTAL("web/edit/modules/logo.html", {},
                                  macro="filetype_error")
            else:
                file = importFile(file.filename, file.tempname)
                node.files.append(file)
                db.session.commit()

    # save logo
    if "logo_save" in req.params.keys():
        # save url
        if req.params.get("logo_link", "") == "":
            if 'url' in node.attrs:
                del node.attrs['url']
        else:
            node.set('url', req.params.get("logo_link"))

        # save filename
        if req.params.get('logo') == "/img/empty.gif":
            # remove logo from current node
            node.set("system.logo", "")
            logg.info("%s cleared logo for node %s (%s, %s)", user.login_name,
                      node.id, node.name, node.type)
        else:
            node.set("system.logo", req.params.get("logo").split("/")[-1])
            logg.info("%s set logo for node %s (%s, %s) to %s",
                      user.login_name, node.id, node.name, node.type,
                      node.get("system.logo"))

        db.session.commit()

    logofiles = []
    for f in node.files:
        if f.filetype == "image":
            logofiles.append(splitpath(f.abspath))

    v = {
        "id": req.params.get("id", "0"),
        "tab": req.params.get("tab", ""),
        "node": node,
        "logofiles": logofiles,
        "logo": node.getLogoPath(),
        "language": lang(req),
        "t": translation_t
    }

    return req.getTAL("web/edit/modules/logo.html", v, macro="edit_logo")
コード例 #33
0
def getContent(req, ids):
    user = users.getUserFromRequest(req)
    node = tree.getNode(ids[0])
    access = acl.AccessData(req)

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

    # delete logo file
    if "action" in req.params and req.params.get('action') == "delete":
        file = req.params.get('file').split("/")[-1]
        for f in node.getFiles():
            if f.retrieveFile().endswith(file):
                node.removeFile(f)
                req.write('ok')
                return None
        req.write('not found')
        return None

    # add logo file
    if "addfile" in req.params.keys():
        file = req.params.get("updatefile")
        if file:
            mimetype = "application/x-download"
            type = "file"
            mimetype, type = getMimeType(file.filename.lower())

            if mimetype not in ("image/jpeg", "image/gif", "image/png"):
                # wrong file type (jpeg, jpg, gif, png)
                req.setStatus(httpstatus.HTTP_INTERNAL_SERVER_ERROR)
                return req.getTAL("web/edit/modules/logo.html", {}, macro="filetype_error")
            else:
                file = importFile(file.filename, file.tempname)
                node.addFile(file)

    # save logo
    if "logo_save" in req.params.keys():
        # save url
        if req.params.get("logo_link", "") == "":
            node.removeAttribute("url")
        else:
            node.set('url', req.params.get("logo_link"))

        # save filename
        if req.params.get('logo') == "/img/empty.gif":
            # remove logo from current node
            node.set("system.logo", "")
            msg = "%s cleared logo for node %r (%r, %r)" % (user.getName(), node.id, node.name, node.type)
            logger.info(msg)
            logger_e.info(msg)
        else:
            node.set("system.logo", req.params.get("logo").split("/")[-1])
            msg = "%s set logo for node %r (%r, %r) to %r" % (user.getName(), node.id, node.name, node.type, node.get("system.logo"))
            logger.info(msg)
            logger_e.info(msg)

    logofiles = []
    for f in node.getFiles():
        if f.getType() == "image":
            logofiles.append(splitpath(f.retrieveFile()))
    
    v = {
        "id": req.params.get("id", "0"),
        "tab": req.params.get("tab", ""),
        "node": node,
        "logofiles": logofiles,
        "logo": node.getLogoPath(),
        "language": lang(req),
        "t": translation_t
    }
         
    return req.getTAL("web/edit/modules/logo.html", v, macro="edit_logo")