feat: use wuttaweb for get_liburl()
logic
thankfully this is already handled and we can remove from tailbone. although this adds some new cruft as well, to handle auto-migrating any existing liburl config for apps. eventually once all apps have migrated to new settings we can remove the prefix from our calls here but also in wuttaweb signature
This commit is contained in:
parent
bbc2c584ec
commit
da0f6bd5e1
|
@ -36,11 +36,11 @@ from rattail.db.util import maxlen
|
|||
from webhelpers2.html import *
|
||||
from webhelpers2.html.tags import *
|
||||
|
||||
from wuttaweb.util import get_liburl
|
||||
from tailbone.util import (csrf_token, get_csrf_token,
|
||||
pretty_datetime, raw_datetime,
|
||||
render_markdown,
|
||||
route_exists,
|
||||
get_liburl)
|
||||
route_exists)
|
||||
|
||||
|
||||
def pretty_date(date):
|
||||
|
|
|
@ -149,8 +149,8 @@
|
|||
</${b}-table>
|
||||
|
||||
% for weblib in weblibs:
|
||||
${h.hidden('tailbone.libver.{}'.format(weblib['key']), **{':value': "simpleSettings['tailbone.libver.{}']".format(weblib['key'])})}
|
||||
${h.hidden('tailbone.liburl.{}'.format(weblib['key']), **{':value': "simpleSettings['tailbone.liburl.{}']".format(weblib['key'])})}
|
||||
${h.hidden('wuttaweb.libver.{}'.format(weblib['key']), **{':value': "simpleSettings['wuttaweb.libver.{}']".format(weblib['key'])})}
|
||||
${h.hidden('wuttaweb.liburl.{}'.format(weblib['key']), **{':value': "simpleSettings['wuttaweb.liburl.{}']".format(weblib['key'])})}
|
||||
% endfor
|
||||
|
||||
<${b}-modal has-modal-card
|
||||
|
@ -236,8 +236,8 @@
|
|||
this.editWebLibraryRecord.configured_url = this.editWebLibraryURL
|
||||
this.editWebLibraryRecord.modified = true
|
||||
|
||||
this.simpleSettings[`tailbone.libver.${'$'}{this.editWebLibraryRecord.key}`] = this.editWebLibraryVersion
|
||||
this.simpleSettings[`tailbone.liburl.${'$'}{this.editWebLibraryRecord.key}`] = this.editWebLibraryURL
|
||||
this.simpleSettings[`wuttaweb.libver.${'$'}{this.editWebLibraryRecord.key}`] = this.editWebLibraryVersion
|
||||
this.simpleSettings[`wuttaweb.liburl.${'$'}{this.editWebLibraryRecord.key}`] = this.editWebLibraryURL
|
||||
|
||||
this.settingsNeedSaved = true
|
||||
this.editWebLibraryShowDialog = false
|
||||
|
|
|
@ -122,16 +122,16 @@
|
|||
</%def>
|
||||
|
||||
<%def name="vuejs()">
|
||||
${h.javascript_link(h.get_liburl(request, 'vue'))}
|
||||
${h.javascript_link(h.get_liburl(request, 'vue_resource'))}
|
||||
${h.javascript_link(h.get_liburl(request, 'vue', prefix='tailbone'))}
|
||||
${h.javascript_link(h.get_liburl(request, 'vue_resource', prefix='tailbone'))}
|
||||
</%def>
|
||||
|
||||
<%def name="buefy()">
|
||||
${h.javascript_link(h.get_liburl(request, 'buefy'))}
|
||||
${h.javascript_link(h.get_liburl(request, 'buefy', prefix='tailbone'))}
|
||||
</%def>
|
||||
|
||||
<%def name="fontawesome()">
|
||||
<script defer src="${h.get_liburl(request, 'fontawesome')}"></script>
|
||||
<script defer src="${h.get_liburl(request, 'fontawesome', prefix='tailbone')}"></script>
|
||||
</%def>
|
||||
|
||||
<%def name="extra_javascript()"></%def>
|
||||
|
@ -171,7 +171,7 @@
|
|||
${h.stylesheet_link(user_css)}
|
||||
% else:
|
||||
## upstream Buefy CSS
|
||||
${h.stylesheet_link(h.get_liburl(request, 'buefy.css'))}
|
||||
${h.stylesheet_link(h.get_liburl(request, 'buefy.css', prefix='tailbone'))}
|
||||
% endif
|
||||
</%def>
|
||||
|
||||
|
|
|
@ -71,12 +71,12 @@
|
|||
{
|
||||
## TODO: eventually version / url should be configurable
|
||||
"imports": {
|
||||
"vue": "${h.get_liburl(request, 'bb_vue')}",
|
||||
"@oruga-ui/oruga-next": "${h.get_liburl(request, 'bb_oruga')}",
|
||||
"@oruga-ui/theme-bulma": "${h.get_liburl(request, 'bb_oruga_bulma')}",
|
||||
"@fortawesome/fontawesome-svg-core": "${h.get_liburl(request, 'bb_fontawesome_svg_core')}",
|
||||
"@fortawesome/free-solid-svg-icons": "${h.get_liburl(request, 'bb_free_solid_svg_icons')}",
|
||||
"@fortawesome/vue-fontawesome": "${h.get_liburl(request, 'bb_vue_fontawesome')}"
|
||||
"vue": "${h.get_liburl(request, 'bb_vue', prefix='tailbone')}",
|
||||
"@oruga-ui/oruga-next": "${h.get_liburl(request, 'bb_oruga', prefix='tailbone')}",
|
||||
"@oruga-ui/theme-bulma": "${h.get_liburl(request, 'bb_oruga_bulma', prefix='tailbone')}",
|
||||
"@fortawesome/fontawesome-svg-core": "${h.get_liburl(request, 'bb_fontawesome_svg_core', prefix='tailbone')}",
|
||||
"@fortawesome/free-solid-svg-icons": "${h.get_liburl(request, 'bb_free_solid_svg_icons', prefix='tailbone')}",
|
||||
"@fortawesome/vue-fontawesome": "${h.get_liburl(request, 'bb_vue_fontawesome', prefix='tailbone')}"
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
@ -92,7 +92,7 @@
|
|||
% if user_css:
|
||||
${h.stylesheet_link(user_css)}
|
||||
% else:
|
||||
${h.stylesheet_link(h.get_liburl(request, 'bb_oruga_bulma_css'))}
|
||||
${h.stylesheet_link(h.get_liburl(request, 'bb_oruga_bulma_css', prefix='tailbone'))}
|
||||
% endif
|
||||
</%def>
|
||||
|
||||
|
|
162
tailbone/util.py
162
tailbone/util.py
|
@ -39,7 +39,9 @@ from pyramid.renderers import get_renderer
|
|||
from pyramid.interfaces import IRoutesMapper
|
||||
from webhelpers2.html import HTML, tags
|
||||
|
||||
from wuttaweb.util import get_form_data as wutta_get_form_data
|
||||
from wuttaweb.util import (get_form_data as wutta_get_form_data,
|
||||
get_libver as wutta_get_libver,
|
||||
get_liburl as wutta_get_liburl)
|
||||
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
@ -103,154 +105,32 @@ def get_global_search_options(request):
|
|||
return options
|
||||
|
||||
|
||||
def get_libver(request, key, fallback=True, default_only=False):
|
||||
def get_libver(request, key, fallback=True, default_only=False): # pragma: no cover
|
||||
"""
|
||||
Return the appropriate URL for the library identified by ``key``.
|
||||
DEPRECATED - use :func:`wuttaweb:wuttaweb.util.get_libver()`
|
||||
instead.
|
||||
"""
|
||||
config = request.rattail_config
|
||||
warnings.warn("tailbone.util.get_libver() is deprecated; "
|
||||
"please use wuttaweb.util.get_libver() instead",
|
||||
DeprecationWarning, stacklevel=2)
|
||||
|
||||
if not default_only:
|
||||
version = config.get('tailbone', 'libver.{}'.format(key))
|
||||
if version:
|
||||
return version
|
||||
|
||||
if not fallback and not default_only:
|
||||
|
||||
if key == 'buefy':
|
||||
version = config.get('tailbone', 'buefy_version')
|
||||
if version:
|
||||
return version
|
||||
|
||||
elif key == 'buefy.css':
|
||||
version = get_libver(request, 'buefy', fallback=False)
|
||||
if version:
|
||||
return version
|
||||
|
||||
elif key == 'vue':
|
||||
version = config.get('tailbone', 'vue_version')
|
||||
if version:
|
||||
return version
|
||||
|
||||
return
|
||||
|
||||
if key == 'buefy':
|
||||
if not default_only:
|
||||
version = config.get('tailbone', 'buefy_version')
|
||||
if version:
|
||||
return version
|
||||
return 'latest'
|
||||
|
||||
elif key == 'buefy.css':
|
||||
version = get_libver(request, 'buefy', default_only=default_only)
|
||||
if version:
|
||||
return version
|
||||
return 'latest'
|
||||
|
||||
elif key == 'vue':
|
||||
if not default_only:
|
||||
version = config.get('tailbone', 'vue_version')
|
||||
if version:
|
||||
return version
|
||||
return '2.6.14'
|
||||
|
||||
elif key == 'vue_resource':
|
||||
return 'latest'
|
||||
|
||||
elif key == 'fontawesome':
|
||||
return '5.3.1'
|
||||
|
||||
elif key == 'bb_vue':
|
||||
return '3.4.31'
|
||||
|
||||
elif key == 'bb_oruga':
|
||||
return '0.8.12'
|
||||
|
||||
elif key in ('bb_oruga_bulma', 'bb_oruga_bulma_css'):
|
||||
return '0.3.0'
|
||||
|
||||
elif key == 'bb_fontawesome_svg_core':
|
||||
return '6.5.2'
|
||||
|
||||
elif key == 'bb_free_solid_svg_icons':
|
||||
return '6.5.2'
|
||||
|
||||
elif key == 'bb_vue_fontawesome':
|
||||
return '3.0.6'
|
||||
return wutta_get_libver(request, key, prefix='tailbone',
|
||||
configured_only=not fallback,
|
||||
default_only=default_only)
|
||||
|
||||
|
||||
def get_liburl(request, key, fallback=True):
|
||||
def get_liburl(request, key, fallback=True): # pragma: no cover
|
||||
"""
|
||||
Return the appropriate URL for the library identified by ``key``.
|
||||
DEPRECATED - use :func:`wuttaweb:wuttaweb.util.get_liburl()`
|
||||
instead.
|
||||
"""
|
||||
config = request.rattail_config
|
||||
warnings.warn("tailbone.util.get_liburl() is deprecated; "
|
||||
"please use wuttaweb.util.get_liburl() instead",
|
||||
DeprecationWarning, stacklevel=2)
|
||||
|
||||
url = config.get('tailbone', 'liburl.{}'.format(key))
|
||||
if url:
|
||||
return url
|
||||
|
||||
if not fallback:
|
||||
return
|
||||
|
||||
version = get_libver(request, key)
|
||||
|
||||
static = config.get('tailbone.static_libcache.module')
|
||||
if static:
|
||||
static = importlib.import_module(static)
|
||||
needed = request.environ['fanstatic.needed']
|
||||
liburl = needed.library_url(static.libcache) + '/'
|
||||
# nb. add custom url prefix if needed, e.g. /theo
|
||||
if request.script_name:
|
||||
liburl = request.script_name + liburl
|
||||
|
||||
if key == 'buefy':
|
||||
return 'https://unpkg.com/buefy@{}/dist/buefy.min.js'.format(version)
|
||||
|
||||
elif key == 'buefy.css':
|
||||
return 'https://unpkg.com/buefy@{}/dist/buefy.min.css'.format(version)
|
||||
|
||||
elif key == 'vue':
|
||||
return 'https://unpkg.com/vue@{}/dist/vue.min.js'.format(version)
|
||||
|
||||
elif key == 'vue_resource':
|
||||
return 'https://cdn.jsdelivr.net/npm/vue-resource@{}'.format(version)
|
||||
|
||||
elif key == 'fontawesome':
|
||||
return 'https://use.fontawesome.com/releases/v{}/js/all.js'.format(version)
|
||||
|
||||
elif key == 'bb_vue':
|
||||
if static and hasattr(static, 'bb_vue_js'):
|
||||
return liburl + static.bb_vue_js.relpath
|
||||
return f'https://unpkg.com/vue@{version}/dist/vue.esm-browser.prod.js'
|
||||
|
||||
elif key == 'bb_oruga':
|
||||
if static and hasattr(static, 'bb_oruga_js'):
|
||||
return liburl + static.bb_oruga_js.relpath
|
||||
return f'https://unpkg.com/@oruga-ui/oruga-next@{version}/dist/oruga.mjs'
|
||||
|
||||
elif key == 'bb_oruga_bulma':
|
||||
if static and hasattr(static, 'bb_oruga_bulma_js'):
|
||||
return liburl + static.bb_oruga_bulma_js.relpath
|
||||
return f'https://unpkg.com/@oruga-ui/theme-bulma@{version}/dist/bulma.mjs'
|
||||
|
||||
elif key == 'bb_oruga_bulma_css':
|
||||
if static and hasattr(static, 'bb_oruga_bulma_css'):
|
||||
return liburl + static.bb_oruga_bulma_css.relpath
|
||||
return f'https://unpkg.com/@oruga-ui/theme-bulma@{version}/dist/bulma.css'
|
||||
|
||||
elif key == 'bb_fontawesome_svg_core':
|
||||
if static and hasattr(static, 'bb_fontawesome_svg_core_js'):
|
||||
return liburl + static.bb_fontawesome_svg_core_js.relpath
|
||||
return f'https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-svg-core@{version}/+esm'
|
||||
|
||||
elif key == 'bb_free_solid_svg_icons':
|
||||
if static and hasattr(static, 'bb_free_solid_svg_icons_js'):
|
||||
return liburl + static.bb_free_solid_svg_icons_js.relpath
|
||||
return f'https://cdn.jsdelivr.net/npm/@fortawesome/free-solid-svg-icons@{version}/+esm'
|
||||
|
||||
elif key == 'bb_vue_fontawesome':
|
||||
if static and hasattr(static, 'bb_vue_fontawesome_js'):
|
||||
return liburl + static.bb_vue_fontawesome_js.relpath
|
||||
return f'https://cdn.jsdelivr.net/npm/@fortawesome/vue-fontawesome@{version}/+esm'
|
||||
return wutta_get_liburl(request, key, prefix='tailbone',
|
||||
configured_only=not fallback,
|
||||
default_only=False)
|
||||
|
||||
|
||||
def pretty_datetime(config, value):
|
||||
|
|
|
@ -24,24 +24,23 @@
|
|||
Settings Views
|
||||
"""
|
||||
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
import subprocess
|
||||
import sys
|
||||
from collections import OrderedDict
|
||||
|
||||
import json
|
||||
import colander
|
||||
|
||||
from rattail.db.model import Setting
|
||||
from rattail.settings import Setting as AppSetting
|
||||
from rattail.util import import_module_path
|
||||
|
||||
import colander
|
||||
|
||||
from tailbone import forms
|
||||
from tailbone.db import Session
|
||||
from tailbone.views import MasterView, View
|
||||
from tailbone.util import get_libver, get_liburl
|
||||
from wuttaweb.util import get_libver, get_liburl
|
||||
|
||||
|
||||
class AppInfoView(MasterView):
|
||||
|
@ -99,10 +98,9 @@ class AppInfoView(MasterView):
|
|||
kwargs['configure_button_title'] = "Configure App"
|
||||
return kwargs
|
||||
|
||||
def configure_get_context(self, **kwargs):
|
||||
context = super().configure_get_context(**kwargs)
|
||||
|
||||
weblibs = OrderedDict([
|
||||
def get_weblibs(self):
|
||||
""" """
|
||||
return OrderedDict([
|
||||
('vue', "Vue"),
|
||||
('vue_resource', "vue-resource"),
|
||||
('buefy', "Buefy"),
|
||||
|
@ -117,6 +115,12 @@ class AppInfoView(MasterView):
|
|||
('bb_vue_fontawesome', "(BB) @fortawesome/vue-fontawesome"),
|
||||
])
|
||||
|
||||
def configure_get_context(self, **kwargs):
|
||||
""" """
|
||||
context = super().configure_get_context(**kwargs)
|
||||
simple_settings = context['simple_settings']
|
||||
weblibs = self.get_weblibs()
|
||||
|
||||
for key in weblibs:
|
||||
title = weblibs[key]
|
||||
weblibs[key] = {
|
||||
|
@ -125,19 +129,33 @@ class AppInfoView(MasterView):
|
|||
|
||||
# nb. these values are exactly as configured, and are
|
||||
# used for editing the settings
|
||||
'configured_version': get_libver(self.request, key, fallback=False),
|
||||
'configured_url': get_liburl(self.request, key, fallback=False),
|
||||
'configured_version': get_libver(self.request, key,
|
||||
prefix='tailbone',
|
||||
configured_only=True),
|
||||
'configured_url': get_liburl(self.request, key,
|
||||
prefix='tailbone',
|
||||
configured_only=True),
|
||||
|
||||
# these are for informational purposes only
|
||||
'default_version': get_libver(self.request, key, default_only=True),
|
||||
'live_url': get_liburl(self.request, key),
|
||||
'default_version': get_libver(self.request, key,
|
||||
prefix='tailbone',
|
||||
default_only=True),
|
||||
'live_url': get_liburl(self.request, key,
|
||||
prefix='tailbone'),
|
||||
}
|
||||
|
||||
# TODO: this is only needed to migrate legacy settings to
|
||||
# use the newer wutaweb setting names
|
||||
url = simple_settings[f'wuttaweb.liburl.{key}']
|
||||
if not url and weblibs[key]['configured_url']:
|
||||
simple_settings[f'wuttaweb.liburl.{key}'] = weblibs[key]['configured_url']
|
||||
|
||||
context['weblibs'] = list(weblibs.values())
|
||||
return context
|
||||
|
||||
def configure_get_simple_settings(self):
|
||||
return [
|
||||
""" """
|
||||
simple_settings = [
|
||||
|
||||
# basics
|
||||
{'section': 'rattail',
|
||||
|
@ -167,63 +185,6 @@ class AppInfoView(MasterView):
|
|||
# 'type': int
|
||||
},
|
||||
|
||||
# web libs
|
||||
{'section': 'tailbone',
|
||||
'option': 'libver.vue'},
|
||||
{'section': 'tailbone',
|
||||
'option': 'liburl.vue'},
|
||||
{'section': 'tailbone',
|
||||
'option': 'libver.vue_resource'},
|
||||
{'section': 'tailbone',
|
||||
'option': 'liburl.vue_resource'},
|
||||
{'section': 'tailbone',
|
||||
'option': 'libver.buefy'},
|
||||
{'section': 'tailbone',
|
||||
'option': 'liburl.buefy'},
|
||||
{'section': 'tailbone',
|
||||
'option': 'libver.buefy.css'},
|
||||
{'section': 'tailbone',
|
||||
'option': 'liburl.buefy.css'},
|
||||
{'section': 'tailbone',
|
||||
'option': 'libver.fontawesome'},
|
||||
{'section': 'tailbone',
|
||||
'option': 'liburl.fontawesome'},
|
||||
|
||||
{'section': 'tailbone',
|
||||
'option': 'libver.bb_vue'},
|
||||
{'section': 'tailbone',
|
||||
'option': 'liburl.bb_vue'},
|
||||
|
||||
{'section': 'tailbone',
|
||||
'option': 'libver.bb_oruga'},
|
||||
{'section': 'tailbone',
|
||||
'option': 'liburl.bb_oruga'},
|
||||
|
||||
{'section': 'tailbone',
|
||||
'option': 'libver.bb_oruga_bulma'},
|
||||
{'section': 'tailbone',
|
||||
'option': 'liburl.bb_oruga_bulma'},
|
||||
|
||||
{'section': 'tailbone',
|
||||
'option': 'libver.bb_oruga_bulma_css'},
|
||||
{'section': 'tailbone',
|
||||
'option': 'liburl.bb_oruga_bulma_css'},
|
||||
|
||||
{'section': 'tailbone',
|
||||
'option': 'libver.bb_fontawesome_svg_core'},
|
||||
{'section': 'tailbone',
|
||||
'option': 'liburl.bb_fontawesome_svg_core'},
|
||||
|
||||
{'section': 'tailbone',
|
||||
'option': 'libver.bb_free_solid_svg_icons'},
|
||||
{'section': 'tailbone',
|
||||
'option': 'liburl.bb_free_solid_svg_icons'},
|
||||
|
||||
{'section': 'tailbone',
|
||||
'option': 'libver.bb_vue_fontawesome'},
|
||||
{'section': 'tailbone',
|
||||
'option': 'liburl.bb_vue_fontawesome'},
|
||||
|
||||
# nb. these are no longer used (deprecated), but we keep
|
||||
# them defined here so the tool auto-deletes them
|
||||
{'section': 'tailbone',
|
||||
|
@ -233,6 +194,36 @@ class AppInfoView(MasterView):
|
|||
|
||||
]
|
||||
|
||||
def getval(key):
|
||||
return self.config.get(f'tailbone.{key}')
|
||||
|
||||
weblibs = self.get_weblibs()
|
||||
for key, title in weblibs.items():
|
||||
|
||||
simple_settings.append({
|
||||
'section': 'wuttaweb',
|
||||
'option': f"libver.{key}",
|
||||
'default': getval(f"libver.{key}"),
|
||||
})
|
||||
simple_settings.append({
|
||||
'section': 'wuttaweb',
|
||||
'option': f"liburl.{key}",
|
||||
'default': getval(f"liburl.{key}"),
|
||||
})
|
||||
|
||||
# nb. these are no longer used (deprecated), but we keep
|
||||
# them defined here so the tool auto-deletes them
|
||||
simple_settings.append({
|
||||
'section': 'tailbone',
|
||||
'option': f"libver.{key}",
|
||||
})
|
||||
simple_settings.append({
|
||||
'section': 'tailbone',
|
||||
'option': f"liburl.{key}",
|
||||
})
|
||||
|
||||
return simple_settings
|
||||
|
||||
|
||||
class SettingView(MasterView):
|
||||
"""
|
||||
|
|
10
tests/views/test_settings.py
Normal file
10
tests/views/test_settings.py
Normal file
|
@ -0,0 +1,10 @@
|
|||
# -*- coding: utf-8; -*-
|
||||
|
||||
from tailbone.views import settings as mod
|
||||
from tests.util import WebTestCase
|
||||
|
||||
|
||||
class TestSettingView(WebTestCase):
|
||||
|
||||
def test_includeme(self):
|
||||
self.pyramid_config.include('tailbone.views.settings')
|
Loading…
Reference in a new issue