Skip to content

Commit

Permalink
redirector: invenio.config deprecation
Browse files Browse the repository at this point in the history
* Replaces usage of invenio.config with invenio.base.globals:cfg.
  (addresses inveniosoftware#3106)

Signed-off-by: Leonardo Rossi <[email protected]>
  • Loading branch information
Leonardo Rossi committed Jul 23, 2015
1 parent bdb2b82 commit b5d4bc4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@
(of a collection).
"""

from invenio.config import CFG_SITE_NAME, CFG_SITE_RECORD
from invenio.base.globals import cfg
from invenio.legacy.search_engine import perform_request_search
from invenio.legacy.bibdocfile.api import BibRecDocs, InvenioBibDocFileError


def goto(cc=CFG_SITE_NAME, p='', f='', sf='date', so='d',
def goto(cc=None, p='', f='', sf='date', so='d',
docname='', format=''):
"""
Redirect the user to the latest record in the given collection.
Expand All @@ -41,12 +41,13 @@ def goto(cc=CFG_SITE_NAME, p='', f='', sf='date', so='d',
only a single bibdoc attached to the record will redirect to that
one.
"""
cc = cc or cfg['CFG_SITE_NAME']
recids = perform_request_search(cc=cc, p=p, f=f, sf=sf, so=so)
if recids:
# The first is the most recent because they are sorted by date
# descending.
recid = recids[0]
url = '/%s/%s' % (CFG_SITE_RECORD, recid)
url = '/%s/%s' % (cfg['CFG_SITE_RECORD'], recid)
if format:
bibrecdocs = BibRecDocs(recid)
if not docname:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@

"""Simple plugin to register an internal redirection."""

from invenio.config import CFG_SITE_URL, CFG_SITE_SECURE_URL
from invenio.base.globals import cfg


def goto(url):
"""Redirect to url (assuming it is internal to the system)."""
if url.startswith('/'):
url = CFG_SITE_URL + url
if url.startswith(CFG_SITE_URL) or url.startswith(CFG_SITE_SECURE_URL):
url = cfg['CFG_SITE_URL'] + url
if url.startswith(cfg['CFG_SITE_URL']) or \
url.startswith(cfg['CFG_SITE_SECURE_URL']):
return url

0 comments on commit b5d4bc4

Please sign in to comment.