diff --git a/tailbone/util.py b/tailbone/util.py index 61fd37c8..aea29342 100644 --- a/tailbone/util.py +++ b/tailbone/util.py @@ -50,6 +50,26 @@ def csrf_token(request, name='_csrf'): return HTML.tag("div", tags.hidden(name, value=token), style="display:none;") +def should_use_buefy(request): + """ + Returns a flag indicating whether or not the current theme supports (and + therefore should use) the Buefy JS library. + """ + # first check theme-specific setting, if one has been defined + theme = request.registry.settings['tailbone.theme'] + buefy = request.rattail_config.getbool('tailbone', 'themes.{}.use_buefy'.format(theme)) + if buefy is not None: + return buefy + + # TODO: should not hard-code this surely, but works for now... + if theme == 'falafel': + return True + + # TODO: probably should not use this fallback? it was the first setting + # i tested with, but is poorly named to say the least + return request.rattail_config.getbool('tailbone', 'grids.use_buefy', default=False) + + def pretty_datetime(config, value): """ Formats a datetime as a "pretty" human-readable string, with a tooltip diff --git a/tailbone/views/core.py b/tailbone/views/core.py index b5ff0574..45047c7b 100644 --- a/tailbone/views/core.py +++ b/tailbone/views/core.py @@ -39,6 +39,7 @@ from pyramid.response import FileResponse from tailbone.db import Session from tailbone.auth import logout_user +from tailbone.util import should_use_buefy class View(object): @@ -78,19 +79,7 @@ class View(object): Returns a flag indicating whether or not the current theme supports (and therefore should use) the Buefy JS library. """ - # first check theme-specific setting, if one has been defined - theme = self.request.registry.settings['tailbone.theme'] - buefy = self.rattail_config.getbool('tailbone', 'themes.{}.use_buefy'.format(theme)) - if buefy is not None: - return buefy - - # TODO: should not hard-code this surely, but works for now... - if theme == 'falafel': - return True - - # TODO: probably should not use this fallback? it was the first setting - # i tested with, but is poorly named to say the least - return self.rattail_config.getbool('tailbone', 'grids.use_buefy', default=False) + return should_use_buefy(self.request) def late_login_user(self): """