diff --git a/src/adhocracy/config/__init__.py b/src/adhocracy/config/__init__.py index db98dd3a0..354a2c230 100644 --- a/src/adhocracy/config/__init__.py +++ b/src/adhocracy/config/__init__.py @@ -19,6 +19,7 @@ 'adhocracy.demo_users': [], 'adhocracy.enable_gender': False, 'adhocracy.export_personal_email': False, + 'adhocracy.external_navigation_base': None, 'adhocracy.feedback_check_instance': True, 'adhocracy.feedback_instance_key': u'feedback', 'adhocracy.feedback_use_categories': True, diff --git a/src/adhocracy/lib/helpers/__init__.py b/src/adhocracy/lib/helpers/__init__.py index 49bd8cf1b..e7fc23fe6 100644 --- a/src/adhocracy/lib/helpers/__init__.py +++ b/src/adhocracy/lib/helpers/__init__.py @@ -45,6 +45,7 @@ from adhocracy.lib.helpers import treatment_helper as treatment from adhocracy.lib.helpers import category_helper as category from adhocracy.lib.helpers import message_helper as message +from adhocracy.lib.helpers import adhocracy_service as adhocracy_service from adhocracy.lib.helpers.fanstatic_helper import (FanstaticNeedHelper, get_socialshareprivacy_url) @@ -178,13 +179,19 @@ def add_rss(title, link): type='application/rss+xml') -def help_link(text, page, anchor=None): - url = base_url('/static/%s.%s', None) +def help_url(page, anchor=None): + if adhocracy_service.instance_staticpages_api_address(): + url = base_url('/static/%s.%s') + else: + url = base_url('/static/%s.%s', None) if anchor is not None: url += "#" + anchor - full_url = url % (page, 'html') - return (u"%s") % (page, full_url, text) + return url % (page, 'html') + + +def help_link(text, page, anchor=None): + url = help_url(page, anchor=anchor) + return (u"%s") % (page, url, text) def get_redirect_url(target=u'login', entity=None, **kwargs): diff --git a/src/adhocracy/lib/helpers/adhocracy_service.py b/src/adhocracy/lib/helpers/adhocracy_service.py index dbb716383..6bb0e404c 100644 --- a/src/adhocracy/lib/helpers/adhocracy_service.py +++ b/src/adhocracy/lib/helpers/adhocracy_service.py @@ -1,10 +1,29 @@ import requests from collections import OrderedDict +from pylons import tmpl_context as c + from adhocracy import config from adhocracy import i18n +def instance_staticpages_api_address(): + if c.instance is not None: + key = 'adhocracy.instance-%s.staticpages.rest_api_address' + return config.get(key % c.instance.key, '') + else: + return '' + + +def staticpages_api_address(): + ret = instance_staticpages_api_address() + if ret == '': + ret = config.get('adhocracy_service.staticpages.rest_api_address', '') + if ret == '': + ret = config.get('adhocracy_service.rest_api_address', '') + return ret + + class RESTAPI(object): """Helper to work with the adhocarcy_service rest api (adhocracy_kotti.mediacenter, adhocracy_kotti.staticpages, plone). @@ -16,9 +35,7 @@ def __init__(self): self.staticpages_api_token = config.get( 'adhocracy_service.staticpages.rest_api_token', config.get('adhocracy_service.rest_api_token', '')) - self.staticpages_api_address = config.get( - 'adhocracy_service.staticpages.rest_api_address', - config.get('adhocracy_service.rest_api_address', '')) + self.staticpages_api_address = staticpages_api_address() self.staticpages_verify = config.get_bool( 'adhocracy_service.staticpages.verify_ssl', config.get_bool('adhocracy_service.verify_ssl', True)) diff --git a/src/adhocracy/lib/helpers/staticpage_helper.py b/src/adhocracy/lib/helpers/staticpage_helper.py index 42c38dca1..11d56220b 100644 --- a/src/adhocracy/lib/helpers/staticpage_helper.py +++ b/src/adhocracy/lib/helpers/staticpage_helper.py @@ -2,18 +2,23 @@ import logging import babel.core +from pylons import tmpl_context as c + from adhocracy import config from adhocracy.lib import cache, staticpage from adhocracy.lib.helpers import url as _url from adhocracy.lib.helpers.adhocracy_service import RESTAPI +from adhocracy.lib.helpers.adhocracy_service import \ + instance_staticpages_api_address log = logging.getLogger(__name__) @cache.memoize('staticpage_url') def url(staticpage, **kwargs): + instance = c.instance if instance_staticpages_api_address() else None pid = staticpage.key - return _url.build(None, 'static', pid, **kwargs) + return _url.build(instance, 'static', pid, **kwargs) def get_lang_info(lang): @@ -56,9 +61,10 @@ def use_external_navigation(): def render_external_navigation(current_key): api = RESTAPI() - base = config.get('adhocracy.kotti_navigation_base', None) + base = config.get('adhocracy.external_navigation_base') result = api.staticpages_get(base=base) nav = result.json() + instance = c.instance if instance_staticpages_api_address() else None if nav is None or not nav.get('children'): log.error('External navigation not found for configured languages') return '' @@ -71,7 +77,7 @@ def render_navigation_item(item, path='', toplevel=False): else: path = item['name'] - url = '/static/%s.html' % path + url = _url.build(instance, 'static', path, format='html') contains_current = (path == current_key) if item['children']: diff --git a/src/adhocracy/templates/error/http.html b/src/adhocracy/templates/error/http.html index 3a96f37ed..f8084d5c7 100644 --- a/src/adhocracy/templates/error/http.html +++ b/src/adhocracy/templates/error/http.html @@ -17,6 +17,7 @@

${_("Error %s") % c.error_code}

%endif %if not c.hide_notify: -

${_("If this error continues to occur, please notify the developers with a description of what you were trying to do.")|n} ${_("An automated email message describing the situation has been sent to our developers.")}

+

${_("If this error continues to occur, please %snotify the developers%s with a description of what you were trying to do.") % tuple(h.help_link('&&', 'imprint').split('&&'))|n} +${_("An automated email message describing the situation has been sent to our developers.")}

%endif diff --git a/src/adhocracy/templates/navigation.html b/src/adhocracy/templates/navigation.html index 68446e167..695fbd272 100644 --- a/src/adhocracy/templates/navigation.html +++ b/src/adhocracy/templates/navigation.html @@ -54,14 +54,14 @@ ${h.staticpage.render_external_navigation(active) | n} %else: - ${nav_link(href=h.base_url('/static/about.html', None), + ${nav_link(href=h.help_url('about'), text=_('About'), a_class='staticlink_about', li_class=_class('about'), id_="nav_about")} - ${nav_link(href=h.base_url('/static/help.html', None), + ${nav_link(href=h.help_url('help'), text=_("Help"), a_class='staticlink_help', li_class=_class('help'), diff --git a/src/adhocracy/templates/user/register_form.html b/src/adhocracy/templates/user/register_form.html index b9932dc67..4344a5a19 100644 --- a/src/adhocracy/templates/user/register_form.html +++ b/src/adhocracy/templates/user/register_form.html @@ -44,7 +44,7 @@

%if c.agree_text is None: - ${_("By registering, you agree with the %s.") % ("%s" % _("Terms and Conditions")) |n} + ${_("By registering, you agree with the %s.") % h.help_link(_("Terms and Conditions"), 'terms') |n} ${_(u"We'll occasionally inform you about important events such as the start of a new participation process via email.")} %else: ${c.agree_text|n}