Exemplo n.º 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
Exemplo n.º 2
0
def admin_redirects(req):
    check_login(req)
    check_right(req, module_right)

    search = req.args.getfirst('search', fce=nuni)

    pager = Pager(order='value')
    pager.bind(req.args)

    if search:
        pager.set_params(search=search)

    items = Redirect.list(req, pager, search=search)

    return generate_page(req, "admin/redirects.html",
                         token=create_token(req),
                         pager=pager, items=items, search=search)
Exemplo n.º 3
0
 def test_list_disables(self, req, redirect):
     items = Redirect.list(req, Pager(limit=1), state=0)
     assert items[0].src == redirect.src
Exemplo n.º 4
0
 def test_list(self, req, redirect):
     items = Redirect.list(req, Pager(limit=1))
     assert items[0].src == redirect.src