Move logic used to determine if current request should use Buefy

so that function-based views can leverage it also
This commit is contained in:
Lance Edgar 2019-05-21 12:34:18 -05:00
parent fbf3ee5cd1
commit 0f0b32d797
2 changed files with 22 additions and 13 deletions

View file

@ -50,6 +50,26 @@ def csrf_token(request, name='_csrf'):
return HTML.tag("div", tags.hidden(name, value=token), style="display:none;") 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): def pretty_datetime(config, value):
""" """
Formats a datetime as a "pretty" human-readable string, with a tooltip Formats a datetime as a "pretty" human-readable string, with a tooltip

View file

@ -39,6 +39,7 @@ from pyramid.response import FileResponse
from tailbone.db import Session from tailbone.db import Session
from tailbone.auth import logout_user from tailbone.auth import logout_user
from tailbone.util import should_use_buefy
class View(object): class View(object):
@ -78,19 +79,7 @@ class View(object):
Returns a flag indicating whether or not the current theme supports Returns a flag indicating whether or not the current theme supports
(and therefore should use) the Buefy JS library. (and therefore should use) the Buefy JS library.
""" """
# first check theme-specific setting, if one has been defined return should_use_buefy(self.request)
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)
def late_login_user(self): def late_login_user(self):
""" """