Skip to content
This repository has been archived by the owner on Jul 11, 2019. It is now read-only.

instance staticpages #845

Merged
merged 5 commits into from
Apr 8, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/adhocracy/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
17 changes: 12 additions & 5 deletions src/adhocracy/lib/helpers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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"<a target='_new' class='staticlink_%s' href='%s' "
u">%s</a>") % (page, full_url, text)
return url % (page, 'html')


def help_link(text, page, anchor=None):
url = help_url(page, anchor=anchor)
return (u"<a class='staticlink_%s' href='%s' >%s</a>") % (page, url, text)


def get_redirect_url(target=u'login', entity=None, **kwargs):
Expand Down
23 changes: 20 additions & 3 deletions src/adhocracy/lib/helpers/adhocracy_service.py
Original file line number Diff line number Diff line change
@@ -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).
Expand All @@ -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))
Expand Down
12 changes: 9 additions & 3 deletions src/adhocracy/lib/helpers/staticpage_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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 ''
Expand All @@ -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']:
Expand Down
3 changes: 2 additions & 1 deletion src/adhocracy/templates/error/http.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ <h2>${_("Error %s") % c.error_code}</h2>
%endif

%if not c.hide_notify:
<p>${_("If this error continues to occur, please <a class='staticlink_imprint' href='/static/imprint.html'>notify the developers</a> with a description of what you were trying to do.")|n} ${_("An automated email message describing the situation has been sent to our developers.")}</p>
<p>${_("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.")}</p>
%endif
</%block>
4 changes: 2 additions & 2 deletions src/adhocracy/templates/navigation.html
Original file line number Diff line number Diff line change
Expand Up @@ -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")}
<!--TODO: remove dummy link to merge in new links with diazo themeing-->
<li id="nav_dummy" style="display: none;"></li>
${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'),
Expand Down
2 changes: 1 addition & 1 deletion src/adhocracy/templates/user/register_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@

<p>
%if c.agree_text is None:
${_("By registering, you agree with the %s.") % ("<a class='staticlink_terms' href='/static/terms.html'>%s</a>" % _("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}
Expand Down