diff --git a/docs/api.rst b/docs/api.rst index 2e82ba566..3b95caad7 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -1,79 +1,80 @@ .. This file is part of Invenio Copyright (C) 2014 CERN. Invenio is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. Invenio is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Invenio; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. .. _api: API === .. toctree:: :maxdepth: 1 base Extensions ---------- .. toctree:: :maxdepth: 1 ext/assets ext/arxiv ext/crossref ext/elasticsearch ext/logging ext/login ext/session ext/sqlalchemy ext/template Modules ------- .. toctree:: :maxdepth: 1 modules/annotations modules/apikeys modules/documentation modules/documents modules/formatter modules/jsonalchemy modules/multimedia modules/oauthclient + modules/redirector modules/tags modules/upgrader modules/uploader modules/workflows Utilities --------- .. toctree:: :maxdepth: 1 utils/datastructures utils/washers Legacy ------ .. toctree:: :maxdepth: 1 legacy/bibrecord diff --git a/docs/api.rst b/docs/modules/redirector.rst similarity index 53% copy from docs/api.rst copy to docs/modules/redirector.rst index 2e82ba566..8ca5b4444 100644 --- a/docs/api.rst +++ b/docs/modules/redirector.rst @@ -1,79 +1,41 @@ .. This file is part of Invenio Copyright (C) 2014 CERN. Invenio is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. Invenio is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Invenio; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. -.. _api: +Redirector +========== -API -=== - -.. toctree:: - :maxdepth: 1 - - base - -Extensions ----------- - -.. toctree:: - :maxdepth: 1 +.. automodule:: invenio.modules.redirector + :members: - ext/assets - ext/arxiv - ext/crossref - ext/elasticsearch - ext/logging - ext/login - ext/session - ext/sqlalchemy - ext/template +Model +----- -Modules -------- +.. automodule:: invenio.modules.redirector.models + :members: -.. toctree:: - :maxdepth: 1 - - modules/annotations - modules/apikeys - modules/documentation - modules/documents - modules/formatter - modules/jsonalchemy - modules/multimedia - modules/oauthclient - modules/tags - modules/upgrader - modules/uploader - modules/workflows - - -Utilities ---------- - -.. toctree:: - :maxdepth: 1 +API +---- - utils/datastructures - utils/washers +.. automodule:: invenio.modules.redirector.api + :members: -Legacy +Manage ------ -.. toctree:: - :maxdepth: 1 +.. automodule:: invenio.modules.redirector.manage + :members: - legacy/bibrecord diff --git a/invenio/legacy/goto/webinterface.py b/invenio/legacy/goto/webinterface.py index 5fbd0e283..b158d154f 100644 --- a/invenio/legacy/goto/webinterface.py +++ b/invenio/legacy/goto/webinterface.py @@ -1,79 +1,81 @@ ## This file is part of Invenio. -## Copyright (C) 2012 CERN. +## Copyright (C) 2012, 2013, 2014 CERN. ## ## Invenio is free software; you can redistribute it and/or ## modify it under the terms of the GNU General Public License as ## published by the Free Software Foundation; either version 2 of the ## License, or (at your option) any later version. ## ## Invenio is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with Invenio; if not, write to the Free Software Foundation, Inc., ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. """ Implements persistent URLs """ import inspect from invenio.config import CFG_SITE_URL from invenio.ext.legacy.handler import WebInterfaceDirectory +from invenio.ext.logging import register_exception +from invenio.legacy.webuser import collect_user_info +from invenio.modules.redirector.api import get_redirection_data +from invenio.modules.redirector.registry import get_redirect_method from invenio.utils.apache import SERVER_RETURN, HTTP_NOT_FOUND from invenio.utils.url import redirect_to_url -from invenio.modules.redirector.api import get_redirection_data -from invenio.legacy.webuser import collect_user_info -from invenio.ext.logging import register_exception + class WebInterfaceGotoPages(WebInterfaceDirectory): def _lookup(self, component, path): try: redirection_data = get_redirection_data(component) - goto_plugin = redirection_data['plugin'] + goto_plugin = get_redirect_method(redirection_data['plugin']) args, dummy_varargs, dummy_varkw, defaults = inspect.getargspec(goto_plugin) args = args and list(args) or [] args.reverse() defaults = defaults and list(defaults) or [] defaults.reverse() params_to_pass = {} for arg, default in map(None, args, defaults): params_to_pass[arg] = default def goto_handler(req, form): ## Let's put what is in the GET query for key, value in dict(form).items(): if key in params_to_pass: params_to_pass[key] = str(value) ## Let's override the params_to_pass to the call with the ## arguments in the configuration configuration_parameters = redirection_data['parameters'] or {} params_to_pass.update(configuration_parameters) ## Let's add default parameters if the plugin expects them if 'component' in params_to_pass: params_to_pass['component'] = component if 'path' in params_to_pass: params_to_pass['path'] = path if 'user_info' in params_to_pass: params_to_pass['user_info'] = collect_user_info(req) if 'req' in params_to_pass: params_to_pass['req'] = req try: new_url = goto_plugin(**params_to_pass) except Exception as err: register_exception(req=req, alert_admin=True) raise SERVER_RETURN(HTTP_NOT_FOUND) if new_url: if new_url.startswith('/'): new_url = CFG_SITE_URL + new_url redirect_to_url(req, new_url) else: raise SERVER_RETURN(HTTP_NOT_FOUND) return goto_handler, [] except ValueError: return None, [] diff --git a/invenio/modules/redirector/__init__.py b/invenio/modules/redirector/__init__.py index eb537e874..d1eae461f 100644 --- a/invenio/modules/redirector/__init__.py +++ b/invenio/modules/redirector/__init__.py @@ -1,18 +1,20 @@ # -*- coding: utf-8 -*- ## ## This file is part of Invenio. -## Copyright (C) 2013 CERN. +## Copyright (C) 2013, 2014 CERN. ## ## Invenio is free software; you can redistribute it and/or ## modify it under the terms of the GNU General Public License as ## published by the Free Software Foundation; either version 2 of the ## License, or (at your option) any later version. ## ## Invenio is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with Invenio; if not, write to the Free Software Foundation, Inc., ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + +"""Init.""" diff --git a/invenio/modules/redirector/api.py b/invenio/modules/redirector/api.py index ac8bf4c78..6f3d7c693 100644 --- a/invenio/modules/redirector/api.py +++ b/invenio/modules/redirector/api.py @@ -1,186 +1,139 @@ # -*- coding: utf-8 -*- -# +## ## This file is part of Invenio. -## Copyright (C) 2012, 2013 CERN. +## Copyright (C) 2012, 2013, 2014 CERN. ## ## Invenio is free software; you can redistribute it and/or ## modify it under the terms of the GNU General Public License as ## published by the Free Software Foundation; either version 2 of the ## License, or (at your option) any later version. ## ## Invenio is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with Invenio; if not, write to the Free Software Foundation, Inc., ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. -""" -Redirecting engine. -""" - -import datetime -from sqlalchemy.exc import IntegrityError +"""Redirecting engine.""" -from invenio.base.utils import autodiscover_redirect_methods from invenio.ext.sqlalchemy import db -from invenio.modules.redirector.models import Goto -from invenio.utils.datastructures import LazyDict -from invenio.utils.json import json, json_unicode_to_utf8 - - -def register_redirect_methods(): - out = {} - for module in autodiscover_redirect_methods(): - if hasattr(module, 'goto'): - out[module.__name__.split('.')[-1]] = module.goto - return out - -REDIRECT_METHODS = LazyDict(register_redirect_methods) +from .models import Goto -def register_redirection(label, plugin, parameters=None, update_on_duplicate=False): +def register_redirection(label, plugin, parameters=None, + update_on_duplicate=False): """ - Register a redirection from /goto/