示例#1
0
def refresh_links(req, cfg_timestamp, clear=True):
    """ refresh redirect links from db if timestamp is change """
    global timestamp

    check = check_timestamp(req, cfg_timestamp)
    if check > timestamp:       # if last load was in past to timestamp file
        req.log_error("file timestamp is older, loading redirects from DB...",
                      state.LOG_INFO)

        if clear:
            for uri, hdls in app.handlers.items():
                if hdls.get(state.METHOD_GET) == redirect_uri:
                    app.pop_route(uri, state.METHOD_GET)
                    app.pop_route(uri, state.METHOD_HEAD)
        for it in Redirect.list(req, Pager(limit=-1), state=1):
            if it.src[-1] == '$':
                if not app.is_rroute(it.src):
                    req.cfg.log_info("Adding %s -> %s" % (it.src, it.dst))
                    app.set_rroute(it.src, redirect_ruri)
            else:
                if not app.is_route(it.src):
                    req.cfg.log_info("Adding %s -> %s" % (it.src, it.dst))
                    app.set_route(it.src, redirect_uri)

        timestamp = check
示例#2
0
def refresh_menu(req, cfg_timestamp):
    """ refresh menu from db if timestamp is change """
    global timestamp
    global static_menu

    check = check_timestamp(req, cfg_timestamp)
    if check > timestamp:  # if last load was in past to timestamp file
        req.log_error("file timestamp is older, loading menu from DB...", state.LOG_INFO)
        static_menu = MenuItem.get_menu(req)
        timestamp = check
示例#3
0
文件: options.py 项目: ondratu/morias
def refresh_options(req, cfg_timestamp):
    """ refresh options from db when timestamp is change """
    global timestamp

    check = check_timestamp(req, cfg_timestamp)
    if check > timestamp:       # if last load was in past to timestamp file
        req.log_error("file timestamp is older, loading options from DB...",
                      state.LOG_INFO)
        load_options(req)
        timestamp = check
示例#4
0
def refresh_page_files(req, cfg_timestamp, clear=True):
    global timestamp
    check = check_timestamp(req, cfg_timestamp)
    if check > timestamp:       # if last load was in past to timestamp file
        req.log_error("file timestamp is older, refresh page_files ...",
                      state.LOG_INFO)

        if clear:
            for uri, hdls in app.handlers.items():
                if hdls.get(state.METHOD_GET) == runtime_file:
                    app.pop_route(uri, state.METHOD_GET)
                    app.pop_route(uri, state.METHOD_HEAD)

        if req.cfg.pages_index_is_root:
            app.set_route('/', runtime_file)                # / will be index
        if req.cfg.pages_runtime_without_html:
            for it in Page.list(req, Pager(limit=-1)):
                if not it.found:
                    req.cfg.log_error("Page %s not found" % it.name)
                    continue
                name = it.name[:it.name.rfind('.')]
                if name in ('admin', 'user', 'login', 'logout'):
                    req.cfg.log_error('Denied runtime file uri: %s' %
                                      it.name[:-5], state.LOG_ERR)
                    continue
                req.cfg.log_info("Adding /%s" % name)
                app.set_route('/'+name, runtime_file)   # without .html
        else:
            for it in Page.list(req, Pager(limit=-1)):
                if not it.found:
                    req.cfg.log_error("Page %s not found" % it.name)
                    continue
                req.cfg.log_info("Adding /%s" % name)
                # rst not work
                app.set_route('/'+it.name, runtime_file)

        timestamp = check